users@glassfish.java.net

Re: JAX-WS Applications Doubt

From: <glassfish_at_javadesktop.org>
Date: Tue, 29 Jun 2010 11:53:02 PDT

Hi,
Please read inline. Hopefully this will clarify your doubts.

> Hi,
>
> I am lost in JAX-WS chaos!
>
> Essentially, I've been trying to build a simple web
> service application (e.g: the AddNumbers web service
> that comes in the Samples from Metro).
>
> But after reading several web pages, and playing
> around with my eclipse, I've come to harvest many
> many doubts.
>
> I will post them here, in hopes that someone might
> shed some light to many of my issues.
>
> (1) Java has many APIs related to the development of
> web services (e.g: jax-WS, Jax-B, and so on). But
> developing these applications, at least for me, seems
> to result in utter chaos for many reasons:
>
> 1.1 Where are the Jars comprising these API's
> supposed to be located?

JDK6 onwards has JAXWS and JAXB integrated so if you want to just use what is in the platform you use JDK6.

If you want to use the latest you can get bits from metro but and use endorsed mechanisms to override the apis in jdk
>
> 1.2 What should you do if JDK comes with a specific
> JAX-WS version and is part of your classpath, Metro
> comes with another, and GlassFish has its own (i
> assume)?
>

Endorsed standards is the way to override the apis in JDK. You can use the java.endorsed.dirs system prop to point to the new jars see http://java.sun.com/j2se/1.4.2/docs/guide/standards/
> 1.3 After compiling you WAR file, which JARs are
> being used to imple the web service stack? The ones
> in the GlassFish modules folder? If so, shouldn't
> those be Jars used in your classpath wheny ou compile
> you web service application?
Right
>
> Related facts: I've seen the JAX-WS and JAX-B jars in
> a hundred different places.
> - I have Java JDK 1.6 installed in this computer, and
> it comes with a JAX-WS.jar (but doesn't seem to have
> any JAX-B jar).
JAXB and JAXWS are both bundled in JDK 6 also the scripts in bin folder like xjc,schemagen,wsimport (it is not possible to have jaxb not in the jdk)
 
> - I've downloaded the current Metro Release, which
> seems to bring all the essential Jars, as expected.
> However, it seems to use a different set of names,
> namely the webservices-api.jar seems to be a fusion
> of JAX-B with JAX-WS.
Yes that is correct.
> - I've even installed the Metro web services stack in
> my GlassFish 3 using the update tool, and many of the
> .jars that came with my Metro Download don't seem to
> exist anywhere among my glassfish libraries.
>

In glassfish we deliver osgi bits from metro so if you look in modules folder you will see webservices-osgi.jar and under modules/endorsed you will see the webservices-api-osgi.jar

It depends on what platform you want to work with.
To summarize
you can use JDK 6 apis
For more recent bits you can use metro or use standalone jaxb or jaxws from jaxb.dev.java.net, jaxws.dev.java.net and use endorsed standards and classpath

If you want to add Quality of Service like WSRM , WS Secure Conversation use Metro

If you want to work with glassfish use the jars in glassfish modules

> To conclude, it seems, that neither is there any
> standard name for these libraries, nor any default
> location you application should be accessing them
> from. Although, I am inclined to believe that for
> servers, the preferred location would be you
> GlassFish server modules.
>

See above
>
> (2) When I am developing a JAX-WS app, what should my
> classpath should be like?
>

The classpath will need jaxws ri and api jars so if you are using glassfish use the jars in modules folder, if you are using metro use the webservices*.jar which are part of the distribution
> Related fact: Because of this .jar redundance,
> ocasionally you have mixes of different versions of
> the same libraries which result in strange
> compilation errors.
>
>
> (3) When I use the APT ant task, my ant is using the
> APT implementation of my JDK. Again, should i be
> using the TOOLS.jar that comes with glassfish, or the
> one that comes with Metro or the One in my JDK?
>
ant tasks are not bundled in jdk. If you want to use the ant tasks use the webservices-tools.jar from glassfish or metro If you are calling the scripts then if you invoke from jdk/bin/xjc you are using the ones in jdk. If you use the glassfish ones you are using from glassfish
> (4) When I tried to use the WSGEN ant task supported
> in the Metro Tools.jar, I got compilation erros,
> because apparently my JAX-WS implemenation of my JDK
> is too outdated.
> (e.g: [i] You are running on JDK6 which comes with
> JAX-WS 2.1 API, but this tool requires JAX-WS 2.2
> API. Use the endorsed standards override mechanism
> (http://java.sun.com/javase/6/docs/technotes/guides/st
> andards/), or set xendorsed="true" on
> <wsimport>.[/i])
>
This means that you change your build.xml where you invoke wsimport add xendorsed=true so that you can override the apis in jdk
> Then how can I compile this application using the
> Metro tools, if they are too recent when compared to
> my JDK?
>
classpath and endorsed standards
> (5) I've seen a hundred pages trying to explain how
> to deploy you WAR files in glassfish.
> But what does GlassFIsh really want you to put in the
> WAR file? Does it want you to produce the WSDL and
> APT stubs before deployment? Or does it do it on its
> own?
>
> So far, I saw no one clearly answering which files I
> should place in my WAR file for it to properly work.
>
> I've seen people saying that if you are Going
> Java->WSDL:
> you don't need to do almost anything. Once you deploy
> the WAR file containg (WEB.XML and you user classes),
> Glassfish will automatically use Wsgen and APT to
> produce both your WSDL and the JAX-B incoming message
> and response of your service operations.
>
> 5.1 I've tried making WARs containing both APT
> classes and without them, in both cases I got correct
> deployments (no errors reported); but when I tried to
> access the Servlet link there was a "resource not
> found" reply from the server.
>
> Let me give you an example.
> It does not use code developed by me.
> 1st: I donwloaded the latest version of metro.
> 2nd: Opened a windows cmd.exe in
> METRO_HOME/samples/fromjava_no_wsgen
> 3rd: In the promt I wrote > ant build-served-java
> (this just compiles your user sources, does not
> generate any stubs. its just a javac over your
> srcDir)
> th: ant create-war
> 5th: asadmin deploy
> build/war/jaxws-fromjava_no_wsgen.war
> 6th: Success
>
> So far no problems to report.
> But then I've been told that If you web service is
> correctly deployed, then if you go to the web.xml
> servlet link you should retrieve the web service
> wsdl.
> Well, when I go to
> "http://localhost:8080/addnumbers"
> I get a resource not available response from the
> server.
> I am assuming this would be the correct link since
> the WEB.xml configures the sevlet as follows:
> [i] <servlet-mapping>
>
> servlet-name>fromjava_no_wsgen</servlet-name>
> <url-pattern>/addnumbers</url-pattern>
> t-mapping>[/i]
> Morever, if I go into the administration console,
> GlassFish seems to think that the service should be
> acessfile in the url /war-file-name, which in this
> case woul be:
> http://localhost:8080/jaxws-fromjava_no_wsgen.
I think http://localhost:8080/jaxws-fromjava_no_wsgen/addnumb
> ers?wsdl" should work
> In both cases I get the 404 response.
>
>
> Something else that confuses me is the web.xml file
> and sun-jaxws.xml. Are these two files complementary?
> The web.xml defines a servlet name for this Java Web
> Application, but chooses as an implementing clas some
> generic WebService Servlet class:
> [i]<servlet>
> <description>JAX-WS endpoint -
> fromjava_no_wsgen</description>
>
> display-name>fromjava_no_wsgen</display-name>
>
> servlet-name>fromjava_no_wsgen</servlet-name>
>
> servlet-class>com.sun.xml.ws.transport.http.servlet.WS
> Servlet</servlet-class>
> <load-on-startup>1</load-on-startup>
> rvlet>
> [/i]
> On the other hand, the sun-jaxws.xml in fact names
> the Application class with the @WebService
> annotation, but it makes no direct refence to the
> "fromjava_no_wsgen" servlet defined in the web.xml
> document.
>
> <endpoints
> xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime'
> version='2.0'>
> <endpoint
> name='fromjava'
>
> mplementation='fromjava_no_wsgen.server.AddNumbersImpl
> '
> url-pattern='/addnumbers'/>
> nts>
>
> So if they are complementatry, how does GlassFish
> know that when a request targets the
> com.sun.xml.ws.transport.http.servlet.WSServlet, this
> request should be transferred to the implementing
> class "fromjava_no_wsgen.server.AddNumbersImpl".
>
>
> Finally, can anyone actually summarize the correct
> Web Service development procedure?
>
> Like:
> 1: Make your class that uses @webService and
> @WebMethod
> 2: Compile your application using the APT tool (the
> one in the GlassFish web serrver - or somewhere else
> - i am not sure which should be used)
> 3: Generate your web service wsdl
> 4: Use Ant to make a WAR File containing all the
> previous stuff + web.xml and sun-jaxws.xml
> 5. AsAdmin deploy the war file
> 6: access sevletUrlPattern to cheack is your WSDL is
> accessible, which should imply everything worked out
> fine.
>
> I don't know if what I said is correct.
> I know that I am having difficulty making the
> deployed web services work properly.
>
>
> > Latest developments:
> IT seems my Web Applications were being correctly
> deployed, I did not know how to properly access wsdl
> of the web service because I was using an Incorrect
> link.
> The link should have been:
> "http://localhost:8080/jaxws-fromjava_no_wsgen/addnumb
> ers?wsdl"
> As explicitly written in the sample build.xml.
>
>
> My best regards,
> Thanks In advance,
> Nuno.
>
> Message was edited by: sono99
>
> Message was edited by: sono99
>
> Message was edited by: sono99
[Message sent by forum member 'bhaktimehta']

http://forums.java.net/jive/thread.jspa?messageID=476329