@WebService and dependency injection

I have the following web service:

@WebService

@Stateless

public class TestWS {

@EJB

private MyService myService;

@WebMethod

public void test() {

//at this point, "myService" is null !! It was not injected.

...

}

}

-I am using Sun System Application Server 9.0.

-My stateless session bean "MyService" is working well on another part of the application. i.e.: on my Managed beans "MyService" is been injected normally.

Web.xml

(...)

<listener>

<listener-class>

com.sun.xml.ws.transport.http.servlet.WSServletContextListener

</listener-class>

</listener>

<servlet>

<display-name>TestWS</display-name>

<servlet-name>TestWS</servlet-name>

<servlet-class>

com.sun.xml.ws.transport.http.servlet.WSServlet

</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>TestWS</servlet-name>

<url-pattern>/testws</url-pattern>

</servlet-mapping>

(...)

sun-jaxws.xml:

<?xml version="1.0" encoding="UTF-8"?>

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

version='2.0'>

<endpoint name='TestWS'

implementation='mypackage.TestWS'

url-pattern='/testws' />

</endpoints>

Am I doing all right?

[1485 byte] By [FelipeRiccettoa] at [2007-11-26 21:46:43]
# 1
How are you invoking the test method? You might want to check the server.log for anyerror messages and try running your application through the verifier tool. --ken
ksaksa at 2007-7-10 3:36:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

I am using the Admin Console web service tester.

When I execute the verifier:

# of Failures : 1

# of Warnings : 0

# of Errors : 0

Failed to find following classes:

[

com.sun.net.httpserver.HttpExchange

]

referenced in the following call stack :

at com.sun.xml.ws.handler.MessageContextUtil

at com.sun.xml.ws.encoding.JAXWSAttachmentMarshaller

at com.sun.xml.ws.model.RuntimeModel

at com.sun.xml.ws.server.RuntimeContext

at com.sun.xml.ws.encoding.soap.internal.AttachmentBlock$JAXBImpl

at com.sun.xml.ws.encoding.soap.internal.AttachmentBlock

at com.sun.xml.ws.encoding.soap.internal.InternalMessage

at com.sun.xml.ws.handler.HandlerContext

at com.sun.xml.ws.handler.XMLHandlerContext

at com.sun.xml.ws.handler.HandlerChainCaller

at com.sun.xml.ws.binding.soap.SOAPBindingImpl

at com.sun.xml.ws.server.RuntimeEndpointInfo

at com.sun.xml.ws.server.WSDLPublisher

at com.sun.xml.ws.transport.http.servlet.WSServletDelegate

at com.sun.xml.ws.transport.http.servlet.WSServlet

I didnt understand the cause of this error.

FelipeRiccettoa at 2007-7-10 3:36:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

The use of descriptors (like sun-jaxws.xml) denotes that you are trying to write a web service that strictly JAXWS based one and not a 109 based one. A strictly JAXWS based service does not support EJB endpoints. To have EJB endpoints, you have to develop a 109 based service. And for such a service you do not need web.xml, sun-jaxws.xml. You don't even need any descriptors !!!

Here are some useful links to help you with this :

http://java.sun.com/developer/EJTechTips/2006/tt0327.html#1

I would recommend that you develop a 109 based service because that is guaranteed to be portable across JavaEE5 containers. Such services do not require you to package any descriptors whatsoever. Let us know if you need more info

vijaysr1a at 2007-7-10 3:36:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Perfect ! :)Just one more thing.The AS generated the following URI for the WSDL: http://localhost:8080/TestWSService/TestWS?WSDLCan I change it to http://localhost:8080/myapplication/services/TestWS?WSDLfor example?Thanks
FelipeRiccettoa at 2007-7-10 3:36:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

the endpoint URI for the WSDL is not standard. Here is what sun's AS does :

For a servlet endpoint :

1. If there is a web.xml and the web.xml has url-pattern specified for the servlet endpoint, then endpoint address URI = context-root/url-pattern-for-servlet-endpoint-in-web.xml

2. If there is no web.xml or is no url-pattern specified for the servlet endpoint in a web.xml, then endpoint address URI = context-root/serviceName

For an EJB endpoint :

1. If sun-ejb-jar.xml is present and endpoint-address-uri is specified for the port, then whatever is present in the sun-ejb-jar.xml will be used as the endpoint address URI

2. If no endpoint-address-uri element is present, then the default URI is serviceName/portName

Here is a sample sun-ejb-jar.xml with endpoint-address-uri element :

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sun-ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Sun ONE Applicati

Server 8.0 EJB 2.1//EN' 'http://www.sun.com/software/sunone/appserver/dtds/su

ejb-jar_2_1-0.dtd'>

<sun-ejb-jar>

<enterprise-beans>

<name>Ping-ejb.jar</name>

<unique-id>0</unique-id>

<ejb>

<ejb-name>PingEjb</ejb-name>

<gen-classes/>

<webservice-endpoint>

<port-component-name>PingEjb</port-component-name>

<endpoint-address-uri>/PingEjbService/PingEjb</endpoint-address-uri>

</webservice-endpoint>

</ejb>

</enterprise-beans>

</sun-ejb-jar>

Note that sun-ejb-jar.xml is a Sun specific descriptor

vijaysr1a at 2007-7-10 3:36:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...