jersey

Rest | @Produces and @Consumes : why dont they both get called for same MIME-type

依然范特西╮ 提交于 2021-02-20 04:30:07
问题 a newbie in JAX-REST (jersey 1.8 impl) I have a class for Resource "/hello" package com.lbs.rest; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Path("/hello") public class Test { //-- produces MIME type text/plain @GET @Produces(MediaType.TEXT_PLAIN) public String thankYouTxt(){ System.out.println("thankYouTxt"); return "thankYouTxt\n"; } //-- consumes MIME type text/plain @GET @Consumes(MediaType

ExceptionMapper not working consistently in Jersey 2.x & javax

China☆狼群 提交于 2021-02-20 03:49:51
问题 I am using javax and jersey for my api application (exposing api endpoints) I am trying to catch exceptions coming from fasterXml (on put and post calls) by having a Provider which implements ExceptionMapper. My Problem is that on POST or PUT, whenever I am sending wrong attributes names, sometime my mapper catch the exceptions and sometime it doesn't. For example: Running my application once -> everything is working as expected, catching exceptions. Running my application again (restart) ->

ExceptionMapper not working consistently in Jersey 2.x & javax

妖精的绣舞 提交于 2021-02-20 03:49:38
问题 I am using javax and jersey for my api application (exposing api endpoints) I am trying to catch exceptions coming from fasterXml (on put and post calls) by having a Provider which implements ExceptionMapper. My Problem is that on POST or PUT, whenever I am sending wrong attributes names, sometime my mapper catch the exceptions and sometime it doesn't. For example: Running my application once -> everything is working as expected, catching exceptions. Running my application again (restart) ->

Configuring Jersey Test Framework with Security

醉酒当歌 提交于 2021-02-20 02:52:17
问题 I am writing a REST web service using Jersey, and I'm trying to write a set of unit tests to test the service using the Jersey Test Framework. However, I use HTTP Authentication and SecurityContext as part of my web service, and I'm having issues setting up JTF to allow me to test these aspects. I can send authentication information in the request, but how do I configure it to know about the different roles and users I wish to set up? I'm currently using Jetty (via JettyTestContainerFactory),

How can JAXB XmlAdapter be used to marshall lists?

落花浮王杯 提交于 2021-02-19 06:48:05
问题 Instances of this class are part of a large object graph and are not at the root of the object graph: public class Day { public Day(LocalDate date, List<LocalTime> times) { this.date = date; this.times = times; } public Day() { this(null, null); } public LocalDate getDate() { return date; } public List<LocalTime> getTimes() { return times; } private final LocalDate date; private final List<LocalTime> times; } The object graph is converted to JSON using Jersey and JAXB. I have XmlAdapter s

Jersey rest client not adding query parameters

我们两清 提交于 2021-02-18 20:13:01
问题 I'm trying to make a simple jersey rest client for google search api. Client client = ClientBuilder.newClient(); WebTarget target = client.target("https://www.googleapis.com/customsearch/v1"); target.queryParam("q", "mobile"); Response response = target.request().get(); System.out.println(response.readEntity(String.class)); As you've noticed I haven't included key and cx . Don't worry about that, it's just a simple demo. When visiting the url https://www.googleapis.com/customsearch/v1?q

Jersey rest client not adding query parameters

纵饮孤独 提交于 2021-02-18 20:10:55
问题 I'm trying to make a simple jersey rest client for google search api. Client client = ClientBuilder.newClient(); WebTarget target = client.target("https://www.googleapis.com/customsearch/v1"); target.queryParam("q", "mobile"); Response response = target.request().get(); System.out.println(response.readEntity(String.class)); As you've noticed I haven't included key and cx . Don't worry about that, it's just a simple demo. When visiting the url https://www.googleapis.com/customsearch/v1?q

Jersey rest client not adding query parameters

心不动则不痛 提交于 2021-02-18 20:08:26
问题 I'm trying to make a simple jersey rest client for google search api. Client client = ClientBuilder.newClient(); WebTarget target = client.target("https://www.googleapis.com/customsearch/v1"); target.queryParam("q", "mobile"); Response response = target.request().get(); System.out.println(response.readEntity(String.class)); As you've noticed I haven't included key and cx . Don't worry about that, it's just a simple demo. When visiting the url https://www.googleapis.com/customsearch/v1?q

File upload endpoint need to close InputStream?

喜夏-厌秋 提交于 2021-02-18 18:20:25
问题 @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/upload") public String upload(@FormDataParam("file") InputStream inputStream) { ... inputStream.close(); // necessary? } For an API endpoint that accepts a file input, do we need to manually close the InputStream or does the framework do it for us? I have checked the Jersey docs but could not find any information about it. Looking for credible source or some way to validate it. 回答1: It is your responsibility to close InputStream. Jersey

File upload endpoint need to close InputStream?

懵懂的女人 提交于 2021-02-18 18:20:07
问题 @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/upload") public String upload(@FormDataParam("file") InputStream inputStream) { ... inputStream.close(); // necessary? } For an API endpoint that accepts a file input, do we need to manually close the InputStream or does the framework do it for us? I have checked the Jersey docs but could not find any information about it. Looking for credible source or some way to validate it. 回答1: It is your responsibility to close InputStream. Jersey