jersey

Pass List to RESTful webservice

梦想的初衷 提交于 2019-12-05 10:38:23
Is there a way to pass a list to RESTFul web service method in Jersey? Something like @PathParam("list") List list? Jana I found out that the best way to send a list via POST from the client to a REST service is by using the @FormParam . If you add a parameter twice or more times to the form, it will result into a list on the server's side. Using the @FormParam means on client side you generate a com.sun.jersey.api.representation.Form and add some form parameters like shown below. Then you add the filled form to the post like that: service.path(..) ... .post(X.class, form) (see example code).

How to mock MyBatis mapper interface?

时光怂恿深爱的人放手 提交于 2019-12-05 09:55:32
I am writing unit test for my Jersey rest API which uses MyBatis at the background. This is the structure of my classes: rest service: @Path("/api") public class HelloRestService { @Inject HelloBean helloBean; @GET @Path("/echo/{name}") public Response echo(@PathParam("name") String name) { return Response.status(200).entity(helloBean.sayHello(name)).build(); } } Stateless EJB: @Stateless public class HelloStatelessBean implements HelloBean { // Injected MyBatis mapper (dao) @Inject private EmployeeMapper employeeMapper; @Override public Employee getEmployeeById(final Long id) { return

URI-specific ExceptionMapper in JAX-RS

偶尔善良 提交于 2019-12-05 09:37:24
I'm using Jersey, and Guice as my IOC-container. I'd like to know if it is possible to associate an ExceptionMapper with a specific URI. The reason for this is that I want to map the same exception differently based on what URI was visited. For example, suppose I've got the following two exception mappers for my custom exception: public class MyExceptionMapperForFirstURI implements ExceptionMapper<MyException> {..return response based on first URI..} public class MyExceptionMapperForSecondURI implements ExceptionMapper<MyException> {..return response based on second URI..} As far as I

WARNING: The (sub)resource method contains empty path annotation

二次信任 提交于 2019-12-05 09:19:00
问题 I have configured rest path like "/v1/" and the endpoint configured in servlet like '/test/'. Now I removed the "/v1" from the java class "Test". org.glassfish.jersey.internal.Errors logErrors WARNING: The following warnings have been detected: WARNING: The (sub)resource method test in com.abc.services.Test contains empty path annotation. I got the above warning after make this change. How to handle this warning? And I want this "/v1" removing changes for across 10 rest paths. So anyone help

This dependency gives me two versions of one jar. How do I fix this?

空扰寡人 提交于 2019-12-05 08:46:59
I'm using Gradle for my project. One of the dependencies I have specified in my build.gradle is compile 'org.glassfish.jersey.media:jersey-media-moxy:2.0' This works fine on a normal Java application, however when I try to build it on Android I get: When looking at which libraries are referenced, it's clear that there's both javax.inject-2.3.0-b05.jar and javax.inject-1.jar , which I found are added by the dependency above. I'm guessing that this 'duplicate' jar is what causes the build error. How do I go around this? Why does the dependency include two of the same jar? Is there a way to

Jersey RESTful Services: Resources & Responses

心不动则不痛 提交于 2019-12-05 08:41:56
I see a lot of Jersey-based web services consisting of 1+ WebResources that have 1+ endpoints/methods like so: package com.myws.fizz; public class FizzResource { @GET @Path("/fizz/{id}") public Response getFizzById(@PathParam("id") Long id) { // ...etc. } @GET @Path("/fizz") public Fizz getFizzByFoo(Foo foo) { // ...etc. } } package com.myws.buzz; public class BuzzResource { @POST @Path("/buzz") public Response createBuzz(Buzz buzz) { // ...etc. } } I'm confused with what Jersey considers a "resource". Is there a relationship between a "resource" and a database? A table? A POJO? When do you

JAX-RS Jersey JSON preserve null using annotations

喜夏-厌秋 提交于 2019-12-05 08:39:00
How do I have JAXB preserve nulls when receiving a JSON sting that contains a null or "" value. String: {"id":null,"fname":"John","region":""} returns Object: Person { Integer id = 0 String fname = "John" Region regions = 0 } I would like it to return null instead of 0 Here is what I have so far: @Provider public class JAXBContextResolver implements ContextResolver<JAXBContext> { private JAXBContext context; private Class<?>[] types = {Person.class}; public JAXBContextResolver() throws Exception { this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), types); } public

jersey.api.client.WebResource - how to debug/log the request headers

江枫思渺然 提交于 2019-12-05 08:27:15
I am using jersey to generate http requests and I would like to be able to see the request before it is sent (for debugging purposes). For example: WebResource resource = client.resource(url); resource.header("aa", "bb"); resource.getHeaders(); // Error: how can I do it? thanks ivan.cikic You can use LoggingFilter , as shown here You need to add init-params and then implement ContainerRequestFilter Put it in your web.xml Please note that com.az.jersey.server.AuthFilter is your class that has implemented mentioned above interface. <init-param> <param-name>com.sun.jersey.spi.container

how to get path param from ContainerRequestContext

二次信任 提交于 2019-12-05 07:58:13
I want to apply authorization filter for my REST API endpoint, and the filter need path parameter to do the filtering. here is my endpoint and code: endpoint: curl --url 'localhost:80/reports/resources/org/12345/product/111 ' --request GET --header 'Authorization: <token here>' resource code: @Path("/resources") public class MyResource extends AbstractResource { ... @GET @Path("/org/{orgId}/product/{productId}") @Produces(MediaType.APPLICATION_JSON) @RoleAuthenticated public Response getResourcesReport(@PathParam("orgId") String orgId, @PathParam("productId") String productId, @Context

Jersey 2.*. Custom InjectionResolver and “A HTTP GET method … should not consume any entity”

徘徊边缘 提交于 2019-12-05 07:15:57
I have followed Michal's guide from his answer to this question [ 1 ] on implementing custom annotation for injecting arbitrary things into resource methods. This (gist) [ 2 ] contains a minimalistic testbed adapted from the jersey-quickstart-grizzly2 archetype. I will refer to it in the following text. I encountered a few problems: My resolver is parametrized type (or at least it would make things much more cleaner, in my opinion) and thus I can not bind it in my binder the way Michal suggests. // Instead of the suggested: // bind(MyInjectionResolver.class).to(new TypeLiteral