jax-rs

Custom Jersey parameter unmarshalling

扶醉桌前 提交于 2019-12-24 13:52:28
问题 I receive as a query parameter a String line like parameter=123,456,789 What I want to obtain is List<Integer> directly in my controller. Something like this: @GET @Path(REST_PATH) @Produces(MediaType.APPLICATION_JSON) public Response getSomeStuff(@MagicalThing("parameter") List<Integer> requiredList) What can be done except for custom provider and an additional type: https://stackoverflow.com/a/6124014? Update: custom annotation solves the puzzle http://avianey.blogspot.de/2011/12/exception

load on startup and Jersey

梦想的初衷 提交于 2019-12-24 13:18:50
问题 Possibly duplicate of Servlet not loading on startup, however Im not allowed yet to comment, so I have to start a new question for this... Same setting, having a servlet using Jersey and Tomcat, using load-on-startup for loading the container. However, due to the thread mentioned above, I understand that this only load the Jersey container but not the classes I setup for the servlet. So, related to what is implied in the answer of the thread above, how is it done that not only the contained

Rendering a new .jsp page using JAX-RS UriBuilder

僤鯓⒐⒋嵵緔 提交于 2019-12-24 11:28:03
问题 I am simply trying to send a new .jsp page to be rendered by the client using the URIBuilder. So I have a main.js send a POST to the server which calls logIn(). For now I just want this to send a new .jsp file to the client to be rendered. Nothing happens thus far, I have tried using different file paths - before I just used "Feed.jsp" as the file path. I feel like there is more to this that I am not picking up on. Here is my main.js file. It sends a POST to server successfully via the logIn(

Subresouce and CDI Injection Issue

孤人 提交于 2019-12-24 11:19:04
问题 I am new to jax-rs and i am stuck with subresources. Take a look. this is not working @Path(..) public class Test { @Path(...) public SubResource getSub(){ return new SubResource(); } } public class SubResource { @Inject private MyBean myBean; @GET public String getStr(){ return myBean.getStr(); // myBean is null, injection didnt work properly } this works, but why???? @Path(..) public class Test { @Context private ResourceContext context; @Path(...) public SubResource getSub(){ return

JAX-RS REST service + EJB on WildFly 10, always adds no-cache HTTP header in responses

江枫思渺然 提交于 2019-12-24 09:49:56
问题 I have wrote a stateless EJB that provides a rest service. I am working with the Wildfly 10 application server and developing with the Netbeans IDE. I have tried to cache the return values of few methods for few hours by adding a max-age header in the http-response of the service methods. Please consider this is a simplified version of my bean: @Stateless @DeclareRoles({"role1","role2"}) @RolesAllowed({"role1","role2"}) @Path("api-dummy") public class DummyApiREST { @EJB private StuffFacade

Sending String[] through REST with Jersey

空扰寡人 提交于 2019-12-24 08:49:48
问题 I'm trying to implement a REST webservice with Jersey. I'm using JBoss AS 7.1.1 Final as my webserver. The problem is happening whenever I attempt to use a String[] as part of my method's signature: @Override @POST @Path("/getVersion") public ControllerVersion getVersion(String deviceID, String[] macAddresses) { System.out.println("Received "+deviceID+", and macAddress[0] "+macAddresses[0]); return new ControllerVersion(); } The exception that's being thrown on the server side is as follows:

Reading JSON to map with JAX-RS

霸气de小男生 提交于 2019-12-24 08:17:47
问题 I'm writing a Java EE REST application (it runs under Glassfish 4.1) and I'm having problems reading a simple key-value JSON list. I'm trying to produce and consume a JSON using a POJO class, producing works fine, but consuming is not working. Let's get to the code. The POJO class I use for produce and consume JSON is like this: public class Transport { protected Integer id; protected String name; protected Map<String, String> fields; // ...getters and setters... } The REST resource import

JAX RS MediaType annotation values must be of the form 'name=value'

自古美人都是妖i 提交于 2019-12-24 08:13:41
问题 I am supposed to learn restful services using Java and JAX RS. I am trying to compile the following code, however I receive an error stating: annotation values must be of the form 'name=value' . The code is in principle correct, it is equivalent with http://www.vogella.com/tutorials/REST/article.html import javax.ws.rs.*; import javax.ws.rs.core.*; import javax.xml.ws.Response; import java.io.IOException; @Path("/") public class WebResource { @GET @Produces( MediaType.APPLICATION_XML,

Custom HTTP reason phrase using ExceptionMapper

北战南征 提交于 2019-12-24 06:46:02
问题 I have defined the following Exception Mapper to handle the custom HttpCustomException package com.myapp.apis; import com.myapp.apis.model.HttpCustomException; import com.myapp.apis.model.HttpCustomExceptionStatusType; import com.myapp.apis.model.HttpCustomNotAuthorizedException; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; @Provider public class HttpCustomExceptionMapper implements ExceptionMapper <HttpCustomException> { @Override

How to show browser login form for basic authentication using RESTEasy

十年热恋 提交于 2019-12-24 06:37:49
问题 I´m currently messing around with JAX-RS specifically Resteasy, because it "just works" with Wildfly and I don´t have to configure anything. That´s really the only reason I use that. I did already implement Basic Authentication, looking forward to replacing it with OAuth2 later, just did this now for simplicity reasons. The ContainerRequestFilter looks like this @Provider public class SecurityFilter implements ContainerRequestFilter { private static final String AUTHORIZATION_HEADER_KEY =