Tuesday, April 7, 2015

Error deploying soap application : org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener

i have mkyong project to test web application deployment in tomcat. it was not working properly. So thought of sharing my thoughts.
link is shown as below.
http://www.mkyong.com/webservices/jax-ws/jax-ws-java-web-application-integration-example/


Following is the error you will get when you try to deploy the web application in Tomcat.


=================================================================

org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
 java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1132)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:549)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:530)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4652)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5158)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1762)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)


====================================================================

Solution : Add jaxws-rt.jar to the lib folder of the tomcat.

you can download whole project from the
 https://jax-ws.java.net/
Download jax-ws ri distribution
unzip it and copy paste jaxws-rt.jar to tomcat lib folder
restart tomcat.

But there can be issue with 64 and 32 bit platforms.

My suggestion is to add jaxws-rt as a maven dependency.

        <dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>


This will add below list of dependencies to the lib folder inside "WEB-INF" in the built war file (maven build project war file). Numbers represent the size of each jar file and those might change with the time.

         296,714 FastInfoset-1.2.13.jar
          21,820 gmbal-api-only-3.1.0-b001.jar
          36,383 ha-api-3.1.9.jar
          26,366 javax.annotation-api-1.2.jar
          41,135 javax.xml.soap-api-1.3.7.jar
         102,308 jaxb-api-2.2.12-b140109.1041.jar
         234,226 jaxb-core-2.2.10-b140802.1033.jar
       1,040,864 jaxb-impl-2.2.10-b140802.1033.jar
          50,360 jaxws-api-2.2.11.jar
       2,505,911 jaxws-rt-2.2.10.jar
           7,989 jsr181-api-1.0-MR1.jar
          42,212 management-api-3.0.0-b012.jar
          63,134 mimepull-1.9.4.jar
         161,631 policy-2.4.jar
          68,177 resolver-20050927.jar
         474,791 saaj-impl-1.3.25.jar
          33,739 stax-ex-1.7.7.jar
         182,112 stax2-api-3.1.1.jar
          65,851 streambuffer-1.5.3.jar
         482,245 woodstox-core-asl-4.2.0.jar

Once you do this you will get the output as "Hello World"
This is what we have included inside the index.html page.
======================================================
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
======================================================


The link to the service also http://localhost:8080/webservices/  not " http://localhost:8080/WebServicesExample/hello "

so if you need to access the wsdl use below link
http://localhost:8080/webservices/hello?wsdl

we are using hello?wsdl cause the webmethod is configured to 'hello' in the endpoint inside the "sun-jaxws.xml" where the configurations for the endpoints are given.


java class

=============================================

package com.mkyong.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class HelloWorld{

@WebMethod(operationName="getHelloWorld")
public String getHelloWorld(String name) {
return "Hello World JAX-WS " + name;
}

}

===============================================
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="HelloWorldWs"
      implementation="com.mkyong.ws.HelloWorld"
      url-pattern="/hello"/>
</endpoints>
===========================================================



the wsdl will looks like below
http://localhost:8080/webservices/hello?wsdl
========================================================================
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.
-->
<!--
 Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.mkyong.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.mkyong.com/" name="HelloWorldService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.mkyong.com/" schemaLocation="http://localhost:8080/webservices/hello?xsd=1"/>
</xsd:schema>
</types>
<message name="getHelloWorld">
<part name="parameters" element="tns:getHelloWorld"/>
</message>
<message name="getHelloWorldResponse">
<part name="parameters" element="tns:getHelloWorldResponse"/>
</message>
<portType name="HelloWorld">
<operation name="getHelloWorld">
<input wsam:Action="http://ws.mkyong.com/HelloWorld/getHelloWorldRequest" message="tns:getHelloWorld"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorld/getHelloWorldResponse" message="tns:getHelloWorldResponse"/>
</operation>
</portType>
<binding name="HelloWorldPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getHelloWorld">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HelloWorldService">
<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">
<soap:address location="http://localhost:8080/webservices/hello"/>
</port>
</service>
</definitions>
========================================================================

No comments:

Post a Comment