jersey

How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilter

有些话、适合烂在心里 提交于 2019-12-12 19:17:15
问题 I have a highly concurrent server and need to implement some special logging. I need an easy way to match the request to the response. The filter() in ContainerResponseFilter has both the request and response . How ever I can not access the http post content because the stream has already been read. Is there some way I can add an ID in the ContainerRequestFilter filter() and somehow have it automatically returned when the ContainerResponseFilter filter() is called? I can not modify the true

JAXB can not handle XML element containing white space to java.net.URI mapping

一世执手 提交于 2019-12-12 18:33:55
问题 I have XML like the following: <repository> <location>/home/username whitespace/somedir</location> </repository> I am using JAXB to unmarshal this into a JAXB annotated Bean. The "location" XML element is mapped to java.net.URI class. The problem is that when location contains white space, JAXB (or perhaps the underlying XML parser) can't handle this and location is set to null . There is no UnmarshalException or anything, just setLocation(URI loc) is called with a null method argument. A URI

Unable to Produce JSON - javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException

两盒软妹~` 提交于 2019-12-12 18:32:52
问题 Am using Jersey 1.15, JDK 1.6, Tomcat 7, Maven 2.2.1 to create a simple Restful Web Service that should return a JSON String from a POJO that I mapped. Here's my pojo: package com.myservice.domain; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Person { private String firstName; private String lastName; // Getters & Setters } my webservice: package com.myservice.resource; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax

Jersey Custom Exception Mapper for Invalid Json String

◇◆丶佛笑我妖孽 提交于 2019-12-12 18:13:05
问题 I am working on an application for which I required to build the response in case an invalid JSON payload is sent in the request. Currently the exception message received at the server end is Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@310db662; line: 13, column: 7] This is how I'm trying to achieve it ... import java.util.ArrayList; import java.util.List

Removing an added provider in Jersey

被刻印的时光 ゝ 提交于 2019-12-12 18:10:01
问题 I am using com.yammer.dropwizard.config.Environment addProvider method to register providers in Jersey.I have a custom provider too which does a task similar to Dropwizards own MessageBodyWriterProvider. Jersey seems to select the inbuilt MessageBodyWriter instead of my custom one.So I figured that if I remove the inbuild provider which is registered and register my own it will work properly. Is there a way to remove the already added provider with the class name or other way? 回答1:

Java Jersey JSON service doesn't return quoted string?

丶灬走出姿态 提交于 2019-12-12 18:05:48
问题 Here is a simple Web Service written using Jersey @GET @Produces(MediaType.APPLICATION_JSON) public Object interpretationJson() { String o = "a simple string"; return o; } The response for this is: HTTP/1.1 200 Content-Type: application/json Content-Length: 15 Date: Mon, 02 Oct 2017 23:18:14 GMT a simple string Shouldn't the string in the response body be quoted? I don't believe this is valid JSON. Shouldn't the response be: HTTP/1.1 200 Content-Type: application/json Content-Length: 15 Date:

Jersey REST api multiple resources

人盡茶涼 提交于 2019-12-12 17:27:09
问题 Please see codes below. I can visit http://localhost:8080/messengerdemo/messages and interact with all the APIs but every time I access http://localhost:8080/messengerdemo/profiles I got a 404 not found error. What did I do wrong? I am a beginner and trying to learn jersey and REST API. web.xml <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider

JAX-RS: Consuming JSON POST data without setting Content-Type header to application/json

╄→гoц情女王★ 提交于 2019-12-12 17:16:33
问题 I have implemented a REST service using Jersey that takes JSON POST data and creates an object from a POJO model. However, in order for this to work, I have to set the Content-Type to application/json (i.e., -H "Content-Type: application/json" ). What I'd like is to be able to consume JSON POST request body without the user having to set the header, basically like Elasticsearch works: POST /test_index/_search?search_type=count { "aggs": { "nested_authors": { "nested": { "path": "authors" },

Servlet class com.foobar.jaxrs.application.MyApplication is not a javax.servlet.Servlet

流过昼夜 提交于 2019-12-12 17:07:21
问题 I'm trying to configure Jersey with Servlet 3.1 and an Application Subclass. Been reading documentation for a while and trying to get this going, but i'm not sure what's wrong here. web.xml (though I shouldn't need one I get a 404 without one...) <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd

HTTP status 415 when using Alamofire multipart upload

我的未来我决定 提交于 2019-12-12 16:29:54
问题 I'm trying to get an image uploaded to a RESTful web api and I'm getting a HTTP status 415 (unsupported media type). The strange thing is I did have it working the other day and i'm not to sure what i've changed to make it stop accepting the POST request. My swift code: func uploadImage(image: UIImage, userId: String, completion: () -> Void) { parameters["userId"] = userId let imageData = UIImageJPEGRepresentation(image, 70) let urlRequest = urlRequestWithComponents(myUrl, parameters: