jersey-2.0

How can I enable MultiPartFeature?

…衆ロ難τιáo~ 提交于 2019-11-28 13:44:32
My JAX-RS application has an extended Application class. @ApplicationPath("/") public class MyApplication extends Application { // empty; really empty } How can I enable org.glassfish.jersey.media.multipart.MultiPartFeature without modifying the class? Or without the necessity of registering all resource classes/packages? Paul Samsotha Not sure why you don't just use a ResourceConfig instead of an Application class. The only reason I can think of is portability, but the use of the Jersey specific multipart feature already breaks that portability. But anyway, I'll try to answer this in the

Maven dependencies needed for Jersey 2.x (2.6)

て烟熏妆下的殇ゞ 提交于 2019-11-28 13:31:52
I'm trying to migrate from Jersey 1.x (1.2) to 2.x (2.6), I have trouble identifying the exact maven dependencies, jersey documentation is not comprehensive enough, it doesn't mention what maven dependencies are needed for the new version. Does anyone have comprehensive list of maven dependencies needed for Jersey 2.x (2.6)? Jersey doc https://jersey.java.net/documentation/latest/migration.html#mig-1.x For a servlet environment, the only dependency you need is <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.6</version

restful service interface with jersey

不羁的心 提交于 2019-11-28 12:41:52
Can I create a restful service with interface and implementation class? and all JAX-RS related imports go into the interface? i am using jersey2.4 and jetty8.1. here is my interface: MyService.java package foo.bar; @Path("/abc") public interface MyService { @GET @JSONP @Path("/method/{id}") public MyResponse getStuff(@PathParam("id") Integer id); } MyServiceImpl.java package foo.bar.impl; public class MyServiceImpl implements MyService { public MyServiceImpl() {} @Override public MyResponse getStuff(Integer id) { // do stuff return MyResponse; } } here's my web.xml: <servlet> <servlet-name

Read another parameter within jersey's ParamConverter

懵懂的女人 提交于 2019-11-28 12:19:17
I've made a ParamConverter which provides an Instant (Date) when given a string formatted as either Instant's native ISO-8601, or as an integer number of milliseconds since the epoch. This is working fine, but I also need to be able to support other date formats (the customers are fussy). To avoid the classic dd/mm/yyyy vs mm/dd/yyyy ambiguity, I'd like to have the customer specify their preferred format as part of the request*. e.g: GET http://api.example.com/filter?since=01/02/2000&dateformat=dd/mm/yyyy passed to a method which looks like: @GET String getFilteredList( final @QueryParam(

Optional params in REST API request using Jersey 2.21

≯℡__Kan透↙ 提交于 2019-11-28 12:09:32
I'm playing around with Jersey 2.21 and I'd like to know if it's possible to have an "optional" param which can, or not, be present in the request made to the server. I want to successfully access this two methods: http://localhost:8080/my_domain/rest/api/myMethod/1 http://localhost:8080/my_domain/rest/api/myMethod As you can see, I'm trying to make the integer ( id ) param an optional one. I've declared myMethod as follows: @GET @Path("myMethod/{id}") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") public String myMethod(@PathParam("id") Integer id, @Context HttpHeaders hh) This

How can I get the stack trace when 500 server error happens in Jersey?

半城伤御伤魂 提交于 2019-11-28 12:07:01
问题 When in jersey server I have server 500 error: In server response don´t have stack trace or some info. In Eclipse console don´t have exception stack trace I try to catch exception in server and print trace in console, but nothing happens How can I get the stack trace when 500 server error happens? 回答1: Most of the time, a generic ExceptionMapper will do the trick. @Provider public class DebugMapper implements ExceptionMapper<Throwable> { @Override public Response toResponse(Throwable t) { t

securing rest services in Jersey

早过忘川 提交于 2019-11-28 10:29:36
I am very much new to web services. I have exposed some REST services using Jersey 2 in integration with Spring. Now I need to secure those rest services using authentication with username/password. I am told not to use Spring security. I have no idea of how to do this. I did search on the net but various links show various implementation and I am unable to decide how to proceed with it. I know this is something vague question but please help in this context. Paul Samsotha A common way for authenticating with username and password is to use Basic Authentication . Basically the client needs to

Using Jersey's Dependency Injection in a Standalone application

你离开我真会死。 提交于 2019-11-28 08:55:09
问题 I have a interface here interface Idemo{ public int getDemo(int i); } And it's one implementation class DemoImpl implements Idemo{ @Override public int getDemo(int i){ return i+10; } } And there is a class which has a dependency on Idemo class Sample{ @Inject Idemo demo; public int getSample(int i){ return demo.getDemo(i); } } Now say I want to test Sample class public class SampleTest extends JerseyTest { @Inject Sample s; @Override protected Application configure() { AbstractBinder binder =

Register JodaModule in Jax-RS Application

那年仲夏 提交于 2019-11-28 08:52:00
问题 I'm writing a Jax-RS application using Jersey, and Jackson2 under the hood to facilitate JSON i/o. The service itself works fine, but I'd like to improve it by having the Jackson mapper automagically serialize/deserialize date and date-times to JodaTime objects. I'm following the documentation here and have added the relevant jars, but I'm lost on this instruction: Registering module To use Joda datatypes with Jackson, you will first need to register the module first (same as with all Jackson

CDI interceptor injected into a jersey RS service(resource) not working?

余生颓废 提交于 2019-11-28 08:19:10
问题 So, I have a tomcat 8 + jersey 2.5.1 + weld CDI app that works very well in most cases. Where it fails is that I am unable to intercept jersey resource method calls with a CDI interceptor. This makes sense because a jersey resource class is not a CDI bean. Then, is there any way to make a CDI interceptor work in jersey? Another way to ask this question: Can a CDI bean be used as a Jersey resource? Thanks! EDIT: Before I wrote my RESTful resources using Jersey, I had CDI interceptors that were