Jersey 2.x JSP pages redirection - java

I have this problem. I'm trying to use Jersey 2.x in order to make REST api, and I would like to use jsp pages for my template (everything without spring or springboot, I can't include them into my project). I have a maven project with this structure:
enter image description here
the pom.xml has the following dependencies:
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc-jsp</artifactId>
<version>2.27</version>
</dependency>
</dependencies>
and the web.xml is:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>testjsp</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>it.testjsp.config.JerseyConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>testjsp</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
When I run my app with tomcat, the following url
http://localhost/testjsp
redirects correctly the index.hml.
I have configured the JerseyConfig class in the following way:
#ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
packages("it.testjsp.endpoints");
register(JspMvcFeature.class);
property("jersey.config.server.mvc.templateBasePath", "/WEB-INF/jsp");
}
}
In order to map all the end points exposed into that package and to use jsp pages into WEB-INF/JSP.
I have two end points:
#Path("/test")
#Produces(MediaType.APPLICATION_JSON)
public class TestEndPoint {
#GET
public Map<String, Object> testApi() {
System.out.println("test jersey 2.27");
Map<String, Object> result = new HashMap<String, Object>();
result.put("result", "test jersey 2.27");
return result;
}
}
This is inside TestEndPoint class and the application responds as I expect (http://localhost/testjsp/api/test returns the json).
The PagesEndPoint is:
#Path("/pages")
public class PagesEndPoint {
#GET
#Path("{pageName}")
public Viewable getPage(#PathParam("pageName") String pageName) {
System.out.println("Try " + pageName + ".html");
return new Viewable("/" + pageName + ".html");
}
}
But when I run the app with tomcat, I have always a 404. Is possible to use jsp (or other html pages)? What I did wrong? Thanks for the help

Related

ContainerException: The ResourceConfig instance does not contain any root resource classes while deploying my app on Wildfly Server

i'm trying to make a simple rest service and deploy the app on wildfly server and when i try to deploy my app on server i have the following exception:
Cannot upload deployment: {"WFLYCTL0080: Failed services" =>
{"jboss.undertow.deployment.default-server.default-host./resttestapp" =>
"org.jboss.msc.service.StartException in service
jboss.undertow.deployment.default-server.default-host./resttestapp:
com.sun.jersey.api.container.ContainerException: The ResourceConfig
instance does not contain any root resource classes. Caused by:
com.sun.jersey.api.container.ContainerException: The ResourceConfig
instance does not contain any root resource classes."}}
I've tried a lot of thing from stackoverflow but nothing works for me.
I'm using Wildfly 9.0.2 (standalone, deploying via admin console), Intellij idea.
This is part of my pom.xml:
<groupId>cz.prg.rob</groupId>
<artifactId>resttestapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>resttestapp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<jersey.version>1.19.4</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
</dependencies>
This is my web.xml:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>JerseyServlet</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>cz.prg.rob</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
This is my service class:
package cz.prg.rob;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import java.util.Date;
#Path("/name")
public class UserService {
#GET
#Produces("text/plain")
public String getName() {
return "Qwerty";
}
#GET
#Path("/user")
#Produces("application/json")
public User getUser(#QueryParam("name") String name, #QueryParam("surname") String surname, #QueryParam("birthDate") Date birthDate) {
return new User(name, surname, birthDate);
}
}
and this is a part of my User (model) class:
#NoArgsConstructor
#AllArgsConstructor
#Data
public class User {
private String name;
private String surname;
private Date birthDate;
}
This is my project structure:
I can't understand what i'm doing wrong. Please help me.
The solution that helped me:
I've added this as init param of JerseyServlet
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>cz.prg.rob.UserServiceApplication</param-value>
</init-param>
And this is the class where i've defined my resource class
public class UserServiceApplication extends Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(UserService.class);
return s;
}
}
So looks like i have to say to jersey which classes are resource classes explicitly. If you want to add new resource classes just add them in HashSet into getClasses() method.

Spring MVC : URL Pattern

here is my web.xml
<servlet>
<servlet-name>Learn</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Learn</servlet-name>
<url-pattern>/learn/*</url-pattern>
</servlet-mapping>
if i change this code
<url-pattern>/learn/*</url-pattern>
to
<url-pattern>/learn/abc/</url-pattern>
i can hit my controller code which is given as
#Controller
#RequestMapping(value = "/learn")
public class ControllerClass
{
#RequestMapping(value = "/", method = RequestMethod.GET)
public String callRequest(ModelMap model)
{
return "index";
}
#RequestMapping(value = "/abc/", method = RequestMethod.GET)
public String personController(ModelMap model)
{
return "welcome";
}
}
but i also want to hit the first method or i will add more method, which i can not achieve by
/learn/abc/
in url mapping.
so please help me out with this
pom.xml
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- spring-context which provides core functionality -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-aop module provides an AOP Alliance-compliant aspect-oriented
programming implementation allowing you to define -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-webmvc module (also known as the Web-Servlet module) contains
Spring’s model-view-controller (MVC) and REST Web Services implementation
for web applications -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-web module provides basic web-oriented integration features
such as multipart file upload functionality and the initialization of the
IoC container using Servlet listeners and a web-oriented application context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
please let me know if i missed any dependency
With this url-pattern <url-pattern>/learn/*</url-pattern> configuration, to hit your method, the url path will be: /learn/learn
The url-pattern atribute on the web.xml works like a basepath for spring's servlet. So a good option is to change your url-pattern to /* , like this:
<url-pattern>/*</url-pattern>
Or if you want some basepath, change the url pattern to something like this:
/basepath/*
And to hit your method, you need to use the path url: /basepath/learn

Jersey - Multipart data form with text body parts

I am trying to send Multipart Form into the Jersey 2.22.1 server as a POST request. This request contains file and multiple text fields. What is happening on the server side is that I can only receive file as InputStream, but all text arguments, which I'm receivin are null.
Here's what I have:
pom.xml:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.22.1</version> <!-- Make sure the Jersey matches
the one you are currently using -->
</dependency>
<dependency>
<groupId>org.jvnet.mimepull</groupId>
<artifactId>mimepull</artifactId>
<version>1.9.6</version>
</dependency>
web.xml:
<servlet>
<servlet-name>vedica-api</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.media.multipart.MultiPartFeature
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.nws.vedica.api,com.fasterxml.jackson</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
and code:
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
...
#POST
#Produces("text/plain")
#Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createDocument(
#FormDataParam("meno") String name,
#FormDataParam("rc") String rc,
#FormDataParam("typzml") String typzml,
#FormDataParam("auto") String auto,
#FormDataParam("verzia") String verzia,
#FormDataParam("documentcustomname") String doccustomname,
#FormDataParam("docpath") String docpath,
#FormDataParam("file") InputStream data,
#FormDataParam("file") FormDataContentDisposition fileInfo
) {
...
return Response.ok().build();
}
so all the String parameters are null.
And here is screenshot of how I'm sendin the request:
can you explain what am I doing wrong and how to fix this?
Thanks
okey, so I found that it was my IDE that was incorrectly creating war package. Code and dependencies are fine, but at least I have found out that parameters are case sensitive!

Another Guice + Jersey error NoSuchMethodError

Well, GeneralUtilities does not even have the method getSystemProperty so not so weird it fails.
What is the best way to handle this?
Deploying on Liberty Profile.
Error:
[1/12/16 15:01:58:482 CET] 00000027 com.ibm.ws.webcontainer.servlet E SRVE0271E: Uncaught init() exception created by servlet [Jersey Web Application] in application [Agent-1.0.0-SNAPSHOT]: java.lang.NoSuchMethodError: org/glassfish/hk2/utilities/general/GeneralUtilities.getSystemProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
at org.jvnet.hk2.internal.ServiceLocatorImpl.<clinit>(ServiceLocatorImpl.java:122)
at org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl.initialize(ServiceLocatorGeneratorImpl.java:66)
at org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl.create(ServiceLocatorGeneratorImpl.java:98)
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.internalCreate(ServiceLocatorFactoryImpl.java:312)
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.create(ServiceLocatorFactoryImpl.java:268)
at org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:138)
at org.glassfish.jersey.internal.inject.Injections.createLocator(Injections.java:123)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:308)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:338)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:171)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:363)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:332)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadOnStartupCheck(ServletWrapper.java:1423)
at com.ibm.ws.webcontainer.webapp.WebApp.doLoadOnStartupActions(WebApp.java:1180)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinally(WebApp.java:1148)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1054)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6448)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:446)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:441)
at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:980)
at com.ibm.ws.webcontainer.osgi.WebContainer.startModule(WebContainer.java:804)
at com.ibm.ws.app.manager.web.internal.WebModuleHandlerImpl.deployModule(WebModuleHandlerImpl.java:102)
at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployModule(DeployedAppInfoBase.java:874)
at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployModules(DeployedAppInfoBase.java:834)
at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:821)
at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:80)
at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:139)
at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1168)
at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:781)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1143)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:618)
at java.lang.Thread.run(Thread.java:785)
JerseyConfig
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.jersey.server.ResourceConfig;
import org.jvnet.hk2.guice.bridge.api.GuiceBridge;
import org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge;
import javax.inject.Inject;
public class JerseyConfig extends ResourceConfig {
#Inject
public JerseyConfig(ServiceLocator locator) {
packages("no.services.agent");
GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
// add your Guice modules.
Injector injector = Guice.createInjector(new GuiceModule());
GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class);
guiceBridge.bridgeGuiceInjector(injector);
}
}
SelftestResource
#Path("/")
#Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.TEXT_HTML})
#Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.TEXT_HTML})
public class SelftestResource {
#GET
public Response selftest(){
return Response.ok().build();
}
}
web.xml
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.services.agent.guice.JerseyConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>guice-bridge</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
Based on what you said I believe the fix is to use the 2.4.0-b31 version of the guice-bridge

Restfull Webservice Maven Project netbeans

I'm looking at every way to try to make a request type to get to my web service created by restfull Webservice into a project with Tomcat , Maven and some servlets , but nothing I do not start by mistake does not find the resource . What am I doing wrong? I may not have configured the web.xml ? how can I do?
I put the file pom.xml below and
<dependencies>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20150729</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
</dependencies>
This is code of my web service:
#Path("ws")
public class WsUserJson {
#Context
private UriInfo context;
/**
* Creates a new instance of WsUserJson
*/
public WsUserJson() {
}
/**
* Retrieves representation of an instance of com.lillonet.testmavenservletws.WsUserJson
* #return an instance of java.lang.String
*/
#GET
#Produces("application/json")
public String getJson(#QueryParam("name") String nome) {
//TODO return proper representation object
return "{"+nome+"}";
}
/**
* PUT method for updating or creating an instance of WsUserJson
* #param content representation for the resource
* #return an HTTP response with content of the updated or created resource.
*/
#PUT
#Consumes("application/json")
public void putJson(String content) {
}
}
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
That is only a jar with a bunch of interfaces. There is no implementation. That dependency should only be used when you plan on deploying to a an EE compliant Server, like Glassfish or Wildfly. Tomcat is not an EE compliant server. It is only a Servlet container. Therefore any features you use from that javaee-web-api, you need to also include an implementation.
So for now, just get rid of it so you don't use ant classes for which there is no implementation. Then you need to decide on a JAX-RS implementation to use. For now I'll just say to use Jersey. So just add this dependency
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>
Then you need to configure the application in the web.xml. You can see here for more options. You basically want something like
<web-app>
<servlet>
<servlet-name>MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.foo.myresources</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
The param-value in the init-param is the package you want Jersey to scan to pick up and register all your classes annotated with #Path and #Provider. The scan is recursive, so you can list the root-most package in your project if you have your resource scattered in different packages.
From here it should work. Then for JSON/POJO support, you can just add the following dependency
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
No extra configuration is needed for that.

Categories

Resources