GeeCON Prague 2014*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Regarding creation of servlet endpoint for  web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Regarding creation of servlet endpoint for  web service" Watch "Regarding creation of servlet endpoint for  web service" New topic
Author

Regarding creation of servlet endpoint for web service

Vasaunth Babu Raju
Greenhorn

Joined: Jun 09, 2009
Posts: 6
I created a servlet end point following the below steps


Make a webapplication/ In eclipse you can make a project which is a dynamic web project.Let's write a POJO bean class which can be invoked by sending a SOAP Request which contains a string and it will return the response "Hello World" + input String.

POJO class:

@WebService
@SOAPBinding(style=SOAPBinding.Style.RPC)
public class HelloBean{

@WebMethod
public String hello(String name){
return "Hello " + name;
}
}

Note the annotation on the bean class. The class does not implements any interface.
Register this bean as a servlet in the web,xml

<servlet>
<servlet-name>helloBean</servlet-name>
<servlet-class>com.oyeJava.HelloBean</servlet-class>

</servlet>
<servlet-mapping>
<servlet-name>helloBean</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

Deploy the war in your server and hit the service at:
http://<hostname>/JAX_WS_HelloWorld/hello?wsdl


When I connect to the above URL I get an exception stating "javax.servlet.ServletException: Class com.service.Hello is not a Servlet"


Kindly let men know how to proceed further?

What was the fault in the above code.

Regards,
Vasanth.

Regards,
Vasanth
SCJP,SCWCD
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
When developing a web service endpoint, you do not need to configure the web.xml deployment descriptor.
In fact, the problem you have originates from the fact that you try to configure the endpoint as a servlet, which it obviously not is, since it does not implement the Servlet interface.
JAX-WS will, when the web service is deployed, create a servlet that takes care of receiving requests destined to your endpoint.
It is possible to configure web.xml and the webservices.xml deployment descriptor, but things quickly becomes rather complicated, because the configuration in the different deployment descriptors etc have to be coordinated and it is easy to make mistakes.
Best wishes!
Vasaunth Babu Raju
Greenhorn

Joined: Jun 09, 2009
Posts: 6
Hi,
First of all thanks for your reply.Your study guide is great it Rocks.


Regrarding the below reply,

Actually when I follow the below approach it runs perfectly.

1. Create an annotated end point for Hello as in previous mail.
2.use
wsgen -cp . com.service.HelloBean -wsdl

to generate ws artifacts.
3. Use the following code to publish the WS
Endpoint.publish("http://localhost:8080/HelloWorldWeb/Hello",
new HelloBean());

3. When I traverse to the below URL I see the corresponding WSDL.
http://localhost:8080/HelloWorldWeb/Hello

But My question is
How do I expose it as a servlet end point?
In other words, with out using Endpoint.publish("http://localhost:8080/HelloWorldWeb/Hello",new HelloBean()); How do I publish it in tomcat.

As you said previously, if JAX-WS generates a servlet, which URL should I use to access the WSDL? As I have no where configured the URL as in this case.


Thanks and awaiting for your reply,

Vasanth





Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hello!
Ah, now I think I understand your question!
First of all, I suggest that you deploy web services to GlassFish - it will make life easier for you. Tomcat in itself is not enough to run JAX-WS web services.
Second, if you have my study notes, then why not read them?!? :-) There are instructions on how to write a web service that is later published to GlassFish.

Generally, you develop a dynamic web project, same as you would if you were to implement a servlet.
In that project, you implement a POJO which you annotate with web service annotation(s) as desired.
Finally, you deploy the web project to, for instance, GlassFish.
The JAX-WS runtime will generate all the required artifacts for you at deployment time, such as WSDL, wrapper servlet, deployment descriptors etc. If you use GlassFish you will be able to easily view the generated deployment descriptors, the WSDL from the GlassFish manager console.
Best wishes!
Vasaunth Babu Raju
Greenhorn

Joined: Jun 09, 2009
Posts: 6
Its working now........

Thanks Ivan.


Regards,
Vasanth
 
GeeCON Prague 2014
 
subject: Regarding creation of servlet endpoint for web service