jersey

How do I get the URL of a request?

青春壹個敷衍的年華 提交于 2019-12-21 07:22:02
问题 I am using Jeresy Jax-RS to build a web service. Now I need to get the url of the request with the port # if one exist. So if my service runs on http://www.somelocation.com/web/services I want to capture the www.somelocation.com How can I do this ? 回答1: You can add a UriInfo parameter to your operation. From there you can access the URL: @POST @Consumes({"application/xml", "application/json"}) public Response create(@Context UriInfo uriInfo, Customer customer) { ... } 来源: https:/

Register ServletContainer programmatically in Osgi

回眸只為那壹抹淺笑 提交于 2019-12-21 05:14:20
问题 I'm developing a JAX-RS application with OSGI where resources are loaded dynamically. For this, I need to register the ServletContainer programmatically, then I can call the method ServletContainer.reload (ResourceConfig). I'm running on OSGI environment with support for servlet 3.x, using PAX-WEB 3.0.2 and Jersey 2.4. The problem is when I want to access a resource that implements Server Sent Event, Jersey raises an error that does not support asynchrony because it runs in a Servlet 2.x.

Adding Oauth 2.0 to Jersey based RESTful server

一个人想着一个人 提交于 2019-12-21 05:08:17
问题 I have a Jersey based server that I want to secure with OAuth 2.0 . There are two paths that I've seen as common: Oltu - Is compatible with Jersey and seems to be supported, although not as well as Spring Security. This 2012 question seems to suggest this is the way to go, but I want confirmation on a 2016 context so I son't implement something not as well supported anymore. Spring Security - It seems to be very popular, but this path implies changing the server into a Spring based MVC. I don

How can I inject a data source dependency into a RESTful web service with Jersey (Test Framework)?

不问归期 提交于 2019-12-21 04:30:38
问题 I'm building a RESTful web service using Jersey that relies on MongoDB for persistence. The web service itself connects to the default database, but for the unit tests, I would like to use a separate test database. I would populate this test database in setUp, run my tests, and then destroy it in tearDown. Normally, I would use dependency injection here to supply the data source to an entity manager that the service would use, but in this case the web service is running independent of the

JUL Adapter not working for Jersey

▼魔方 西西 提交于 2019-12-21 04:22:05
问题 I am trying to use JUL Adapter to delegate Java Util Logging to Log4j2. More precisely, any third-party library that use JUL to generate logs, should be delegated to Log4j2. As a simple exercise, I created a standalone application that uses a library (I created this library for testing purposes, it generates logs using JUL) to test the JUL Adapter . When I change the log manager as described here I can see the effects. And it works fine. Hers's the code: import org.apache.logging.log4j

Generating Rest API documentation using swagger or any other tool

孤街浪徒 提交于 2019-12-21 04:12:28
问题 I am looking for a way to document my Rest APIs. My server is a Tomcat/Spring server and the Rest APIs are implemented using Jenkins. Swagger seems to be a pretty cool solution but i can't figure out how i can use it with my code. I am looking for the best way to create the json swagger-ui can read - how i should do that? Also, i would be happy to check any other good solutions for documenting Rest APIs in such environment. 回答1: I haven't tried swagger but you may try enunciate. It can

ExceptionMapper for WebApplicationExceptions thrown with entity?

ε祈祈猫儿з 提交于 2019-12-21 04:03:00
问题 In our (legacy) codebase, we're throwing WebApplicationExceptions in different ways. In an attempt to make some order in how we're handling exceptions - I wanted to create an ExceptionMapper for these WAEs (and others). I realized, however, that Jersey's ExceptionMapper only maps WAE which weren't thrown with an entity. For example: throw new WebApplicationException(Response.status(500).build()); This exception is caught by the ExceptionMapper. throw new WebApplicationException(Response

Jersey (JSR311-Implementation) & Redirections

▼魔方 西西 提交于 2019-12-21 04:02:50
问题 Is there a way to redirect the user-agent in a Jersey Resource? In Spring MVC there's the "redirect:"-syntax but I didn't find anything comparable in Jersey's Viewable class. The only method I found working was using HttpServletResponse.sendRedirect() . 回答1: You have to return a Response object containing your status code and Location -header. The easiest way is to use javax.ws.rs.core.Response.temporaryRedirect(URI) . When using Viewable you might need to throw a WebApplicationException

Jersey ClientBuilder.newClient(): source not found

若如初见. 提交于 2019-12-21 03:42:30
问题 I have an Java 64-bit Eclipse application with Eclipse running on Windows 7 Pro x64. I downloaded the Jersey bundle, jaxrs-ri-2.7.zip, for client RESTful API access. I added these external jars (Project | Build Path | Configure Build Path... | Libraries): jaxrs-ri/api/javax.ws.rs-api-2.0.jar jaxrs-ri/lib/jersey-client.jar jaxrs-ri/lib/jersey-common.jar Here is the source: package prjTestJersey; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; public static void main

Send File as a parameter to a REST Service, from a client?

雨燕双飞 提交于 2019-12-21 02:44:08
问题 My Requirement is to send the file to the REST Service through one client. That service is going to process the file. I am using Jersey API for implementing this. But I have searched in many articles, there is no any information of how to pass the file from client side and how the REST service will retrieve the file ... How to achieve this? And I am not using the Servlets for Creating REST Service. 回答1: Assuming you are using Jersey on both the client and server side, here is some code that