× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Pete Hall skrev den 28-04-2009 01:55:
Thorbjørn Ravn Andersen wrote:
I've made Metro 1.4 - the WebService layer in Glassfish - work with
Jetty, and I asked if there was basis for a paper article, but no, so I
was preparing to make a step-by-step blog entry with a WSDCi project.

Sounds like you might be interested?


Very much so Thorbjørn, and very grateful too.
Sure :) This works for me with deployment on Java 5 (_untested_ with Java 6) on V5R3.

I downloaded Metro 1.4 from https://metro.dev.java.net/1.4/ (version 1.5 is very new and I haven't looked at it), which eventually unpacks to several jar files.

Copy webservices-api.jar, webservices-rt.jar, webservices-extra-api.jar and webservices-extra.jar (four files) to the folder containing "blessed" jarfiles common to all of tomcat - I believe it is ${TOMCAT}/lib for Tomcat 6.[1]

In your Eclipse project eventually ending up to be a WAR file:

* If your workspace JRE is Java 5, you must add webservices-api.jar to the classpath (it should not be deployed in the end). If it is Java 6 you should be able to skip this step.

* Create a class foo.Ping looking like:

package foo;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
* Ping is a simple web service class providing a "yes, we have contact" class.
* Currently the doPing() method provides a response with the host name and
* address (if available) and the current server time.
*
*/
@javax.jws.WebService
public class Ping {

@javax.jws.WebMethod(action = "doPing")
public String doPing() {
System.out.println("Ping.doPing() called.");

String hostName;
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
hostName = "unknown (" + e.getMessage() + ")";
}

String hostAddress;
try {
hostAddress = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
hostAddress = "unknown (" + e.getMessage() + ")";
}

return "Reached '" + hostName + "' (" + hostAddress + ") at "
+ new java.util.Date() + " java.version="
+ System.getProperty("java.version", "(not set)");
}
}


* In your WEB-INF/web.xml add this snippet:


<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<description>JAX-WS endpoint - this servlet must handle all endpoints</description>
<display-name>webservice</display-name>
<servlet-name>webservice</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- each endpoint must have a mapping to the JAX-WS endpoint servlet -->

<servlet-mapping>
<servlet-name>webservice</servlet-name>
<url-pattern>/ws</url-pattern>
</servlet-mapping>


* Create a NEW file WEB-INF/sun-jaxws.xml:

<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime'
version='2.0'>

<endpoint name='ping' implementation='foo.Ping'
url-pattern='/ws'>
</endpoint
</endpoints>


* Ensure that both web.xml and sun-jaxws.xml are included in the deployment!

* Done!

Now deploy your war file to the Tomcat prepared above, and open "/ws" under your deployed web application. This might be "http://localhost:8080/foo/ws";. This will give you a page with information including a link to WSDL for all web services, including the Ping. This link can be used directly in any WSDL processing tool, including the web service tool in Eclipse JEE and WSDCi.

Hope this helps you :)



[1] Not making them global WILL give you classloader problems!


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.