jax-rs

How to return an ArrayList from a database query?

I am querying a database for a web service using the Jersey JAX-RS. I can return a single row as XML or JSON, but I can't figure out how to return multiple records. Do I use an ArrayList? If so how? Does anyone have an example of how to do this? Thanks ...

Apache CXF REST Services w/ Spring AOP

I'm trying to get Apache CXF JAX-RS services working with Spring AOP. I've created a simple logging class: public class AOPLogger{ public void logBefore(){ System.out.println("Logging Before!"); } } My Spring configuration (beans.xml): <aop:config> <aop:aspect id="aopLogger" ref="test.aop.AOPLogger"> ...

Using @Context, @Provider and ContextResolver in JAX-RS

I'm just getting acquainted with implementing REST web services in Java using JAX-RS and I ran into the following problem. One of my resource classes requires access to a storage backend, which is abstracted away behind a StorageEngine interface. I would like to inject the current StorageEngine instance into the resource class serving th...

JAX-RS JSON java.util.Date Unmarshall

Hi, I'm using Jersey (jax-rs), to build a REST rich application. Everything is great, but I really don't understand how to set in JSON Marshalling and Unmarshalling converting option for dates and numbers. I have a User class: @XmlRootElement public class User { private String username; private String password; private jav...

How do you secure Apache CXF RESTful APIs?

Is there an easy way to secure RESTful API exposed via Apache CXF's JAX-RS implementation? Are there any hooks for security via Spring Security?. I heard of people using Basic Authentication over HTTPS, but I haven't seen any actual examples. Any ideas would be greatly appreciated. Thanks! ...

Jersey JAX-RS on Glassfish 3.0.1: Can I have an empty webapp element in my web.xml?

My understanding is that glassfish 3 is JEE6 compliant and jax-rs-aware, and that consequently I do not have to include the jersey servlet container and mapping in my web.xml file. Here's what I was hoping my web.xml could look like <webapp> </webapp> That doesn't work though, as I get 404's when I try to hit my jax-rs path-anotated ...

Getting the URL of the Calling Application

When using JAX-RS is there a way of getting information about who is calling the webservice? Can we get the ip or url of the calling application? If so how do you do it? Thanks ...

How to get details of ClientResponseFailure in RestEasy Client ?

How to get http response contents when status >=400 is returned. That's my code sample : try { ChatService client = ProxyFactory.create(ChatService.class, apiUrl); client.putMessage(dto); } catch (ClientResponseFailure ex) { System.out.println(ex.getResponse().getEntity().toString()); } This throws...

Java Jax-rs Jersey Spring: How to create a MessageBodyReader and MessageBodyWriter for Multipart

I have an application with Java/Jersey/Spring2.5/Jboss. In one of the service response, I want to use Multipart. How can I send a Multipart response? How should I implement the MessageBodyReader and MessageBodyWriter? I'm wrapping a byte[] in the Multipart. I have to display this on a JSP. Before this, I was using a JAXB object to wrap ...

Apache CXF - How to add custom HTTP Header to JAX-RS response?

I'm trying to add custom HTTP header to response in Apache CXF. I need to count MD5 from content and add it as a HTTP header. I tried to use ResponseHandler or Interceptor. My last try was @Component public class ResponseBPAuthFilter extends AbstractOutDatabindingInterceptor { public ResponseBPAuthFilter() { super(Phase.MAR...

How to configure a custom Spring PerformanceInterceptor for a Resource Method

I'm using Java/Spring/Jersey v1.0.3/Jboss. I want to configure a PerformanceInterceptor for my resource. How can I do this? Let's say I have the following configuration: <bean id="service" class="com.services.RESTfulService" /> <bean name="servicePointcut" class="org.springframework.aop.support.NameMatchMethodPointcut"> <property name="...

Sending protocol buffers via REST

Hi, I am trying to implement protocol buffers for client/server using REST. I am still a bit confused if I need to send protocol buffers request in byte format? I mean, in my client code, do I need to serialize object to byte array? For example protoRequest.build.toByteArray() And in the server, do I need to c @POST @Consumes...

Protocol Buffers MIME problem

Help! Trying to implement Protocol Buffers via Rest (Jersey), but get this exception. class com.util.ProtobufMessageBodyReader class com.util.ProtobufMessageBodyWriter Jul 6, 2010 3:43:37 PM org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-9102 Jul 6, 2010 3:43:37 PM org.apache.catalina.startup.Catali...

JAX-RS custom mapping from entities to xml

Here's my problem: Say I have two entities annotated with JAX-RS annotations: @XmlRootElement @Entity public Person { private String firstname; private String lastname; private Address address; } @XmlType @Entity public Address { private String street; private String city; } This will get rendered into: <person> <first...

System wide adapter in Jersey?

I'm trying configure a "system wide" custom javax.xml.bind.annotation.adapters.XmlAdapter for the java.util.Locale type in Jersey. It's easy enough to use @XmlJavaTypeAdapter on classes I control but that's not always the case (3rd party code that I can't annotate). It seems like it would be a pretty common problem but I can't find any...

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

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....

Passing the URI Path to the JAX-RS Providers

I recently implemented a Jersey JAX-RS Rest service. I created a JIBX provider that allows one to unmarshal and marshall between XML and Java types. I would like to also version my service by specifying the version in the URL path. Versioning would include the version of message binding used to marshal and unmarshall the Java types. ...

Is it possible to use JAX-RS as a web framework?

I've been looking into JAX-RS lately because I really like the Java platform and a RESTful style of web development. I've read a lot about using JAX-RS for creating RESTful Web Services, but is it possible to use JAX-RS to create RESTful web sites? I guess more specifically, is it possible to use JAX-RS as a controller (to retrieve requi...

Call ExceptionMapper from another ExceptionMapper in JAX-RS

In my RESTEasy application I'm getting a java.lang.reflect.UndeclaredThrowableException, because a checked exception is being thrown from a method that doesn't declare the exception in the throws clause. So I'm writing an UndeclaredThrowableExceptionMapper. The UndeclaredThrowableException wraps the real exception; I call e.getCause() ...

Why are names returned with @ in JSON using Jersey

I am using the JAXB that is part of the Jersey JAX-RS. When I request JSON for my output type, all my attribute names start with an asterisk like this, This object; package com.ups.crd.data.objects; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlType; @XmlType public class ResponseDetails { @Xm...