jersey

How should I mock Jersey HTTP-client requests?

This is the class I'm trying to test (it calculates the size of HTTP page): import javax.ws.rs.core.MediaType; import com.sun.jersey.api.client.*; public class Loader { private Client client; public Loader(Client c) { this.client = c; } public Integer getLength(URI uri) throws Exception { return c.resource(uri) // return...

Can I wrap all JAX-RS requests with custom pre-dispatch, post-dispatch and error-handler code?

I have a number of classes exposed as JAX-RS request "handlers", using javax.ws.rs.Path annotations. I want to add certain actions before every request and after each request. Also, I need to create a global application-wide exception handler, which will catch everything thrown by these handlers and protocol. Is it possible to achieve t...

What is the problem with Glassfish Embedded container?

This is my pom.xml (part of it): [...] <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>${jersey.version}</version> </dependency> <dependency> <groupId>com.sun.jersey.jersey-test-framework</groupId> <artifactId>jersey-test-framework-embedded-glassfish</artifactId> <version>${jers...

is jersey a better choice for ExtJS than Spring MVC?

What are the advantages/disadvantages of using Jersey with ExtJS than to use Spring MVC? Any of you using this combination of frameworks? Please share some insights. Thanks. ...

REST API with web application(JSP,Servlets)

I have one normal servlet and one jersey specific REST related servlet i.e.ServletContainer configured in web.xml. Case 1 - Url pattern for normal servlet is "/login" Url pattern for other REST servlet is "/" In this case all request will got REST servlet. Request for login also goes to tht Servlet only. Case 2 - If Url pattern for RES...

JAXB JSON force brackets on arrays

Hello, I'm trying to force brackets on lists that contain only one element. I want something like this: {"id":"0","industries":[{"id":"0","name":"Technologies"}],"name":"Google Inc."} But I get: {"id":"0","industries":{"id":"0","name":"Technologies"},"name":"Google Inc."} Here is my Entity: @Entity @XmlRootElement public class Compan...

Correct implementation of 300 http respond code in Jersey restful web service for a geo location service

I have a resource .../releases/343/file/21 Depending from where the user access the resource I need to implement a geo balancing mechanism, so I redirect him to a static web server or another. I have something like this : URI uri; if( is_near(user, us) ) uri = URI.create("http://us.static.myserver.com/myfile.tar.gz"); ...

Java library to map request parameters onto an object

I have used stipes on a project in the past, and it has a great TypeConverter library that can take request parameters and route them into JavaBeans. It can even handle maps and arrays, such that: class A { private int num; private Map<String, Integer> map; private List<String> list; ... setters and getters ... } <input type='text...

Filtering static content Jersey

Hi, I'm trying to serve static content (a HTML form that calls a Jersey REST resource) from the same webapp as the servlet that handles the requests to the resource. As I understand I can filter requests to static content away from the Jersey servlet. My web.xml is as follows, but at the moment I am unable to access the static content n...

How do I get JSON data from my RESTful service using JEE 5?

I have a simple RESTful web service written in JEE 5. It works fine but I've decided to output JSON from the GET method. As an initial step I've only add one line of code: ObjectMapper mapper = new ObjectMapper(); That one line results in this error: 48d5-9878-2ef7c0a948c4;|StandardWrapperValve[Jersey Web Application]: PWC1406: Servl...

Jersey web services multiple formats

In following method: @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN}) @Path("{id}") public String getMessage(@PathParam("username") String username, @PathParam("id") int id, @QueryParam("format") String format) { return "test"; } how do I return the the data in the specific fo...

jersey rest web services multiple format

how to return the correct representation based on URI example /text.json should return json /text.xml should return xml /text should return plain text All these are mapped to the same method @GET public Contact getContacts() { } ...

Securing Jersey RESTful services with spring-security-core using jaxrs plugin

I'm needing to implement some RESTful webservices for a client in a Grails app and I want to use the jaxrs plugin but I am having a heck of a time finding information on how to implement security that isn't realm based (tomcat-users.xml). I am using the spring-security-core plugin and I'd like to utilize it to authenticate against my we...

Can I get normal pojo as json object in RESTful-jersey

I am implementing jersey restful web service to get application/json mime type from the java bean classes. Given below is the resource class code @GET @Produces({"application/json"}) public synchronized Flights getFlightList() { return myFlights; } Here if the return object (Flight) converts to json object only when ...

http delete with REST

I am currently using Jersey Framework (JAX-RS implementation) for building RESTful Web Services. The Resource classes in the project have implemented the standard HTTP operations - GET,POST & DELETE. I am trying to figure out how to send request parameters from client to these methods. For GET it would be in the query string(extract usi...

how to increase jersey WS timeout

How do I increase the jersey WS timeout? It is waiting on a call which takes around 2 minutes. It is timing out at WS layer. Do I have to increase client timeout as well? What are the defaults for these? ...

Jersey Problem with Parsing a JSONArray

Hi, I'm trying to implement a Resource with the jersey framework. But if I call my resource, I will get a parsing exception, that the parser can't parse JSONArray datatype. Here's my resource structure: @Path("/books") @Consumes("application/json") public class BookResource { @GET @Produces("application/json") public JSONArray getAll...

What Jersey doesn't like in my Stateless Session Bean?

This is my SLSB: @Stateless(name = "FinderEJB") @Path("/") public class Finder implements FinderLocal { @Path("/simple") @GET public String simple() { return "works"; } } The interface is: @Local public interface FinderLocal { public String simple(); } This is what I'm getting in Glassfish server log when I'm trying t...