• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Java Client for a SOAP wsdl with basic authentication

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 7413
170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which version of Axis2 are you using?
 
Vishnu Austin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Axis2 1.6.1
 
Vishnu Austin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:o="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
Saloon Keeper
Posts: 7413
170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vishnu Austin,

Please use code tags (UseCodeTags) when posting code in the forums. I've edited your first post.
 
Vishnu Austin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fixed the issue, see post with label "Error: MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-s"

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

 
I don't always make ads but when I do they're tiny
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic