1

I'm new to soap web service.Can someone please tell me how to make a soap request using the wsdl provided and its username and password using x509 in JAVA. I got many codes in .NET. But I'm still blank on how to form request using x509 authentication in java. Any help would be appreciated. Thanks in advance.

Using soap UI and using basic authentication in AUTH tab.. following is the error I get.

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
   </s:Header>
   <s:Body>
      <s:Fault>
         <s:Code>
            <s:Value>s:Sender</s:Value>
            <s:Subcode>
               <s:Value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</s:Value>
            </s:Subcode>
         </s:Code>
         <s:Reason>
            <s:Text xml:lang="en-US">An error occurred when verifying security for the message.</s:Text>
         </s:Reason>
      </s:Fault>
   </s:Body>
</s:Envelope>
User14141111
  • 355
  • 2
  • 19

1 Answers1

0

See, if you've got the WSDL, you should use the tool SoapUI which will help you to create the request and see the response. You can easily generate sample requests using this tool providing username and password and see the response based upon the request.

It shows complete and detailed version of requests where you can easily map the mandatory and optional fields.

Once you have a perfect sample of request based upon you requirement, you can use JAXB for further processes. You can generate Java classes from WSDL and the set the values with the help of request you have ready from SoapUI. Next step is convert object into XML and vice versa which you can do with mashalling and unmarshalling.

  • I tried using soapUI , but it gives authentication error. Please check I've edited question – User14141111 Sep 16 '16 at 10:21
  • Have you tried passing the authentication on left most side panel? Please share the screen shot so that I would tell you exact point to provide the details. – Shashwat Sharma Sep 16 '16 at 10:26
  • here's the screen shot @ShashwatSharma https://www.dropbox.com/s/lo1khg4chztlm1q/te.png?dl=0 – User14141111 Sep 17 '16 at 06:16
  • Your header part is empty which is required for soap services in several cases. Is that the default one which you create? Try sharing the fresh request so that I would further deduce the fact of issue if you're not done yet. – Shashwat Sharma Sep 21 '16 at 09:31
  • @ShaswatSharma Aren't the header automatically generated based on the information provided in Authentication and header tab.? If not how can I add it? I mean the security tokens and timestamp that have to be passed in header are generated automatically based on info we provide in tabs below. I've even changed must understand to true in WS Addressing related Settings. – User14141111 Sep 23 '16 at 09:53
  • Hi, it doesn't automatically generate the header part (as always in my case). You have to provide the values manually as you provide in body part. It could be more helpful if you provide the default generated request because I'm unable to see the header part in the screen shot shared by you. – Shashwat Sharma Sep 23 '16 at 11:08
  • the request is as it can be seen in the screen shot. Can you please share a reference on ho can i authenticate first using soap-ui. I followed this link and created a keystore.jks file that has to be passed as shown in the link using this cmd **keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048**. But without any success. @ShashwatSharma – User14141111 Sep 24 '16 at 08:34
  • In **raw** tab it is showing only this POST http://host.ca/Service.svc HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: application/soap+xml;charset=UTF-8;action="http://test.or/GetMessageSer/GetMessage" Content-Length: 5197 Host: hostname.ca Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5) – User14141111 Sep 24 '16 at 08:35