1

Construi uma aplicação JAX-WS pelo Maven, porém não estou conseguindo implanta-la no servidor de aplicação Tomcat.

Seguem os os meus artefatos:

  • pom.xml:
<project
    xmlns = "http://maven.apache.org/POM/4.0.0"
    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>HelloWebService</groupId>
    <artifactId>HelloWebService</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>JAX-WS webservice with maven</name>
    <url>http://maven.apache.org</url>
   <dependencies>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.1.3</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>HelloService</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

A classe que representa meu web service:

package HelloWebService;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

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

    @WebMethod(operationName = "sayHello")
    public String sayHello(@WebParam(name="guestname") String guestname){
        if(guestname==null){
            return "Hello";
        }
        return "Hello "+ guestname;
    }

}

Arquivos do diretório WEB-INF:

  • 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="HelloWebService" implementation="HelloWebService.HelloWebService" url-pattern="/helloWebService" ></endpoint>
  • web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  id="WebApp_ID" version="2.5">

  <display-name>jaxwsExample</display-name>

  <listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>helloWebService</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>helloWebService</servlet-name>
    <url-pattern>/helloWebService</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>120</session-timeout>
  </session-config>
</web-app>

Copiei o WAR gerado pelo maven para TOMCAT_HOME/webapps, porém ao subir o servidor o seguinte log é gerado:

Set 05, 2015 9:40:42 AM org.apache.catalina.core.StandardContext listenerStart
Grave: Exception sending context initialized event to listener instance of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to parse runtime descriptor: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,128]
Message: XML document structures must start and end within the same entity.
    at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    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:744)
Caused by: com.sun.xml.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,128]
Message: XML document structures must start and end within the same entity.
    at com.sun.xml.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:267)
    at com.sun.xml.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:95)
    at com.sun.xml.ws.streaming.XMLStreamReaderUtil.nextContent(XMLStreamReaderUtil.java:110)
    at com.sun.xml.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:100)
    at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:211)
    at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147)
    at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:108)
    ... 13 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,128]
Message: XML document structures must start and end within the same entity.
    at com.sun.xml.stream.XMLReaderImpl.next(XMLReaderImpl.java:571)
    at com.sun.xml.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:92)
    at com.sun.xml.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:76)
    ... 18 more

Set 05, 2015 9:40:45 AM org.apache.catalina.core.ApplicationContext log
Informações: ContextListener: contextInitialized()
Set 05, 2015 9:40:45 AM org.apache.catalina.core.ApplicationContext log
Informações: SessionListener: contextInitialized()
Set 05, 2015 9:40:45 AM org.apache.catalina.core.ApplicationContext log
Informações: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@7192a096')
2

1 Resposta 1

1

O erro é ao parsear seu arquivo sun-jaxws.xml, como mostra este trecho do log:

WSSERVLET11: failed to parse runtime descriptor: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,128]

Na mensagem abaixo o erro sugere que os elementos a estrutura do documento deve começar e terminar com o mesmo tipo de elemento:

Message: XML document structures must start and end within the same entity.

Se observar seu arquivo, verá que está faltando fechar o elemento endpoints. Então, considere usar este conteúdo em seu 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="HelloWebService" implementation="HelloWebService.HelloWebService" url-pattern="/helloWebService"></endpoint>
</endpoints>
2
  • Bruno, muito obrigado. Ao arrumar a estrutura do xml funcionou perfeitamente. 5/09/2015 às 14:16
  • @FilipeCanatto OK, caso tenha sido útil, considere aceitar a resposta. 5/09/2015 às 15:35

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .