jersey

Supporting both Multipart and Application Url Encoded parameters in Jersey

独自空忆成欢 提交于 2019-12-10 14:44:07
问题 I have a rest service in Jersey. I would like to have some post method that accepts parameters both as multipart and as url encoded. I started with : @POST @Path("/some/resource") public String addSomeResource(@FormParam("param") String param) { repository.add(new SomeResource(param)); } My understanding is that using @Consumes more narrowly defines what's acceptable, and sure enough, this method is called whether someone attaches form data the usual way $.ajax({url:'/some/resource', type:

GlassFish 4 + JAX-RS Filter with @EJB

僤鯓⒐⒋嵵緔 提交于 2019-12-10 14:44:01
问题 I'm developing an REST application using Glassfish 4.0. In resource classes I can get injection to work by making the class @Stateless and injecting via @EJB (injected class is an stateless EJB). However this approach does not work in an JAX-RS filter. I cannot get injection to work at all. See code below: @Provider public class UpdateFilter implements ContainerRequestFilter { @EJB private MyBeanInterface doStuffBean; @Override public void filter(ContainerRequestContext requestContext) { ...

Moxy, JSON and Jersey 2.0 does not deserialize plain String array

旧时模样 提交于 2019-12-10 14:43:49
问题 In my current setup I use Jersey 2.0 with MOXy as discribed in jersey docs. I rely completely on the “Auto-Discoverable Features”, so I do not use any extra configuration or JAXB annotation. My task is to deserialize an array of strings on the server side. The client is sending the JSON message: ["foo","bar"] And on the server side the following method header should deserialize it: @POST @Path("/stringArray") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public

Unresolved dependencies error when following Jersey 2.0 user guide

守給你的承諾、 提交于 2019-12-10 13:47:33
问题 Update: This does not/should not occur anymore, see accepted answer. If you are facing this problem with some other jar, it is typically a transient thing. You can try some of the workaround suggested in other answers. I am following the instructions from Jersey 2.0 user guide. When I reach 1.3 (running the project, I get the following failure: [ERROR] Failed to execute goal on project xxx-service: Could not resolve dependencies for project xxx.restapi:xxx-service:jar:1.0-SNAPSHOT: Failure to

Using Jersey 2.1 with CDI

痴心易碎 提交于 2019-12-10 13:30:33
问题 I try to use Jersey 2.1 and CDI in my Java EE 7 project which is deployed on Glassfish 4.0. Jersey modules depend on Guava libraries. But using Guava libraries (14.0.1) with CDI results the following exception being thrown. CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Set<Service>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.google.common.util.concurrent.ServiceManager(Set<Service>)]

RestAssured - passing list as QueryParam

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 13:21:45
问题 I have a REST-service that takes in a number of query-params, amongst other things a list of strings. I use RestAssured to test this REST-service, but I am experiencing some problems with passing the list to the service. My REST-service: @GET @Consumes(Mediatyper.JSON_UTF8) @Produces(Mediatyper.JSON_UTF8) public AggregerteDataDTO doSearch(@QueryParam("param1") final String param1, @QueryParam("param2") final String param2, @QueryParam("list") final List<String> list) { My RestAssured test:

Where to throw customized 404 error in jersey when HttpServer can't find a resource

不羁的心 提交于 2019-12-10 13:04:22
问题 I want to customize 404 response, that the server (not me) throws whenever it can't find a requested resource, (or throw a customized WebApplicationException myself, if it's possible to test if a requested resource is present in one app? probably a List of resources is stored somewhere?). please don't refer me to solutions that suggest to extend WebApplicationException, because even doing so, my problem is when to throw it?, when resource is not found! but how to express this need in jersey

Custom ExceptionMapper for Jersey not working for invalid JSON input

非 Y 不嫁゛ 提交于 2019-12-10 12:59:17
问题 I have the following resource that consumes a JSON being mapped to a POJO. @Path("example") public class ExampleResource { @POST @Consumes(MediaType.APPLICATION_JSON) public Response addThesis(MyObject myObject) { return Response.ok().entity("Test").build(); } } Here's the POJO class: public class MyObject { private String title; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } When I send a POST request with the body {"title":"Test title

Using Jackson ObjectMapper with Generics to POJO instead of LinkedHashMap

a 夏天 提交于 2019-12-10 12:57:09
问题 Using Jersey I'm defining a service like: @Path("/studentIds") public void writeList(JsonArray<Long> studentIds){ //iterate over studentIds and save them } Where JsonArray is: public class JsonArray<T> extends ArrayList<T> { public JsonArray(String v) throws IOException { ObjectMapper objectMapper = new ObjectMapper(new MappingJsonFactory()); TypeReference<ArrayList<T>> typeRef = new TypeReference<ArrayList<T>>() {}; ArrayList<T> list = objectMapper.readValue(v, typeRef); for (T x : list) {

How to retrieve matched resources of a request in a ContainerRequestFilter

巧了我就是萌 提交于 2019-12-10 12:34:03
问题 I am working on a WebService using JAX-RS/Jersey. I've set up a ContainerRequestFilter whose purpose is to authenticate the user. I only need to protect some of the paths with authentication, the rest can be available to everyone. I want to retrieve matchedResources / matchedResults via ExtendedUriInfo in my ContainerRequestFilter so that I can check if the path should be protected or not. Is there a way to create a filter which is invoked after ExtendedUriInfo is populated, but before the