jax-rs

REST async operation throws ProcessingException

筅森魡賤 提交于 2019-12-23 08:56:39
问题 I am building a REST api using jax-rs 2 . I keep getting an exception when I try to run the REST service.I am running to check for asyncResponse . I am not sure what I am doing wrong with the asyncResponse. As without it , the code runs fine. Also, the web container is Tomcat 7. here is the stack trace of the exception: WARNING: Attempt to put servlet request into asynchronous mode has failed. Please check your servlet configuration - all Servlet instances and Servlet filters involved in the

JAX-RS: OPTIONS for every Resource

痴心易碎 提交于 2019-12-23 07:22:37
问题 I am using a JAX-RS interface with XMLHttpRequest (XHR). Due to the XHR preflight, XHR send always OPTIONS before calling the real resource. Now I have dozens of methods and I need the OPTIONS for every resoruce. Is there any way to do this automatically? I dont want to write dozens of methods like: @OPTIONS @Path("/{id}") @PermitAll public Response optionsById() { return Response.status(Response.Status.NO_CONTENT).build(); } @OPTIONS @Path("/{id}/data") @PermitAll public Response

Servlet init() method equivalent in JAX-RS

℡╲_俬逩灬. 提交于 2019-12-23 07:00:59
问题 I am working on an application which is running on Glassfish. I am supposed to convert the servlets to proper restful stuff, by using jax-rs and jersey. I have been trying to find a workaround for init() method, but till now i failed. Here is the original part, using servlets: import javax.servlet.* public void init(ServletConfig config) throws ServletException { super.init(config); if (!isRunning() == true)) { /* Do some stuff here*/ } logger.info("Deamon has started"); } and this one which

Should we always use Asynchronous JAX-RS resources For mobile backend?

强颜欢笑 提交于 2019-12-23 05:25:27
问题 I am building Mobile backend API using Java EE - JAX-RS 2.0 technology. Since most of mobile client consumes are asynchronous http calls so my question is: Should I use asynchronous feature for all JAX-RS resources ? And the reason if not? The below is the template Mobile Async API @Path("/async_api") public class AsyncResource { @GET @Path("/loadUsers") @Produces(MediaType.APPLICATION_JSON) public void loadUsers(@Suspended AsyncResponse asyncResponse) { //TODO: ManagedExecutorService new

JAX-RS Rest Filter does not invoke

北慕城南 提交于 2019-12-23 05:15:21
问题 I have an api that needs to implement security. But the filter is not invoked. my call pass directly to the endpoint... My Secure interface @NameBinding @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE,ElementType.METHOD}) public @interface Seguro {} My Filter @Seguro @Provider @Priority(Priorities.AUTHENTICATION) public class FiltroAutenticacao implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { String

JAX-RS, components can access which information through the request life cycle

纵饮孤独 提交于 2019-12-23 04:57:27
问题 While going through the processing of a request in JAX-RS, what I studied is that the flow of the whole process is as below; I know that there are different components , which serve the purpose of pluggability, like we can have filters and can plug them to whatever resource methods we want, same is the case with interceptors(and I know that they are triggered around MessageBodyWriters and MessageBodyReaders). But I am confused about each of the component and the piece of information which

Jersey, Jackson and JAX-RS POST multiple JSON formats

风流意气都作罢 提交于 2019-12-23 04:45:53
问题 I am trying to be able to define the following code: public class MyObject { private String name; ... // Other attributes } @Path(...) @Stateless public class MyRestResource { @POST @Consumes(MediaType.APPLICATION_JSON) public Response create(List<MyObject> myObjects) { // Do some stuff there } } I know that I need to use: DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true to setup correctly my object mapper to be able to accept single value as array on my rest resources. I

Google App Engine Jersey error format json

心不动则不痛 提交于 2019-12-23 04:43:37
问题 I'm developing a REST API with Google App Engine JAVA with Jersey and JAX-RS. I want to be able to send custom errors to users in JSON format, for that I'm using javax.ws.rs.ext.ExceptionMapper All works well when I run the app with Jetty on my local machine, but when I deploy to Google I get the default HTML 404 page Here is the resource code: @GET @Produces(MediaType.APPLICATION_JSON) @Path("{id}") public Customer getCustomer(@PathParam("id") String id) { Customer customer = getCustomer(id)

restful call Wrong MediaType format for MediaType:“*; q=.2”

跟風遠走 提交于 2019-12-23 03:11:24
问题 Trying to execute restful web service using POST method. Here is the relevant part of my interface: @Path("/customers") public interface CustomerResource { @POST @Consumes(MediaType.APPLICATION_XML) public Response createCustomer(InputStream is); ..... } The implementation: // Create customer public Response createCustomer(InputStream is) { logger.debug("In createCustomer"); Customer customer = readCustomer(is); customer.setId(idCounter.incrementAndGet()); customerDB.put(customer.getId(),

JAX-RS REST Services as a library

♀尐吖头ヾ 提交于 2019-12-23 03:04:25
问题 Is it possible to package my rest resource classes in a .jar library so that when they are included in someone's app that app gets the services? i am currently using jersey (jersey.dev.java.net) 回答1: Well, I don't see why it won't work GRANTED that person defines the rest servlet in their web.xml to locate your REST package from the jar... like this:- <servlet> <servlet-name>Jersey Rest Web Service</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet<