加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

将文档从AngularJS发布到SOLR 4

发布时间:2020-12-17 17:40:37 所属栏目:安全 来源:网络整理
导读:我对此深陷兔子洞.我正在创建一个简单的应用程序,它使用SOLR 4作为NoSQL数据存储区,使用AngularJS v1.2.2作为接口.我从命令行加载了一堆文件,AngularJS使搜索/查看这些文件变得非常容易.我想允许文档编辑,但无法使POST工作. Chrome控制台显示400个错误,“网
我对此深陷兔子洞.我正在创建一个简单的应用程序,它使用SOLR 4作为NoSQL数据存储区,使用AngularJS v1.2.2作为接口.我从命令行加载了一堆文件,AngularJS使搜索/查看这些文件变得非常容易.我想允许文档编辑,但无法使POST工作. Chrome控制台显示400个错误,“网络”标签显示OPTIONS方法失败.
网络标题:
请求URL:http:// localhost:8983 / solr / mrm_assay / update
请求方法:选项
状态代码:400错误请求
请求标题
接受:*/*
接受编码:gzip,放气,SDCH
接受语言:EN-US,EN; Q = 0.8,ES; Q = 0.6
Access-Control-Request-Headers:accept,content-type
访问控制请求-方法:POST
缓存控制:无缓存
连接:保持活跃
主持人:本地主机:8983
产地:HTTP://本地主机:63342
附注:无缓存
引用者:HTTP://本地主机:63342 /角solr2 /应用/ index.html中
用户代理:Mozilla / 5.0(Macintosh; Intel Mac OS X 10_8_5)AppleWebKit / 537.36(K HTML,与Gecko一样)Chrome / 31.0.1650.57 Safari / 537.36
响应标题
访问控制允许的凭据:真
Access-Control-Allow-Headers:origin,content-type,cache-control,accept,options
访问控制允许的方法:GET,POST,DELETE,PUT,HEAD,OPTIONS
访问控制允许来源:HTTP://本地主机:63342
访问控制 – 最大 – 年龄:1800
内容类型:应用/ XML;字符集= UTF-8
传输编码:分块

架构快速概述:
SOLR和AngularJS应用程序都在我的Mac上运行.
SOLR使用默认的Jetty实例,Angular应用程序在WebStorm IDE的服务器内运行. CORS已启用,包括GET,OPTIONS.

更新工作时:

>使用SOLR的仪表板
>使用命令行(示例)
$curl http:// localhost:8983 / solr / mrm_assay / update -H’Content-type:application / json’-d'[{
“keep_in_assay”{“set”:“N”,
“detected_endog”:“N”,
“problems_w_is”:“删除的b / c需要添加后绿洲”,
“onc_std_set”:“set1”,
“fraction_id”:“7”,
“onclistgene”:“UBL3”,
“geneid”:“UBL3_IS6”,
“taxonid”:“9606”,
“肽”:“SSNVPADMINLR”,
“degen_human”:“1”,
“gene_degeneracy”:“1”,
“percnt_id”:“66.7”,
“uuid”:“6d20eb03-d3ee-4eb2-bc16-27cfaabab989”
}]’

我的Angular控制器代码如下所示:
assayControllers.controller(‘AssayUpdateController’,[‘$scope’,’$http’,
????function($scope,$http){
????????$scope.processForm = function(){
????????????的console.log($scope.assay);
????????????$HTTP({
????????????????方法: ‘POST’,
????????????????网址: ‘HTTP://本地主机:8983 / Solr的/ mrm_assay /更新’,
????????????????数据:$scope.assay,
????????????????标题:{‘Content-Type’:’application / json’}
????????????})
????????????????.success(function(data,status,headers){
????????????????????的console.log(data.message);
????????????????})
????????????????.error(function(data,headers,config){
????????????????????的console.log(状态);
????????????????});
????????};
????}
]);

数据从表单中成功发送,因为我可以在控制台上看到它(虽然JSON对象没有打包在一个数组中,SOLR似乎期望…我还尝试将JSON格式的数据推送到数组并POST但没有运气)

我感谢您的帮助 – 即使只是为了指导我的故障排除!

解决方法

关于如何使用AngularJS v1.2.2将单个文档更新为SOLR v4.7的答案是多部分的.这只在我的localhost上测试过!

I.在SOLRsolr-4.7.0 / example / solr-webapp / webapp / WEB-INF / web.xml附带的Jetty服务器上配置CORS

注意:CrossOriginFilter有一个参数chainPreflight,默认情况下设置为true.这需要设置为false.这是CORS转发POST而不是SOLTIONS的关键.此外,订单很重要!

<filter>
    <filter-name>cross-origin</filter-name>
    <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
    <init-param>
         <param-name>allowedOrigins</param-name>
         <param-value>http://localhost*</param-value>
    </init-param>
     <init-param>
         <param-name>allowedMethods</param-name>
         <param-value>GET,OPTIONS</param-value>
     </init-param>
     <init-param>
         <param-name>allowedHeaders</param-name>
         <param-value>origin,options,authorization,x-requested-with</param-value>
     </init-param>
    <init-param>
        <param-name>supportsCredentials</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>chainPreflight</param-name>
      <param-value>false</param-value>
    </init-param>
</filter>

<filter-mapping>
  <filter-name>cross-origin</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

II. SOLR期望以数组格式的有效载荷,因此您需要将Angular对象推入一个.基本上,$scope.data变为[$scope.data]

assayControllers.controller('AssayUpdateController',['$scope','$http','$location',function($scope,$http,$location){
        $scope.processForm = function(){
            $http.post("http://localhost:8983/solr/mrm_assay/update?commit=true",[$scope.assay])
                .success(function(data,headers){
                    console.log(data.message);
                    $location.path("/assays")
                })
                .error(function(data,config){
                    console.log(status);
                });
        };
    }
]);

III. SOLR文档包含可能导致POST出现“冲突”错误的版本字段.这是由于我无法追踪的缓存问题(卷曲显示当前值但浏览器有旧版;甚至强制刷新).无论如何,这对SOLR来说比我更有用,所以最好的办法是不要首先将它归还给客户.我不认为字段排除是一个选项,因此我将所有要在solrconfig.xml中返回的字段列入白名单

<!-- A request handler that returns indented JSON by default -->
  <requestHandler name="/query" class="solr.SearchHandler">
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <str name="wt">json</str>
       <str name="indent">true</str>
       <str name="df">text</str>
      <str name="fl">uuid,keep_in_assay,detected_endog,problems_w_is,onc_std_set,fraction_id,detected_by_orbi_experiments,onclistgene,geneid,taxonid,peptide,
degen_human,degen_mouse,gene_degeneracy,department,protein_ac,pepid,protid,percnt_id,peptide_ordered</str>

现在该应用程序就像一个魅力!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读