Webservice Restful Jersey

Asked

Viewed 366 times

0

I am starting the development of Webservice Restful Jersey in Java and I am not able to connect to realize a simple Hello World.

I added the jar:

  • asm-3.1jar
  • jersey-core-1.19jar
  • jersey-server-1.19jar
  • jersey-Servlet-1.19jar
  • jrr311-api.1.1.jar

I created the Hello class:

package com.k19.restful.resources; 

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;  

@Path("/helloworld") 
public class Hello {

    @GET @Produces("text/plain") 
    public String showHelloWorld() { 
        return "Olá mundo!"; 
    }

}

I set up web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app> 
    <display-name>jersey-tutorial</display-name>
    <servlet> 
        <servlet-name>Jersey REST Service</servlet-name> 
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param> 
            <param-name>com.sun.jersey.config.property.packages</param-name> 
            <param-value>com.k19.restful.resources</param-value>
        </init-param> 
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping> 
        <servlet-name>Jersey REST Service</servlet-name> 
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

I’m using Tomcat, it boots normally... but when I enter the url:

http://localhost:8080/jersey-tutorial/helloworld

Error 404. Door is 8080...

Is there any other procedure I need to do?

Log generated on Tomcat startup:

Mai 01, 2015 8:43:25 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
Advertência: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ExemploWS' did not find a matching property.
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Server version:        Apache Tomcat/7.0.59
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Server built:          Jan 28 2015 15:51:10 UTC
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Server number:         7.0.59.0
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: OS Name:               Windows 7
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: OS Version:            6.1
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Architecture:          amd64
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Java Home:             C:\Program Files\Java\jre7
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: JVM Version:           1.7.0_01-b08
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: JVM Vendor:            Oracle Corporation
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: CATALINA_BASE:         C:\Users\paula\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 7.0
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Command line argument: -Dcatalina.base=C:\Users\paula\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 7.0
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Command line argument: -Dwtp.deploy=C:\Users\paula\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 7.0\endorsed
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.VersionLoggerListener log
Informações: Command line argument: -Dfile.encoding=Cp1252
Mai 01, 2015 8:43:25 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
Informações: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;c:\Program Files (x86)\AMD APP\bin\x86_64;c:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Sony\VAIO Improvement\;C:\Program Files (x86)\Sony\VAIO Startup Setting Tool;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Skype\Phone\;.
Mai 01, 2015 8:43:25 PM org.apache.coyote.AbstractProtocol init
Informações: Initializing ProtocolHandler ["http-bio-8080"]
Mai 01, 2015 8:43:25 PM org.apache.coyote.AbstractProtocol init
Informações: Initializing ProtocolHandler ["ajp-bio-8009"]
Mai 01, 2015 8:43:25 PM org.apache.catalina.startup.Catalina load
Informações: Initialization processed in 1340 ms
Mai 01, 2015 8:43:25 PM org.apache.catalina.core.StandardService startInternal
Informações: Starting service Catalina
Mai 01, 2015 8:43:25 PM org.apache.catalina.core.StandardEngine startInternal
Informações: Starting Servlet Engine: Apache Tomcat/7.0.59
[WARN] Web application uses org.apache.axis2.transport.http.AxisAdminServlet; please update web.xml to use org.apache.axis2.webapp.AxisAdminServlet instead
[INFO] Clustering has been disabled
[INFO] Deploying module: addressing-1.6.2 - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/modules/addressing-1.6.2.mar
[INFO] Deploying module: metadataExchange-1.6.2 - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/modules/mex-1.6.2.mar
[INFO] Deploying module: mtompolicy-1.6.2 - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/modules/mtompolicy-1.6.2.mar
[INFO] Deploying module: ping-1.6.2 - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/modules/ping-1.6.2.mar
[INFO] Deploying module: script-1.6.2 - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/modules/scripting-1.6.2.mar
[INFO] Deploying module: soapmonitor-1.6.2 - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/modules/soapmonitor-1.6.2.mar
[INFO] Deploying Web service: UsuarioDAO - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/services/UsuarioDAO/
[INFO] Deploying Web service: version.aar - file:/C:/Users/paula/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ExemploWS/WEB-INF/services/version.aar
[WARN] No transportReceiver for org.apache.axis2.transport.http.AxisServletListener found. An instance for HTTP will be configured automatically. Please update your axis2.xml file!
Mai 01, 2015 8:43:32 PM org.apache.coyote.AbstractProtocol start
Informações: Starting ProtocolHandler ["http-bio-8080"]
Mai 01, 2015 8:43:32 PM org.apache.coyote.AbstractProtocol start
Informações: Starting ProtocolHandler ["ajp-bio-8009"]
Mai 01, 2015 8:43:32 PM org.apache.catalina.startup.Catalina start
Informações: Server startup in 7000 ms
  • try to put in your method also for example @Path("/showHelloWorld") and then access: http://localhost:8080/jersey-tutorial/helloworld/showHelloWorld

  • Paula, I tested your example here and it’s OK. Can you include the Tomcat startup log? Maybe by logging we can see what it might be. Probably "root classes" were not found, so 404, that is, did not publish the resource.

  • Bruno, yes I can! I opened in the eclipse a webservice that I had already made with SOAP and ran right. I think some configuration is missing, for example Axis.I will edit the question and put the log

  • Paula, thank you for updating. But you would need the Tomcat log starting with the jersey-tutorial and not with other projects. The problem is not the lack of axis, it is a SOAP implementation. Try starting Tomcat with only jersey-tutorial published by the log I may be able to help you. Also, if possible, show the directory structure of jersey-tutorial, may be that the web.xml is not being published.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.