aspose file tools*
The moose likes Web Services and the fly likes Java Client for a SOAP wsdl with basic authentication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Java Client for a SOAP wsdl with basic authentication" Watch "Java Client for a SOAP wsdl with basic authentication" New topic
Author

Java Client for a SOAP wsdl with basic authentication

Vishnu Austin
Greenhorn

Joined: Mar 30, 2012
Posts: 11
Hi,

I generated the java client using axis2, for a secured wsdl. I am facing following errors on testing the client
org.apache.axis2.AxisFault: An error occurred when verifying security for the message.
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at us.tx.state.txdps.records.cch.SearchServiceStub.SearchBySid(SearchServiceStub.java:1015)
at us.tx.state.txdps.records.cch.Test.testStub(Test.java:40)
at us.tx.state.txdps.records.cch.Test.main(Test.java:143)

My client code is


Also tried


Also tried

But with no success.

I tested the wsdl using SOAPUI and it works good.

Appreciate if someone could tell where I am going wrong.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Which version of Axis2 are you using?
Vishnu Austin
Greenhorn

Joined: Mar 30, 2012
Posts: 11
Axis2 1.6.1
Vishnu Austin
Greenhorn

Joined: Mar 30, 2012
Posts: 11
Below is the request response generated by SOAP
XML Request
-----------
<soapenv:Envelope xmlns:cch="http://search.txdps.state.tx.us/cch" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>abc</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">123<wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">I7JFUNelmF6cViOKuY6UFw==</wsse:Nonce>
<wsu:Created>2012-05-07T13:23:16.023Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<cch:SearchBySid>
<!--Optional:-->
<cch:sid>07206390</cch:sid>
</cch:SearchBySid>
</soapenv:Body>
</soapenv:Envelope>



XML Response
------------
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2012-05-07T13:23:19.945Z</u:Created>
<u:Expires>2012-05-07T13:28:19.945Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<SearchBySidResponse xmlns="http://records.txdps.state.tx.us/cch">
<SearchBySidResult xmlns:a="http://schemas.datacontract.org/2004/07/CchService.Search" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:BatchId>3496101</a:BatchId>
<a:Hits>
<a:WsSearchHitItem>
<a:BatchId>3496101</a:BatchId>
<a:MatchRank>0</a:MatchRank>
<a:MatchSummary>Cook, PAUL</a:MatchSummary>
<a:MatchType>EXACT</a:MatchType>
<a:MatchTypeSummary>EXACT</a:MatchTypeSummary>
<a:PhotoId>0</a:PhotoId>
<a:SearchId>25543142</a:SearchId>
</a:WsSearchHitItem>
</a:Hits>
<a:ResultCode>DONE</a:ResultCode>
<a:SearchDate>2012-05-07T08:23:19.9450188-05:00</a:SearchDate>
<a:SearchId>25543142</a:SearchId>
<a:Summary>SID: 07206390</a:Summary>
</SearchBySidResult>
</SearchBySidResponse>
</s:Body>
</s:Envelope>
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
It looks as if you're trying to mix WSS authentication and HTTP authentication (which is what the username/password in the Options class is all about).

Have you tried configuring WSS externally by using a WSDD file, instead of doing it programmatically (which is much harder to get right)? That's what I prefer to do, as it allows you to use the same code secured and unsecured with just a change of the WSDD file.
Vishnu Austin
Greenhorn

Joined: Mar 30, 2012
Posts: 11
Thanks Tim appreciate your response.

I tried another option using JAX-WS, and I am getting

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood
at com.sun.xml.internal.ws.protocol.soap.MUTube.createMUSOAPFaultException(MUTube.java:140)
at com.sun.xml.internal.ws.protocol.soap.ClientMUTube.processResponse(ClientMUTube.java:82)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:591)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:540)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:525)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:422)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:235)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:120)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:230)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
at $Proxy30.searchBySid(Unknown Source)
at Test.callWebService(Test.java:36)



The actual xml request from SOAP is



Appreciate your help.
Thanks again

Vishnu Austin
Greenhorn

Joined: Mar 30, 2012
Posts: 11
Tim,
I made one more change...and now I am getting

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: An error occurred when verifying security for the message.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:171)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:94)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:240)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
at $Proxy30.searchBySid(Unknown Source)
at Test.callWebService(Test.java:36)
at Test.main(Test.java:52)

The XML Request being sent is

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3859

Hi Vishnu Austin,

Please use code tags (UseCodeTags) when posting code in the forums. I've edited your first post.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Vishnu Austin
Greenhorn

Joined: Mar 30, 2012
Posts: 11
Fixed the issue, see post with label "Error: MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-s"

Priti Machhi
Greenhorn

Joined: Sep 06, 2012
Posts: 1
How did you add the header to the client. When I try building it using the OMElement it gave me error at line
OMElement omuserName = omFactory.createOMElement(new QName("", "Username", "wsse"), null);

java.lang.IllegalArgumentException: Cannot create a prefixed element with an empty namespace name
at org.apache.axiom.om.impl.llom.OMElementImpl.handleNamespace(OMElementImpl.java:186)
at org.apache.axiom.om.impl.llom.OMElementImpl.<init>(OMElementImpl.java:161)
at org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory.createOMElement(OMLinkedListImplFactory.java:126)
Suraj Berwal
Greenhorn

Joined: Dec 28, 2001
Posts: 26
Hi Priti,

You need to set the header QName as below

new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu")

Thanks,
Suraj

Priti Machhi wrote:How did you add the header to the client. When I try building it using the OMElement it gave me error at line
OMElement omuserName = omFactory.createOMElement(new QName("", "Username", "wsse"), null);

java.lang.IllegalArgumentException: Cannot create a prefixed element with an empty namespace name
at org.apache.axiom.om.impl.llom.OMElementImpl.handleNamespace(OMElementImpl.java:186)
at org.apache.axiom.om.impl.llom.OMElementImpl.<init>(OMElementImpl.java:161)
at org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory.createOMElement(OMLinkedListImplFactory.java:126)


Suraj Berwal
Sun Certified Programmer for Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Client for a SOAP wsdl with basic authentication