jersey

Spring boot Jersey Jackson

血红的双手。 提交于 2019-12-17 14:54:05
问题 I have a question related to the Jackson configuration on my Spring boot project As described on spring boot blog I try to customize my Object serialization. After added a new config bean in my config @Bean public Jackson2ObjectMapperBuilder jacksonBuilder() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.propertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); return builder; } When I try to output an instance of my class

NoSuchMethodError: MultivaluedMap.addAll in Jersey Client

此生再无相见时 提交于 2019-12-17 12:14:32
问题 I'm trying to use Jersey Client to simulate HTTP requests to my web service. I tried to implement the simple example from the documentation. Here's my short code: public void restoreTest(String sessionId) throws Exception { Client client = ClientBuilder.newClient(); WebTarget target = client.target(idsUrl).path("restore"); Form form = new Form(); form.param("sessionId", sessionId); target.request(MediaType.APPLICATION_FORM_URLENCODED_TYPE); } I didn't even implement the whole example, because

When to use @Singleton annotation of Jersey?

心已入冬 提交于 2019-12-17 10:59:13
问题 I am developing a RESTful Web Service and while reading the Jersey documentation I came across an annotation @Singleton In my web service I am mostly returning data based on the unique keys provided as parameter. An analogy would be return all the information of a Student when the Student_Id is passed. So my question is when @Singleton would be suited in such kind of Web Services? As per documentation for @RequestScoped If the resource is used more than one time in the request processing,

When to use @Singleton annotation of Jersey?

允我心安 提交于 2019-12-17 10:59:06
问题 I am developing a RESTful Web Service and while reading the Jersey documentation I came across an annotation @Singleton In my web service I am mostly returning data based on the unique keys provided as parameter. An analogy would be return all the information of a Student when the Student_Id is passed. So my question is when @Singleton would be suited in such kind of Web Services? As per documentation for @RequestScoped If the resource is used more than one time in the request processing,

Jersey RESTful web service gradle setup

南笙酒味 提交于 2019-12-17 10:53:50
问题 I am stuck with creating a gradle project for a RESTful web service using the jersey library. The project configuration should be capable of launching the service inside a jetty application server. I already found a resource: https://github.com/ziroby/jetty-gradle-hello-world My problem with that solution is, that it uses an outdated version of jersey. I need at least version 2(preferred latest 2.14). I tried to search for new versions on maven central, but in version 2 a lot of artifact

Configure Jersey/Jackson to NOT use @XmlElement field annotation for JSON field naming

点点圈 提交于 2019-12-17 10:44:41
问题 I am running a Jersey REST service. The POJO's which represent my resources are JAXB (XML) annotated simple Java classes (they are generated from a schema definition - so they have the annotations). I want Jersey/Jackson to ignore the XML-Annotations. I did this configuration in my web.xml (as mentioned here): <init-param> <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> <param-value>true</param-value> </init-param> I now expected that the @XMLElement annotation would not

Using @Context, @Provider and ContextResolver in JAX-RS

我的未来我决定 提交于 2019-12-17 10:27:13
问题 I'm just getting acquainted with implementing REST web services in Java using JAX-RS and I ran into the following problem. One of my resource classes requires access to a storage backend, which is abstracted away behind a StorageEngine interface. I would like to inject the current StorageEngine instance into the resource class serving the REST requests and I thought a nice way of doing this would be by using the @Context annotation and an appropriate ContextResolver class. This is what I have

Jersey Client API - authentication

六眼飞鱼酱① 提交于 2019-12-17 10:22:37
问题 I'm using the Jersey client API to submit SOAP requests to a JAX-WS webservice. By default Jersey is somehow using my Windows Nt credentials for authentication when challenged. Can anyone explain where Jersey does this in the code? And can it be overriden? I have tried using HTTPBasicAuthFilter and adding as a filter on the Client. I have also tried adding my credentials to the WebResoruce queryParams field however neither are being picked up. 回答1: At first I got this working as documented in

Catch all Exceptions and also return custom Errors in Jersey

喜你入骨 提交于 2019-12-17 09:41:19
问题 I want to catch all unexpected Exceptions in a jersey rest service. Therefore i wrote an ExceptionMapper: @Provider public class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<Exception> { private static Logger logger = LogManager.getLogManager().getLogger(ExceptionMapper.class.getName()); @Override public Response toResponse(Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Internal error").type("text

JAX-RS using exception mappers

三世轮回 提交于 2019-12-17 09:25:09
问题 I have read that I can create an implementation of javax.ws.rs.ext.ExceptionMapper that will map a thrown application exception to a Response object. I've created a simple example which throws an exception if the phone length is greater than 20 characters when persisting the object. I am expecting the exception to be mapped to an HTTP 400 (Bad Request) response; however, I am receiving an HTTP 500 (Internal Server Error) with the following exception: java.lang.ClassCastException: com.example