jax-rs

How to use PATCH method in CXF

白昼怎懂夜的黑 提交于 2019-12-23 12:46:16
问题 I am trying to use PATCH method in my client using CXF implementation of JAX-RS. At first I defined the PATCH annotation as @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @HttpMethod("PATCH") public @interface PATCH { } Referencing what was written here : How to have a @PATCH annotation for JAX-RS? Then I found out @PATCH was added into CXF 3.1.2, so I changed version in my maven's pom.xml and indeed there is public @interface PATCH inside of package org.apache.cxf.jaxrs

Jax-RS not registering resource with @provider annotation

蓝咒 提交于 2019-12-23 12:38:55
问题 I have a rest application running in weblogic 12c using jersey api. I have a http request filter class with an annotation @provider. however when deploying the application the filter class is not registered with the other resource classes that I have added in my ApplicationConfig class. and subsequently I am not able to filter the http requests. below are my logs and the code Sep 01, 2015 11:16:12 AM weblogic.jaxrs.server.portable.servlet.JerseyServletContainerInitializer onStartup INFO:

JPA LazyInitializationException when returning a JAXB Object through a Webservice

假如想象 提交于 2019-12-23 12:19:00
问题 I'm working with JBoss. i created a simple JAX-RS Webservice that retrieves a JPA Entitiy from the database and returns it to the user. As soon as I have a relationship (@OneToOne) to another Entity I get a LazyInitializationException. The Reason is simple: The Relationship was not initialized by JPA (lazy loading) and when jaxb tries to serialize it, everything breaks. But how do i solve this? I could touch the relationship before i return the object. Not nice and complex for greater object

java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; when deploying jersey ws to Weblogic

时光总嘲笑我的痴心妄想 提交于 2019-12-23 12:09:03
问题 I'm deploying a web service application on Weblogic 12. The application uses jersey and thus depends on javax.ws.rs-api:2.0.1 library. However when I deploy it to server I have a following error : Caused By: java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:304) at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285) at org.glassfish.jersey

JAX-RS response.getEntity returns null after post

心不动则不痛 提交于 2019-12-23 11:53:16
问题 When i invoke next code: Response response = target.request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); response.getEntity(); response.getEntity() is always null. But when i invoke: JsonObject json = target.request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), JsonObject.class); variable json is not null. I need to use first variant because i need to check response status.

Jersey - JAX/RS - how to handle different content-type using different handlers

≯℡__Kan透↙ 提交于 2019-12-23 10:08:47
问题 I would like to handle two different media types for the same REST URL using different handlers using Jersey/JAX-RS. Is that possible? For example: @Path("/foo") public class FooHandler { @POST @Path("/x") @Consumes("application/json") public Response handleJson() { } @POST @Path("/x") @Consumes("application/octet-stream") public Response handleBinary() { } } 回答1: Yes this is possible. There are a lot of things that go into determining the resource method, and the media type is one of them.

Jetty + Jersey + Jackson, different behavior in Eclipse (Success) vs command line (Error Unsupported Media Type)!

为君一笑 提交于 2019-12-23 09:53:08
问题 I'm getting crazy trying to run Jetty Jersey and Jackson outside Eclipse. I have a main class: public class Main { public static void main(String[] args) throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*").setInitParameter( "jersey.config.server.provider.classnames", CanaryEndpoint.class.getCanonicalName()); Server jettyServer = new org.eclipse.jetty.server

Optimizing JaxRS/Jackson to exclude nulls, empty Lists, arrays

允我心安 提交于 2019-12-23 09:05:15
问题 We're using JaxRS & Jackson to send data to our client. Since the client is Javascript, we don't really need to send null values or empty arrays if there isn't a valid value for that property (which JaxRS does by default). Is there a way around this? An example. JaxRS sends this: {"prop1":[],"prop2":null,"prop3":"foo"} where we could have gotten away with {"prop3":"foo"} 回答1: There are multiple ways to achieve this, depending; annotation @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL

How to stream an endless InputStream with JAX-RS

£可爱£侵袭症+ 提交于 2019-12-23 09:03:10
问题 I have an endless InputStream with some data, which I want to return in response to a GET HTTP request. I want my web/API client to read from it endlessly. How can I do it with JAX-RS? I'm trying this: @GET @Path("/stream") @Produces(MediaType.TEXT_PLAIN) public StreamingOutput stream() { final InputStream input = // get it return new StreamingOutput() { @Override public void write(OutputStream out) throws IOException { while (true) { out.write(input.read()); out.flush(); } } }; } But content

JAX-RS Custom ExceptionMapper not intercept RuntimeException

╄→гoц情女王★ 提交于 2019-12-23 09:01:32
问题 I want to wrap underlaying RuntimeExceptions to a custom json format , making the servlet container won't dump the stacktrace to client. I follow this question : JAX-RS (Jersey) custom exception with XML or JSON . When calling : try { doSomething(parameters); } catch(RuntimeException e) { throw new MyCustomException(500 , e.getMessage() , Status.INTERNAL_SERVER_ERROR); } When I intentionally feed wrong parameters (and trigger RuntimeException thrown by doSomething() ) , I didn't see