0

I am supposed to consume a SOAP service exposed by a third party. I have 2 basic questions w.r.t that:

Q1. The WSDL needs a basic authentication to access through the browser. Now when I try creating the client jar using wsgen/WSDL2JAVA/ using Eclipse Webservice client, I get HTTP 401 unauthorised. If I download and save the WSDL locally and then use axis's WSDL2JAVA, I get


Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDL
    at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:178)
    at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
    at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'file:/C:/TEST/TOOLS/Authentication.wsdl'.: org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound.
    at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile(CodeGenerationEngine.java:320)
    at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:133)
    ... 2 more
Caused by: org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
    ... 7 more

Q2. How do we handle a frequently changing WSDL, do we generate the client jars everytime and redeploy the application?

Any pointers in helping me create the client.jar would be great.

RAM
  • 2,413
  • 1
  • 21
  • 33
user1912337
  • 1
  • 1
  • 2

2 Answers2

0

You should definitely redeploy your client.jar for every change in WSDL.

I would suggest you this.

  1. Create a jar project to generate classes from wsdl. Check cxf-codegen-plugin wsdl2java for example.
  2. Create another jar project(Client.jar) that refer the previous project.

So whenever a change in WSDL you should modify the WSDL URL in the project and then build both jar project to create Client.jar. Better practice is to use the WSDL URL as a configurable property value inside or outside the Client.jar for maintaining it.

Hope this helps.

Saravana Kumar
  • 113
  • 3
  • 16
  • Thanks Sarvana, but creating client jar itself is a problem since the WSDL is exposed by a 3rd party and has a basic authentication. While using wsdl2Java, i get the exception stated above, since i am not aware where to set the ID/PWD such that the wsdl2Java tool clears the authentication. I hope i made my question clear. Thanks in Advance !!! – user1912337 Dec 26 '12 at 10:35
  • It does not seem like the exception because of Basic Authentication. Also wsdl2java tool would not needed to be set credentials. It might be authenticated only when you are invoking the endpoint using the client proxy. It seems like the WSDL has not saved in a correct way. Or the wsdl itself has some issue on its syntax. – Saravana Kumar Dec 26 '12 at 12:08
0

In your wsdl file, check the "<"wsdl:definitions">" tag for the xmlns:wsdl attribute, if this is missing it will throw the error:

"org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound" found on line 5 of the error summary you posted.

In the example below you will see prefixes being defined by the xmlns (xml namespace) attribute:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://org.apache.axis2/xsd" 
xmlns:ns="http://pojo.service.quickstart.samples" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
targetNamespace="http://pojo.service.quickstart.samples">

Review how xml namespaces work here: http://www.w3schools.com/xml/xml_namespaces.asp

am6sigma
  • 184
  • 8