The Source for Java Technology Collaboration

Home » java.net Forums » Java Web Services and XML » Java WS & XML Community News

Thread: Running Sample WS on Tomcat 6

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Last Post: Nov 12, 2009 7:39 AM by: jebricker Threads: [ Previous | Next ]
jebricker

Posts: 3
Running Sample WS on Tomcat 6
Posted: Nov 2, 2009 7:46 AM
 
  Click to reply to this thread Reply

I'm running NetBeans 6.7.1 and am taking the sample Calculator WS and client and trying to run them on Tomcat. They were made for Glassfish. I'm getting a couple of problems.

#1 I can not seem to pick up the WSDL when I deploy the service. It is in the WAR file but I can not seem to pick it up once deployed.
#2 The Client Context can not find servlet.

I removed the @WebServiceRef based on recommendations of this board. I've read that this might be that the jaxws 2.1.1 jars are in Glassfish and not in Tomcat. I added the jaxws-tool.jar to the Client project but no other jars. The Service has the complete jaxws 2.1 Library in the project.

any recommendations on getting this running? Thanks,
import java.io.*;
import java.net.*;
import javax.annotation.Resource;
 
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceRef;
 
/**
 *
 * @author mg116726
 */
public class ClientServlet extends HttpServlet {
 
    public CalculatorWSService service;
    
    @Resource
    protected WebServiceContext context;
    
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<h2>Servlet ClientServlet at " + request.getContextPath () + "</h2>");
                service = new CalculatorWSService();
                org.me.calculator.client.CalculatorWS port = service.getCalculatorWSPort();
 
                int i = Integer.parseInt(request.getParameter("value1"));
                int j = Integer.parseInt(request.getParameter("value2"));
 
                int result = port.multiply(i, j);
             
                out.println("<br/>");
                out.println("Result:");
                out.println("" + i + " x " + j + " = " + result);
                ((Closeable)port).close();
            
        } finally { 
            out.close();
        }
    } 
 


javax.servlet.ServletException: Error instantiating servlet class org.me.calculator.client.ClientServlet
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	java.lang.Thread.run(Thread.java:619)
 
root cause
 
javax.naming.NameNotFoundException: Name org.me.calculator.client.ClientServlet is not bound in this Context
	org.apache.naming.NamingContext.lookup(NamingContext.java:770)
	org.apache.naming.NamingContext.lookup(NamingContext.java:153)
	org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:265)
	org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:174)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	java.lang.Thread.run(Thread.java:619)


Message was edited by: jebricker

Message was edited by: jebricker

jebricker

Posts: 3
Re: Running Sample WS on Tomcat 6
Posted: Nov 12, 2009 7:35 AM   in response to: jebricker
 
  Click to reply to this thread Reply

I will answer my own question and pose another.

Initially, I took the sample Calculator service and client and ran them on Glassfish and they worked perfectly. When I changed the build to Tomcat it broke down.

First problem was that while Glassfish had the jaxws libraries in it tomcat 6 did not. First I added them to the Service but later I found it was better to add them to the $CATALINA_HOME/lib directory and remove them from the service.

The other problem was the annotations. My client could not find the context.
 public CalculatorWSService service;
    
   [b] @Resource[/b]
    protected WebServiceContext context;


I forgot to remove this one annotation and that was causing the problem.

Now on to the next set of problems. the xml config files. It seems that Tomcat 6 likes things a bit different and I have not been able to figure this out yet. Right not the client can not find the endpoint.

Service web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>CalculatorApp</display-name>
    <listener>
        <listener-class>org.me.calculator.CalculatorWS</listener-class>
    </listener>
    <servlet>
        <servlet-name>CalculatorWSService</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CalculatorWSService</servlet-name>
        <url-pattern>/CalculatorWS</url-pattern>
    </servlet-mapping>
    <service-ref>
            <service-ref-name>CalculatorApp/CalculatorWSService</service-ref-name>
            <service-interface>javax.xml.ws.Service</service-interface>
            <wsdl-file>/WEB-INF/wsdl/CalculatorWSService.wsdl</wsdl-file>
        </service-ref>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>


Service sun-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" 
"http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
  <context-root>/CalculatorApp</context-root>
  <servlet>
    <servlet-name>CalculatorAppServlet</servlet-name>
    <webservice-endpoint>
      <port-component-name>CalculatorWSService</port-component-name>
      <endpoint-address-uri>/CalculatorApp/CalculatorWSService</endpoint-address-uri>
      <transport-guarantee>NONE</transport-guarantee>
    </webservice-endpoint>
  </servlet>
  <endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
    <endpoint implementation="org.me.calculator" name="CalculatorWSService" url-pattern="/CalculatorWS"/>
  </endpoints>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
  <webservice-description>
    <webservice-description-name>CalculatorApp</webservice-description-name>
    <wsdl-publish-location>/WEB-INF/wsdl</wsdl-publish-location>
  </webservice-description>
</sun-web-app>


client web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>ClientServlet</servlet-name>
        <servlet-class>org.me.calculator.client.ClientServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ClientServlet</servlet-name>
        <url-pattern>/ClientServlet</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <service-ref>
            <service-ref-name>CalculatorApp/CalculatorWSService</service-ref-name>
            <service-interface>javax.xml.ws.Service</service-interface>
            <wsdl-file>/WEB-INF/wsdl/CalculatorWSService.wsdl</wsdl-file>
        </service-ref>
 
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>


client sun-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" 
"http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
  <context-root>/CalculatorClientApp</context-root>
  <servlet>
    <servlet-name>ClientServlet</servlet-name>
  </servlet>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</sun-web-app>
 


WSDL
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.4-b01-. -->
<definitions targetNamespace="http://calculator.me.org/" name="CalculatorWSService" 
xmlns="http://schemas.xmlsoap.org/wsdl/" 
xmlns:tns="http://calculator.me.org/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <types>
    <xsd:schema>
    <!--  <xsd:import namespace="http://calculator.me.org/" schemaLocation="CalculatorWSService_schema1.xsd"/>-->
    <xsd:element name="multiply" type="tns:multiply"/>
 
  <xsd:element name="multiplyResponse" type="tns:multiplyResponse"/>
 
  <xsd:complexType name="multiply">
    <xsd:sequence>
      <xsd:element name="i" type="xs:int"/>
      <xsd:element name="j" type="xs:int"/>
    </xsd:sequence>
  </xsd:complexType>
 
  <xsd:complexType name="multiplyResponse">
    <xsd:sequence>
      <xsd:element name="return" type="xs:int"/>
    </xsd:sequence>
  </xsd:complexType>
    </xsd:schema>
  </types>
  <message name="multiply">
    <part name="parameters" element="tns:multiply"/>
  </message>
  <message name="multiplyResponse">
    <part name="parameters" element="tns:multiplyResponse"/>
  </message>
  <portType name="CalculatorWS">
    <operation name="multiply">
      <input message="tns:multiply"/>
      <output message="tns:multiplyResponse"/>
    </operation>
  </portType>
  <binding name="CalculatorWSPortBinding" type="tns:CalculatorWS">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="multiply">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
  <service name="CalculatorWSService">
    <port name="CalculatorWSPort" binding="tns:CalculatorWSPortBinding">
      <soap:address location="http://localhost:8080/CalculatorApp/CalculatorWSService"/>
    </port>
  </service>
</definitions>
 
 


Message was edited by: jebricker




 XML java.net RSS