[英]Getting 401 error Unauthorized while making soap request
Recently I got a requirement from one of our customer. 最近我收到了一位客户的要求。 They provided a WSDL to call their service.
他们提供了一个WSDL来调用他们的服务。 They are doing IP whitelisting for authentication.
他们正在进行IP白名单以进行身份验证。 I gave my server public IP and it got whitelisted.
我给了我的服务器公共IP,它被列入白名单。 First, I tested that service through SOAP UI tool and it got worked without any issues.
首先,我通过SOAP UI工具测试了该服务,并且它没有任何问题。 Then I integrated through JAVA code and it got failed.
然后我通过JAVA代码集成,它失败了。 I am getting an exception like
我得到一个例外
Unable to sendViaPost to url[ https://apps.greystar.com/gsWebService/gsExtract.asmx] org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.handleResponse(HTTPSenderImpl.java:343) ~[axis2-transport-http-1.7.1.jar:1.7.1] at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.sendViaPost(HTTPSenderImpl.java:213) ~[axis2-transport-http-1.7.1.jar:1.7.1] at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:121) [axis2-transport-http-1.7.1.jar:1.7.1] at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:403) [axis2-transport-http-1.7.1.jar:1.7.1] at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:234) [axis2-transport-http-1.7.1.jar:1.7.1] at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431) [axis2-kernel-1.7.1.jar:1.7.1] at org.apache.axis2.description.OutInAxisO
无法将viaPost发送到网址[ https://apps.greystar.com/gsWebService/gsExtract.asmx] org.apache.axis2.AxisFault:传输错误:401错误:未经授权在 org.apache.axis2.transport.http.impl。 httpclient3.HTTPSenderImpl.handleResponse(HTTPSenderImpl.java:343)〜[axis2-transport-http-1.7.1.jar:1.7.1] at org.apache.axis2.transport.http.impl.httpclient3.HTTPSenderImpl.sendViaPost(HTTPSenderImpl .java:213)〜[axis2-transport-http-1.7.1.jar:1.7.1] atg.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] at at 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] org.apache.axis2.description.OutInAxisO perationClient.send(OutInAxisOperation.java:399) [axis2-kernel-1.7.1.jar:1.7.1] at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) [axis2-kernel-1.7.1.jar:1.7.1] at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) [axis2-kernel-1.7.1.jar:1.7.1] at 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] at com.reputation.r4e.integrator.recordreader.GreystarLocationImportRecordReader.process(GreystarLocationImportRecordReader.java:97) [classes/:na] at com.reputation.r4e.integrator.impl.DefaultPipeline.flow(DefaultPipeline.java:33) [classes/:na] at com.reputation.r4e.integrator.impl.DefaultPipeline.process(DefaultPipeline.java:52) [classes/:na] at com.reputation.r4e.integrator.importer.NullImporter.p
perationClient.send(OutInAxisOperation.java:399)[axis2-kernel-1.7.1.jar:1.7.1] atg.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)[ axis2-kernel-1.7 .jar:1.7.1]在com.reputation.r4e的org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)[axis2-kernel-1.7.1.jar:1.7.1]。 integrator.greystar.ExtractDataStub.greystarExtract(ExtractDataStub.java:300)[classes /:na] at com.reputation.r4e.integrator.recordreader.GreystarLocationImportRecordReader.getGreystarExtractResponse(GreystarLocationImportRecordReader.java:198)[classes /:na] at com。 Reputation.r4e.integrator.recordreader.GreystarLocationImportRecordReader.process(GreystarLocationImportRecordReader.java:97)[classes /:na] at 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.importer.NullImporter.p rocess(NullImporter.java:38) [classes/:na] at com.reputation.r4e.integrator.impl.DefaultPipeline.flow(DefaultPipeline.java:33) [classes/:na] at 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] at 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] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
rocess(NullImporter.java:38)[classes /:na] at com.reputation.r4e.integrator.impl.DefaultPipeline.flow(DefaultPipeline.java:33)[classes /:na] at 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] at 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] at java.lang。 Thread.run(Thread.java:745)[na:1.8.0_45]
It's saying 401 unauthorised error. 这是说401未经授权的错误。 How it got worked through SOAP UI and why its not working through a JAVA client.?
它是如何通过SOAP UI工作的,以及为什么它不能通过JAVA客户端工作。
I monitor http traffic through TCPMon and except headers all are same. 我通过TCPMon监控http流量,除了标头都相同。 So I added the headers which got from the SOAP UI tool to my JAVA Client but still no luck.
所以我添加了从SOAP UI工具到我的JAVA Client的标题,但仍然没有运气。 I am getting the same 401 unauthorised error.
我得到了同样的401未经授权的错误。
Here are the soap request of both SOAP UI and through JAVA Client. 以下是SOAP UI和JAVA Client的soap请求。
SOAP UI Request: 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 CLIENT Request: 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>
Note: I added JAVA Client headers by looking at the SOAP UI headers. 注意:我通过查看SOAP UI标头添加了JAVA Client标头。 The actual JAVA client headers are below
实际的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
What could be the reason for failing this through JAVA client.? 通过JAVA客户端失败的原因可能是什么? Can any one please answer my question because I stuck over here.
任何人都可以回答我的问题,因为我坚持到这里。
Thanks in advance, Amar.T 在此先感谢,Amar.T
I tried other third party libraries and its working as expected. 我尝试了其他第三方库,并按预期工作。 I tried CXF and SOAP UI JAVA API and its working as expected.
我尝试了CXF和SOAP UI JAVA API ,并按预期工作。 I don't know why its not working with APACHE AXIS2.
我不知道为什么它不能与APACHE AXIS2合作。
If anyone finds the answer why its not working with AXIS2 please post the answer. 如果有人找到答案,为什么它不与AXIS2合作,请发布答案。
Thanks & Regards, Amar.T 感谢和问候,Amar.T
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.