jersey-2.0

How to inject an object into jersey request context?

老子叫甜甜 提交于 2019-12-27 11:05:48
问题 I have this scenario where I want to write a filter and I want this filter to insert some object into the current request and pass it on so that when the resource class gets the request it can use the object. Filter class @Override public void filter(ContainerRequestContext request) throws IOException { MyObject obj = new MyObject(); // Inject MyObject to request which I dont know how } Resource Class @PUT @Consumes("application/json") @Path("/") public String create( JSONParam sample,

glass fish java can i send object through get request?

久未见 提交于 2019-12-25 18:42:36
问题 I have a class like this: class Customer { private int id; private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } } and I have a glass fish web service: i want to know it is possible to send a customer object using get (i know i can do this in post, but in get ... i don't know) this is what i tried: @GET @Path("/test") @Produces(MediaType.TEXT_PLAIN)

Inject EJB into JAX-RS 2.0 subresource when subresource is got via ResourceContext

断了今生、忘了曾经 提交于 2019-12-25 12:52:48
问题 I am using Jersey 2.8 with Glassfish 4.0. I have a resource locator class which looks like below @Path("/") @ManagedBean public class MyServiceLocator { @Context ResourceContext rc;//javax.ws.rs.container.ResourceContext @EJB private MyEJBHome myEJB; @Inject//javax.inject.Inject MySubService mss; @Path("/mysubservice") public MySubService getMySubService() { return rc.getResource(MySubService.class); //also tried return rc.initResource(new MySubService()); } } and a sub resource class which

Inject EJB into JAX-RS 2.0 subresource when subresource is got via ResourceContext

跟風遠走 提交于 2019-12-25 12:51:27
问题 I am using Jersey 2.8 with Glassfish 4.0. I have a resource locator class which looks like below @Path("/") @ManagedBean public class MyServiceLocator { @Context ResourceContext rc;//javax.ws.rs.container.ResourceContext @EJB private MyEJBHome myEJB; @Inject//javax.inject.Inject MySubService mss; @Path("/mysubservice") public MySubService getMySubService() { return rc.getResource(MySubService.class); //also tried return rc.initResource(new MySubService()); } } and a sub resource class which

How to document implicitly dto usage, when we use entity class as api param?

穿精又带淫゛_ 提交于 2019-12-25 08:49:24
问题 There are a problem, when we use Jersey2 resource with implicitly dto usage. Example: @POST @ApiOperation(value = "Create pet", response = PetDTO.class) public Pet create(Pet pet) throws IOException { return this.petService.save(pet); } In this example we implicitly get petDto as param, and than map it to entity. The question is, is the way to how to configure swagger to document PetDTO as api param, not Pet? 回答1: It can be done next way: @POST @ApiOperation(value = "Create pet", response =

null in FormParam with “charset=UTF-8” in Jersey 2.0

别来无恙 提交于 2019-12-25 07:08:01
问题 I'm currently working on an AngularJS project and I'm calling some rest services using content-type "application/x-www-form-urlencoded;". On server side I use Jersey in version 2.0. This is my maven dependency. <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet-core</artifactId> <version>2.0</version> </dependency> Everthing work fine on Chrome and IE7. My problem is Firefox who add mystically "charset=UTF-8" in the content type. I made some

Removing meta data from the file

跟風遠走 提交于 2019-12-25 04:22:13
问题 The following is my method signature. @POST @Path("/upload/{user_id}/{user_type}") @Produces("application/json") public Response fileUploader(InputStream a_fileInputStream, @PathParam("user_id") String user_id, @PathParam("user_type") String logType, @Context ContainerRequestContext crc) { //WRITE INPUTSTREAM TO FILE } I am able to write content to my file successfully, but there is some meta data which is written to my file at start of my file the following meta data is written: -----

ResourceInfo not injected into spring managed jersey filter

 ̄綄美尐妖づ 提交于 2019-12-24 19:24:58
问题 I am having problems injecting the ResourceInfo into my jersey filter. The annotation @Context doesn't seem to work properly when having a spring managed filter instance. What I found is this: Jersey Request Filter only on certain URI The second goal is quite similar to my situation. DynamicFeature: @Provider public class HttpCacheConfigDynamicFeature implements DynamicFeature { private final DefaultHttpCacheFilter defaultHttpCacheFilter; private final HttpCacheFilter httpCacheFilter;

Spring Boot 1.2.5 & Jersey 2 ignore null fields

大城市里の小女人 提交于 2019-12-24 18:31:30
问题 In Spring boot 1.2.5 with a Jersey 2 interface, how can I set the JSON marshaller to not include fields that have null values? For example: [ { "created": 1433987509174, "lastModified": 1433876475580, "id": 1, "example": "example1b" }, { "created": 1434502031212, "lastModified": 1434502031212, "id": 10000, "example": "example1c" }, { "created": 1439151444176, "lastModified": 1439151444176, "id": 10011, "example": null } ] The field "example": null should not be included in the json output at

Jersey Jackson JSON attribute change globally

六眼飞鱼酱① 提交于 2019-12-24 16:04:02
问题 I have a scenario that if there is an XML attribute (defined as @XmlAttribute ) in the POJO then it should named differently in the JSON output. @XmlAttribute(name = "value") //@JsonProperty("value-new") protected String value; Now I can use @JsonProperty to define the new name. But I have plenty of such attributes in each POJO and the name change required is "common" for all of them (say add -new) at the end. Is it possible to do this globally ? 回答1: You can implement your own