jax-rs

Glassfish JAX-RS JSON Mapping Simple Example Internal Server Error 500 No Logs Produced

Deadly 提交于 2019-12-29 01:35:29
问题 I have created a simple REST service with two resources. The first resource works great and just returns MediaType.TEXT_PLAIN. For the second resource I wanted to try mapping POJO to Java and followed this example: https://github.com/jersey/jersey/tree/2.3.1/examples/json-moxy/src/main/java/org/glassfish/jersey/examples/jsonmoxy with my testbean defined as: @XmlRootElement public class Company { public String name; public String symbol; public String country; public Company(String name,

Inheritance with JAX-RS

别来无恙 提交于 2019-12-28 12:00:14
问题 I am using JAX-RS for my web services. I have common functionality and would like to use inheritance. I am providing simple CRUD operations. I have defined an interface like so: public interface ICRUD { @POST @Consumes("application/json") @Produces("application/json") @Path("create") public String createREST(String transferObject); @GET @Consumes("application/json") @Produces("application/json") @Path("retrieve/{id}") public String retrieveREST(@PathParam("id") String id); @POST @Consumes(

JAX-RS with embedded server

一世执手 提交于 2019-12-28 10:46:16
问题 Clarification: this question was about GZIPping an JAX-WS-based REST service, but I've decided to change the topic to make it easier to find I'm implementing a REST service via JAX-WS Provider <Source> , and publishing it with standard Endpoint (the reason is that I want to avoid using a servlet container or application server). Is there a way to make server to gzip response content, if Accept-Encoding: gzip is present? HOW-TO Samples provided by nicore actually works, and it allows you to

JAX-RS (Jersey) custom exception with XML or JSON

亡梦爱人 提交于 2019-12-28 08:09:35
问题 I have a REST service built using Jersey. I want to be able to set the MIME of my custom exception writers depending on the MIME that was sent to the server. application/json is returned when json is received, and application/xml when xml is received. Now I hard code application/json , but that's making the XML clients left in the dark. public class MyCustomException extends WebApplicationException { public MyCustomException(Status status, String message, String reason, int errorCode) { super

How to Convert a Properties Object to JSON Object with JAXB

早过忘川 提交于 2019-12-28 06:53:28
问题 I want to accept and respond JSON objects in a REST Application. The data I need to send and receive are in a .properties file. I have already read them and are now in a Properties Object(From java.util.Properties ). Is there a way to marshal and unmarshal Properties Objects, without implementing a new class? I am using Jax-rs API in a Weblogic server. @POST @Path("{id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public JSONObject getbyID(@PathParam("id"

Request-scoped context field injections into RESTEasy singletons

别等时光非礼了梦想. 提交于 2019-12-28 06:24:09
问题 While trying to embed RESTEasy with singleton resources in OSGi (using something similar to resteasy-osgi-bundle), to my surprise field-injected @Context UriInfo was available and valid on each request. Digging deeper I found proxy magic and ThreadLocal in ResteasyProviderFactory . All well and good, but I cannot find any reference to such a behavior in docs, neither in RESTEasy's one nor in JAX-RS spec. In Jersey docs we can find something like: The exception exists for specific request

Get HttpServletRequest in Jax Rs / Appfuse application?

陌路散爱 提交于 2019-12-28 06:17:11
问题 I created a basic application shell with AppFuse, and followed the AppFuse tutorial to create a a simple RESTful service with Jax-RS. That works just fine. A call to http://localhost:8080/services/api/persons returns a collection of Person objects as a Json formatted string with the right data. I now would like to access the ServletRequest and ServletResponse objects from within a RESTful service exposed by Appfuse (to use another library that requires these objects). I think that should be

Required @QueryParam in JAX-RS (and what to do in their absence)

早过忘川 提交于 2019-12-28 03:29:10
问题 I deploy a web-services component to JBoss Application Server 7 using the RESTEasy JAX-RS implementation. Is there an annotation available to declare required, mandatory @QueryParam parameters in JAX-RS ? And, if not, what is the 'standard' way to deal with situations where such parameters are missing? My web service (resource) methods return JSON-stringified results when properly invoked with all the mandatory arguments, but I'm not sure what is the best way to indicate to the caller that a

A message body writer for Java class not found

喜夏-厌秋 提交于 2019-12-28 02:39:35
问题 I am new to using JAX-RS and wrote a sample application that outputs a json object. but I am getting an exception. Here is my code: @Path("/hello") public class HelloWorldService { @GET @Path("/query/{artist_id}") @Produces("application/json") public Data getMsg(@PathParam("artist_id") int artist_id, @QueryParam("from") int from, @QueryParam("to") int to) { Data d=new Data(); d.setName("Mateen"); d.setRoll(77); return d; } } My data is simply a POJO class: @XmlRootElement public class Data {

What exactly is the ResourceConfig class in Jersey 2?

不羁岁月 提交于 2019-12-27 11:53:33
问题 I have seen a lot of Jersey tutorials that starts with something like @ApplicationPath("services") public class JerseyApplication extends ResourceConfig { public JerseyApplication() { packages("com.abc.jersey.services"); } } without explaining what exactly the ResourceConfig class is. So where can I find its documentation, usage, etc.? Googling for "jersey resourceconfig" does not yield any official doc. Some of my questions about this class and its usage are: What things can I do inside the