获取401错误在发出肥皂请求时未经授权

时间:2016-09-25 04:00:25

标签: java web-services soap wsdl

最近我收到了一位客户的要求。他们提供了一个WSDL来调用他们的服务。他们正在进行IP白名单以进行身份​​验证。我给了我的服务器公共IP,它被列入白名单。首先,我通过SOAP UI工具测试了该服务,并且它没有任何问题。然后我通过JAVA代码集成,它失败了。我得到了像

这样的例外
  

无法将viaPost发送到网址[https://apps.greystar.com/gsWebService/gsExtract.asmx]    org.apache.axis2.AxisFault:传输错误:401错误:未经授权       at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.handleResponse(HTTPSenderImpl.java:343)〜[axis2-transport-http-1.7.1.jar:1.7.1]       在org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.sendViaPost(HTTPSenderImpl.java:213)〜[axis2-transport-http-1.7.1.jar:1.7.1]       在org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:121)[axis2-transport-http-1.7.1.jar:1.7.1]       在org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:403)[axis2-transport-http-1.7.1.jar:1.7.1]       在org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:234)[axis2-transport-http-1.7.1.jar:1.7.1]       在org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431)[axis2-kernel-1.7.1.jar:1.7.1]       at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:399)[axis2-kernel-1.7.1.jar:1.7.1]       在org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)[axis2-kernel-1.7.1.jar:1.7.1]       在org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)[axis2-kernel-1.7.1.jar:1.7.1]       在com.reputation.r4e.integrator.greystar.ExtractDataStub.greystarExtract(ExtractDataStub.java:300)[classes /:na]       at com.reputation.r4e.integrator.recordreader.GreystarLocationImportRecordReader.getGreystarExtractResponse(GreystarLocationImportRecordReader.java:198)[classes /:na]       在com.reputation.r4e.integrator.recordreader.GreystarLocationImportRecordReader.process(GreystarLocationImportRecordReader.java:97)[classes /:na]       在com.reputation.r4e.integrator.impl.DefaultPipeline.flow(DefaultPipeline.java:33)[classes /:na]       在com.reputation.r4e.integrator.impl.DefaultPipeline.process(DefaultPipeline.java:52)[classes /:na]       在com.reputation.r4e.integrator.importer.NullImporter.process(NullImporter.java:38)[classes /:na]       在com.reputation.r4e.integrator.impl.DefaultPipeline.flow(DefaultPipeline.java:33)[classes /:na]       在com.reputation.r4e.integrator.impl.DefaultPipeline.process(DefaultPipeline.java:52)[classes /:na]       at com.reputation.r4e.integrator.IntegrationRunner $ IntegrationRunnable.run(IntegrationRunner.java:87)[classes /:na]       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[na:1.8.0_45]       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)[na:1.8.0_45]       在java.lang.Thread.run(Thread.java:745)[na:1.8.0_45]

它说401未经授权的错误。它是如何通过SOAP UI工作的,以及为什么它不能通过JAVA客户端工作。

我通过TCPMon监控http流量,除了标头都相同。所以我添加了从SOAP UI工具到我的JAVA Client的标题,但仍然没有运气。我收到了同样的401未经授权的错误。

以下是SOAP UI和JAVA Client的soap请求。

SOAP UI请求:

POST https://apps.greystar.com/gsWebService/gsExtract.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="https://apps.greystar.com/greystarExtract"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Content-Length: 692
Host: apps.greystar.com
Connection: Keep-Alive

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"  xmlns:apps="https://apps.greystar.com/">
  <soap:Header/>
  <soap:Body>
     <apps:greystarExtract>
        <apps:axmlVendorCode>VENDOR_CODE</apps:axmlVendorCode>
        <apps:axmlToken>PASSWORD</apps:axmlToken>
        <apps:axmlExtractType>PROPERTY_LIST</apps:axmlExtractType>
        <apps:axmlFormat>XML</apps:axmlFormat>
        <apps:axmlParameters></apps:axmlParameters>
     </apps:greystarExtract>
  </soap:Body>
</soap:Envelope>

JAVA客户请求:

POST /gsWebService/gsExtract.asmx HTTP/1.1
Content-Type: application/soap+xml; charset=UTF-8; action="https://apps.greystar.com/greystarExtract
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36[\r][\n]
Connection: Keep-Alive
Host: apps.greystar.com
Transfer-Encoding: chunked

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
     <soapenv:Header />
     <soapenv:Body>
        <ns1:greystarExtract xmlns:ns1="https://apps.greystar.com/">
           <ns1:axmlVendorCode>VENDOR_CODE</ns1:axmlVendorCode>
           <ns1:axmlToken>PASSWORD</ns1:axmlToken>
           <ns1:axmlExtractType>PROPERTY_LIST</ns1:axmlExtractType>
           <ns1:axmlFormat>JSON</ns1:axmlFormat>
           <ns1:axmlParameters></ns1:axmlParameters>
        </ns1:greystarExtract>
     </soapenv:Body>
</soapenv:Envelope>

注意:我通过查看SOAP UI标头添加了JAVA Client标头。实际的JAVA客户端标题位于

之下
POST /gsWebService/gsExtract.asmx HTTP/1.1
Content-Type: application/soap+xml; charset=UTF-8;               
action="https://apps.greystar.com/greystarExtract
User-Agent: Axis2
Host: apps.greystar.com
Transfer-Encoding: chunked

通过JAVA客户端失败的原因是什么?任何人都可以回答我的问题,因为我坚持到这里。

提前致谢, Amar.T

1 个答案:

答案 0 :(得分:0)

我尝试了其他第三方库,并按预期工作。我尝试了 CXF和SOAP UI JAVA API ,并按预期工作。我不知道为什么它不能与APACHE AXIS2合作。

如果有人找到答案,为什么它不与AXIS2合作,请发布答案。

谢谢&amp;问候, Amar.T