java - 404 error with Rest Service - Jersey/tomcat8 -
i have been trying past couple of days many examples, not able make rest service running. have tomcat8(ubuntu 14.x)/jersey. idea?
pom.xml snippet
<dependencies> <dependency> <groupid>javax.ws.rs</groupid> <artifactid>jsr311-api</artifactid> <version>1.1.1</version> <scope>provided</scope> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-server</artifactid> <version>1.18.1</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-servlet</artifactid> <version>1.18.1</version> </dependency> </dependencies>
web.xml snippet
<servlet> <servlet-name>restservice</servlet-name> <!--servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class--> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <!--param-name>jersey.config.server.provider.packages</param-name--> <param-value>mail.service</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>restservice</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
no errors on tomcat startup:
11-jul-2015 11:23:08.327 info [localhost-startstop-8] com.sun.jersey.server.impl.application.webapplicationimpl._initiate initiating jersey application, version 'jersey: 1.18.1 02/19/2014 03:28 am' 11-jul-2015 11:23:08.795 info [localhost-startstop-8] org.apache.catalina.startup.hostconfig.deploywar deployment of web application archive /home/apcuser/tomcat8/apache-tomcat-8.0.24/webapps/exprocess.war has finished in 1,488 ms
rest service class:
package mail.service; import javax.ws.rs.consumes; import javax.ws.rs.get; import javax.ws.rs.put; import javax.ws.rs.path; import javax.ws.rs.pathparam; import javax.ws.rs.produces; import javax.ws.rs.core.context; import javax.ws.rs.core.mediatype; import javax.ws.rs.core.request; import javax.ws.rs.core.response; import javax.ws.rs.core.uriinfo; import javax.xml.bind.jaxbelement; //import org.slf4j.logger; //import org.slf4j.loggerfactory; @path("restservice") public class restservice { @context uriinfo uriinfo; @context request request; string id; @get @path("{name}") public string sayhello(@pathparam("name") string name){ return "hello " + name; } }
result:
http status 404 - /rest/restservice/testname
update: couldn't figure out whats wrong project, started scratch following : http://javabrains.koushik.org/courses/javaee_jaxrs/lessons/setting-up works now.
@path("/restservice") public class restservice { @context uriinfo uriinfo; @context request request; string id; @get @path("/{name}") @produces(mediatype.text_plain) public string sayhello(@pathparam("name") string name){ return "hello " + name; } }
http 404 file not found error, getting because didn't append /
@path
annotation value.
@path("restservice")
should @path("/restservice")
, @path("{name}")
should @path("/{name}")
edit update-
added @produces(mediatype.text_plain)
Comments
Post a Comment