Jersey - Multipart data form with text body parts - java

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!

Related

Jersey 2.x JSP pages redirection

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

MessageBodyWriter not found for media type=application/octet-stream, type=class org.glassfish.jersey.media.multipart.MultiPart

I am getting MessageBodyProviderNotFoundExceptionafter upgrading the Jersey distribution. I've registered the MultiPart in the web.xml but it seems like I am missing more to configure.
pom
<!-- Jersey -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version.no}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version.no}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey.version.no}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version.no}</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version.no}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${jersey.version.no}</version>
</dependency>
web.xml
<servlet>
<servlet-name>Jersey Spring</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.mercuryinsurance.esignature.client.rest.service</param-value>
</init-param>
<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.servlet.filter.contextPath</param-name>
<param-value>/WEB-INF/jsps/rest</param-value>
</init-param>
<init-param>
<param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
<param-value>/(resources|(WEB-INF/jsp))/.*</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Code:
WebTarget webTarget = client.createResource( ESignatureSpringUtil.getMessage( KeyConstants.ALSB_DOCUSIGN_ADDRESS )
+ ESignatureSpringUtil.getMessage( KeyConstants.REST_SEND_DOCUMENTS_ADDRESS ) );
Invocation.Builder builder = webTarget
.path( ESignatureSpringUtil.getMessage( KeyConstants.REST_SEND_DOCUMENTS_ADDRESS ) )
.request( MediaType.APPLICATION_XML )
.header( KeyConstants.REST_URI_APPENDERS, docSb )
.header( DocusignRESTContants.CONTENT_TYPE, DocusignRESTContants.MULTIPART_FORM_DATA )
.header( DocusignRESTContants.X_DOCUSIGN_AUTHENTICATION, getDocusignAuthHeader( cu ) );
Response response = builder.post( Entity.entity( multiPart, MediaType.APPLICATION_OCTET_STREAM ), Response.class );
stacktrace
Caused by: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/octet-stream, type=class org.glassfish.jersey.media.multipart.MultiPart, genericType=class org.glassfish.jersey.media.multipart.MultiPart.
I finally got it to work. I am sending the form as MultiPart object t be able to send multiple forms. I had to send it as a byte stream not just as a plain java object. multipart.toString().getBytes() in the entity method. I am getting 200 status code back from the vendor.

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.

How can I send a JSON object with Jersey in a Rest Service

I'm trying to make a restful service with jersey, for that I'm using the jersey example for a maven project. So this is what I got:
my 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>com.example</groupId>
<artifactId>simple-service-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-service-webapp</name>
<build>
<finalName>simple-service-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<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>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<!-- uncomment this to get JSON support <dependency> <groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId> </dependency> -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.19</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.example</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
the resource
package com.example;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Root resource (exposed at "myresource" path)
*/
#Path("/myresource")
public class MyResource {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* #return String that will be returned as a text/plain response.
*/
#GET
#Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}
#Path( "complexObject/{name}" )
#GET
#Produces( { MediaType.APPLICATION_JSON } )
public ComplexObject complexObject( #PathParam( "name" ) String name ) {
return new ComplexObject(name);
}
}
The ComplexObject class is just a class with a string.
when I hit the url: http://localhost:8080/simple-service-webapp/webapi/myresource/
This work, I get "Got it!"
but when I hit on: http://localhost:8080/simple-service-webapp/webapi/myresource/complexObject/capo
I get this error on the console:
SEVERE: MessageBodyWriter not found for media type=application/json,
type=class com.example.ComplexObject, genericType=class
com.example.ComplexObject.
How can I fix this?
With this dependency
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.0</version>
</dependency>
You will still need to register the provider. You could register it individually
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
</param-value>
</init-param>
Or since the dependency also comes with Jackson ExceptionMappers, you might want to just have the whole package scanned (just add it to the list of packages)
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.example,
com.fasterxml.jackson.jaxrs.json
</param-value>
</init-param>
Another option, besides using the above dependency, is to use Jersey's "wrapper" dependency (which handle the registration of the of the providers, among a couple other things such as Jackson Entity Filtering. Just used
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
With this dependency, do registration is required. It is automatically registered through Jersey's auto-discoverable feature

Resource not found in Jersey (Error 404)

I am making an AJAX call to a Jersey resource through JavaScript where class is mapped to /books and a GET method to /allBooks. This is the code for AJAX call:
function libBooks(){
alert("Inside js");
//The above alert is displayed
var requestData = {
"dataType": "application/json",
"type": "GET",
"url": "http://localhost:8080/library/rest/books/allBooks/"
};
var request = $.ajax(requestData);
alert("Ajax call made");
//The above alert is displayed
request.success(function(data) {
alert("Inside done function");
//The above alert is not displayed
var dataReceived =data.listOfBooks;
var numOfItems = dataReceived.length;
alert(numOfItems);
});
request.fail(function(jqXHR, status, errorMessage) {
if((errorMessage = $.trim(errorMessage)) === "") {
alert("An unspecified error occurred. Check the server error log for details.");
}
else {
alert("An error occurred: " + errorMessage);
}
});
}
In JSP I have a link like this:
<p>List of books in library Click Here</p>
And here is my BookResource:
#Path("/books")
public class BookResource {
#GET
#Path("/allBooks")
#Produces(MediaType.APPLICATION_JSON)
public Response getAllBooks() {
BooksHelper bookHelper = new BooksHelper();
ArrayList<Book> listOfBooks = bookHelper.getListOfBooks();
ResponseBuilder responseBuilder = Response.status(Status.OK);
responseBuilder.entity(listOfBooks);
Response response = responseBuilder.build();
return response;
}
}
Here is my 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>org.sudhanshu</groupId>
<artifactId>library</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>library</name>
<build>
<finalName>library</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<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>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.16</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
I am not sure how mapping in pom.xml works as I am using Maven for the first time. Here is my web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>Jersey Web Application</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.sudhanshu.library</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
When I get to the URL: http://localhost:8080/library/rest/books/allBooks , it says resource not found 404. I think the problem might be in web.xml REST request entry point and my mapping in Resource. Also, please suggest if URL in my ajax request is correct or not. I have tried various things but none of them are working. For now I just want an alert that shows that ajax call was successful.Here is my directory structure: Any help will be appreciated. Thank You.
Look at here
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.sudhanshu.library</param-value>
</init-param>
You're specifying the package(s) to scan is org.sudhanshu.library. Looking at the image of your project structure, that package is empty. The package you should be scanning is com.resources
Second thing (unrelated to the 404, but will be the next problem) is you need a JSON provider. You can see in the generated pom.xml file they give you a hint
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
-->
You need to un-comment that dependency. Also I would change the dependency from jersey-media-moxy to jersey-media-json-jackson. IMO Jackson works a lot better than MOXy in many aspects.
This helped me find out what was my problem: I was having the same issue (resource not found) and I tried to establish my <param-value> tag with only the name of the package where my resource is (not nameOfMyApp.myResource).
I think it could be helpful to know it as few colleagues where having also the same mistake as I was.

Categories

Resources