jersey

Validating path to nested resource

点点圈 提交于 2021-01-27 14:20:46
问题 I'm using Jersey to implement a RESTful Service with some nested resources. This is a basic example of what I currently have: @Path("/sites") public class SiteResource { @GET @Path("/{siteId}") public Site get(@PathParam("siteId") long siteId) { Site site = // find Site with siteId if (site == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } return site; } } @Path("/sites/{siteId}/articles") public class ArticleResource { @GET @Path("/articleId") public Article get(

ServletContextListener does not execute on deployment

你说的曾经没有我的故事 提交于 2021-01-27 13:48:55
问题 I am trying to initialize a streaming object when my war file is deployed. I wrote an Initializer class that implements ServletContextListener and added a listener-class tag to my web.xml. The issue is that the ContextInitialized Event occurs when I make the first request to my application and NOT when the app is deployed. Is there a better way to initialize my application? EDIT: public class Initializer implements ServletContextListener{ @Override public void contextDestroyed

Jersey: How to use a custom `ExceptionMapperFactory`

℡╲_俬逩灬. 提交于 2021-01-27 13:23:16
问题 I need to use a custom ExceptionMapperFactory to implement a custom find() logic. public class MyExceptionMapperFactory extends ExceptionMapperFactory { // [...] @Override public <T extends Throwable> ExceptionMapper<T> find(Class<T> type) { // [...] } } How can I use/register it? Registering it in my RestApplication has no effect: public class RestApplication extends ResourceConfig { public RestApplication() { register(JacksonFeature.class); register(JacksonXMLProvider.class); register

Jersey web service proxy

不羁岁月 提交于 2021-01-27 06:58:48
问题 I am trying to implement a web service that proxies another service that I want to hide from external users of the API. Basically I want to play the middle man to have ability to add functionality to the hidden api which is solr. I have to following code: @POST @Path("/update/{collection}") public Response update(@PathParam("collection") String collection, @Context Request request) { //extract URL params //update URL to target internal web service //put body from incoming request to outgoing

Populating a spring request scoped bean in a ContainerRequestFilter

China☆狼群 提交于 2021-01-26 19:39:16
问题 I wrote a rest service using jersey 1.13 and spring 3.1.1 which runs on tomcat 6. In tomcat I'm using a realm which will do the authentication. In my application I need the current user but I don't want to access the SecurityContext from jersey in every resource. I want to inject a request scoped ApplicationConfig object in my rest resources which will contain the current user. Later I can extend this class to contain more request level configuration parameteters. This seems a nice

Populating a spring request scoped bean in a ContainerRequestFilter

一笑奈何 提交于 2021-01-26 19:35:14
问题 I wrote a rest service using jersey 1.13 and spring 3.1.1 which runs on tomcat 6. In tomcat I'm using a realm which will do the authentication. In my application I need the current user but I don't want to access the SecurityContext from jersey in every resource. I want to inject a request scoped ApplicationConfig object in my rest resources which will contain the current user. Later I can extend this class to contain more request level configuration parameteters. This seems a nice

javax servlet filter vs jersey filter [duplicate]

落花浮王杯 提交于 2021-01-05 23:51:53
问题 This question already has an answer here : What is the difference between a Servlet filter and a Jersey filter? (1 answer) Closed yesterday . I'm planning on writing a servlet application (meant for deployment with OSGI) and use some filters for HTTP header pre-processing. While originally settled on the javax.servlet filter implementation, it occured to me that I actually don't know why/when one would choose to use that vs the Jersey ContainerRequestFilter. Granted the latter comes with some

javax servlet filter vs jersey filter [duplicate]

空扰寡人 提交于 2021-01-05 23:47:34
问题 This question already has an answer here : What is the difference between a Servlet filter and a Jersey filter? (1 answer) Closed yesterday . I'm planning on writing a servlet application (meant for deployment with OSGI) and use some filters for HTTP header pre-processing. While originally settled on the javax.servlet filter implementation, it occured to me that I actually don't know why/when one would choose to use that vs the Jersey ContainerRequestFilter. Granted the latter comes with some

Get Jersey to work with Optional parameters

有些话、适合烂在心里 提交于 2020-12-15 06:43:32
问题 I'm trying to get Jersey to work with Optional parameters. I have a very simple web service: @Path("helloworld") public static class HelloWorldResource { public static final String CLICHED_MESSAGE = "Hello World!"; @GET @Produces("text/plain") public String getHello(@QueryParam("maybe") Optional<String> maybe) { return CLICHED_MESSAGE; } } And a simple harness: public static void main(String[] arg) throws IOException { ResourceConfig config = new ResourceConfig(HelloWorldResource.class);

Get Jersey to work with Optional parameters

吃可爱长大的小学妹 提交于 2020-12-15 06:43:19
问题 I'm trying to get Jersey to work with Optional parameters. I have a very simple web service: @Path("helloworld") public static class HelloWorldResource { public static final String CLICHED_MESSAGE = "Hello World!"; @GET @Produces("text/plain") public String getHello(@QueryParam("maybe") Optional<String> maybe) { return CLICHED_MESSAGE; } } And a simple harness: public static void main(String[] arg) throws IOException { ResourceConfig config = new ResourceConfig(HelloWorldResource.class);