jersey

Message body writer error while doing POST operation with JSON payload using Jersey Client

爱⌒轻易说出口 提交于 2019-12-11 12:08:39
问题 e I am trying to do a POST operation with JSON payload for REST service using Jersey Client in JUnit . Here is what I have done: Resource Class @Path("/Users") @Component public class UserResource{ @POST @Path("register") @Consumes({MediaType.APPLICATION_JSON}) @Produces(MediaType.APPLICATION_JSON) public String registerUser(RegisterRequestJSON requestJson) { User user = userManager.getUserInformationByEmail(email); UserInfoJSON userInfoJSON = new UserInfoJSON(); userInfoJSON.copyFromUserBean

jax-rs share information between ContainerRequestFilter and ReaderInterceptor

你说的曾经没有我的故事 提交于 2019-12-11 11:55:15
问题 I'm using Jax-rs, and I'm doing some logic in the Filters , and then I would like to share information between ContainerRequestFilter (Filter) and ReaderInterceptor (Interceptor). I can see that between Filters and Interceptors is possible through the set/getProperties but between Filter and Interceptors is not possible. Any idea if there's any other mechanism?. Regards. 回答1: You can use a request scoped service that you inject into both the filter and the interceptor. For instance public

Eclipse : Unable to load jar's into the Tomcat WEB-INF/Lib folder ?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 11:54:02
问题 I'm getting this tomcat error " java.lang.ClassNotFoundException:org.glassfish.jersey.servlet.ServletContainer" when I run Tomcat using eclipse : I see that eclipse does not include the jars into the (tomcat 7.0) WEB-INF/Lib folder, though I tried this : Included the Maven dependencies in "Web Deployment Assembly" under Project properties. ( Maven downloaded the dependencies in the POM.xml , but these jars are not getting picked up by eclipse ) The POM.xml as follows: <project xmlns="http:/

Jackson equivalent to @XmlSeeAlso

99封情书 提交于 2019-12-11 11:36:49
问题 I am writing a RESTful web service using Java and Jersey, where the service will accept either XML or JSON inputs. Jackson is used as the JSON deserializer, and integrated into the Jersey config. One of the endpoints is a POST request to a URL, where the content can be one of several different Java classes, and there is a common base class. These classes - with XML annotations - are: @XmlRootElement(name = "action") @XmlAccessorType(XmlAccessType.NONE) @XmlSeeAlso({ FirstAction.class,

Unable to test Jax-rs with JSON entity

夙愿已清 提交于 2019-12-11 11:32:30
问题 I am trying to test a Jax-rs resource by following this https://jersey.java.net/documentation/latest/test-framework.html, and I am using container jersey-test-framework-provider-jdk-http I can assert status code. However, when I try to readEntity, I get exception: javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type application/json and type class java.lang.String at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound

How to fix xml-less autowiring of service

不想你离开。 提交于 2019-12-11 11:13:34
问题 When I call a service directly in my main() I can query the database and things work fine. When a jersey request comes in and maps the JSON to NewJobRequest I can't use my service because the @Autowire failed. My app: public class Main { public static final URI BASE_URI = getBaseURI(); private static URI getBaseURI() { return UriBuilder.fromUri("http://localhost/").port(9998).build(); } protected static HttpServer startServer() throws IOException { ResourceConfig rc = new

How can I inject a custom factory using hk2?

青春壹個敷衍的年華 提交于 2019-12-11 11:01:42
问题 I'm having a hard time to work with jersey test framework. I have a root resource. @Path("sample") public class SampleResource { @GET @Path("path") @Produces({MediaType.TEXT_PLAIN}) public String readPath() { return String.valueOf(path); } @Inject private java.nio.file.Path path; } I prepared a factory providing the path . public class SamplePathFactory implements Factory<Path> { @Override public Path provide() { try { return Files.createTempDirectory(null); } catch (final IOException ioe) {

HTTP method GET is not supported by this URL. (Java rest api with jersey)

自作多情 提交于 2019-12-11 10:49:59
问题 im following one of the online tutorials for making rest api in java. I work in Eclipse 4.5.2 . When i enter http://localhost:7001/ds2/api/v1/status i got mentioned in a title error. I included Jersey 1.19 . Im using Oracle WebLogic Server 12c R2 (12.2.1). Starting page(index) works fine, but anything i would enter after /api/ gives me the same error. My V1_status.java class: package ds2.status; import javax.ws.rs.*; import javax.ws.rs.core.*; @Path("/v1/status") public class V1_status { @GET

Jersey content type customization

烂漫一生 提交于 2019-12-11 10:45:42
问题 Hi I've got a scenario where I would like to control the content type return by a jersey web-service dynamically without using request header content-type. Currently I do the standard thing: @Produces( {"application/xml", "application/json"}) public ContactsConverter getSearchContacts() So by default I'll get xml back. However, if I want to get a json object back, i'll have to set "Content-Type: application/json" in my request header. This is currently not an option for me because the request

Setting a Jersey response status code from interface without returning Response

孤人 提交于 2019-12-11 10:08:54
问题 I am trying to set a response status of the following Jersey REST endpoint @Path("/roles") public interface IRoleService { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Role create(Role role); } Since it creates a new resource it would be appropriate if it returned Status code 201 but currently it returns 200. The only way I found how to set the status code is to have the method return a javax.ws.rs.core.Response and set it there, but I really do not want