• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

WSDL2Java Question

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just started using Webservices, so please excuse me if I missed something obvious.

I have the wsdl url. I need to pass the url to a java class and to generate the java class with the wsdl, so i can get the interface with all the method names. Is there anyway we can do this, so I can get the list of methods as a map or something.

As of now I use WSDL2Java in command line and the java file is created and stored in y machine. But I need to do this in java.

Many use only ANT scripts to do this, but as per my requirement we cannot use ANT.

My .jws file is



So I executed

and I got HelloWorldService.java in my machine.



Is there any way I can get only the method names from this class. I need to display this information.

Thanks.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should probably use
JAX-RPC: Dynamic Invocation Interface (DII) or JAX-WS: javax.xml.ws.Dispatch client
instead.

To read the WSDL simply read it through an HTTP connection and then extract the information that you need directly from it.

The classes generated by WSDL2Java should not be used as a canonical representation of the service interface - they are simply a convenience java adapter for a static (i.e. non-changing) endpoint definition.

As you are dynamically exploring the WSDL you should stick to the definition found within the WSDL which is the actual service contract - not some approximated translation as provided by WSDL2Java.
[ September 25, 2007: Message edited by: Peer Reynders ]
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response.

So you mean I do not need to use WSDL2Java at all. I also have a Client with which I accessed the wsdl.



I was also able to see the output.

To read the WSDL simply read it through an HTTP connection and then extract the information that you need directly from it.



Could you explain this a bit more. Are you saying that I need to parse the xml and look for the tag "wsdl:message" in <wsdl:message name="HelloWorldRequest">
<wsdl art name="data" type="xsd:string" />
</wsdl:message>

Am I correct or did I miss something.

Thanks again.

P.S. I am looking at the 2nd link you gave as the first was kind of similar to what I did.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vjy chin:
Are you saying that I need to parse the xml and look for the tag "wsdl:message" in <wsdl:message name="HelloWorldRequest">
<wsdl art name="data" type="xsd:string" />
</wsdl:message>



Yes. However you are not looking for "wsdl:message" you are looking for "{http://schemas.xmlsoap.org/wsdl/}message" - that is, you need to be namespace aware. So it is probably easier with XPath. For an example see here.

Ronald Bourret: XML Namespaces FAQ
James Clark: XML Namespaces
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response.

I could not go through the links fully. I would do that ASAP.

I tried running the example you had written and I was not able to run it. I changed a bit.


[ September 25, 2007: Message edited by: vjy chin ]
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vjy chin:
I tried running the example you had written and I was not able to run it. I changed a bit.



The XPath libraries have are only standard with Java 1.5.
With 1.4 you have to use Xalan's XPathAPI which works a bit differently.

Xalan
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again. I am using Java 1.5 version. Actually I had the questions in the code part. I apologize for not mentioning it.

Please look at the code part, I have added my questions in the code part


Thanks again.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vjy chin:
Is this correct? If not how should I do this for my example



Yes, provided you use "wsdl" as the prefix in your XPath query and the WSDL complies with WSDL 1.0.
For WSDL 2.0 you have to use "http://www.w3.org/ns/wsdl".

What value should I set for this and how do I determine the value.



Well, you are going to need multiple expressions - so its time to brush up on XPath

"/wsdl:definitions/wsdl:messages/attribute::name/child::text()"
or
"/wsdl:definitions/wsdl:messages/@name/text()"

Should give you a org.w3c.dom.NodeList of the message names (haven't tested it though).

However these messages are only part of a "web operation" within the WSDL if
  • The message name is referenced in a portType's operation definition.
  • That operation is bound in a binding.
  • The binding is used in the service's port definition.

  • (reality is even a bit more complicated than that).
    What you are really interested in are the binding's operation names.

    You will need to change the content of that xmlSource variable - that needs to be the WSDL itself.
    [ September 25, 2007: Message edited by: Peer Reynders ]
     
    vjy chin
    Ranch Hand
    Posts: 279
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the reply.

    I actually got something working though not much. I have completely removed the name spaces and I am looking only for certain attributes.

    The xml file which I have from the URL is


    As of not I am only going to be looking for wsdl:message attributes.

    The code I have is a little modified version of yours.



    Ok, the output I get is



    This is well and good, but I also need to get the wsdl:part and the type (xsd:string) which tells me type of parameter.

    Do I need to change my expression1 (String expression1 = "/schema/element/attribute::*"; ) statement?

    How can I do that? Any suggestions.

    Thanks again.
    [ September 28, 2007: Message edited by: vjy chin ]
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Given the expression that you are using I don't even know what you are parsing. That expression is finding

    <schema>
    <element name="enableUserRequest" />
    </schema>

    etc. somewhere.

    In any case - simply use an expression that selects the message nodes and then use the org.w3c.dom.Node interface to navigate to the parts you want. getAttributes() will give you a org.w3c.dom.NamedNodeMap and getChildNodes() will get you another org.w3c.dom.NodeList.
    [ September 28, 2007: Message edited by: Peer Reynders ]
     
    vjy chin
    Ranch Hand
    Posts: 279
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the reply. I tried to get the values, but not able to get the type part (I need to get xsd:string as result) in


    The code I have now is



    I am not able to get the value. Am I missing something?

    Thanks for your help.

    P.S. I tried WSDL4j library and I was able to get the results. But the value I get is some ibm class (com.ibm.wsdl.ServiceImpl), so I am not sure if it would be good.
    [ September 28, 2007: Message edited by: vjy chin ]
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Your WSDL sample uses namespaces while your XPath expression does not ... ???

    This (non-namespace) code sample works fine:


    Output:
     
    vjy chin
    Ranch Hand
    Posts: 279
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Peer,

    It worked great and I changed slightly according to my requirement.

    Thanks once again for your time and help.
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    You can use axis's Emitter class which is being used by axis's WSDL2Java behind the scene. This is same as WSDL2Java but you can use it programmatically.
     
    Sheriff
    Posts: 67752
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Elsan, please check your private messages for an important message.
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Elsan:
    You can use axis's Emitter class which is being used by axis's WSDL2Java behind the scene.



    The point that I made earlier in the thread was that the WSDL is the service contract. The output from WSDL2Java is merely a translation of the original service contract according to certain mapping rules. That translation is used a convenience during development but should never be mistaken for the actual service contract.
     
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hey i am an new bee to web services and i need to perform this task and can you please suggest some web sites where i can learn them in detail....thanks in advance
     
    If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic