jersey

Non-resolvable import POM: Could not transfer artifact

给你一囗甜甜゛ 提交于 2020-01-02 07:07:07
问题 This my pom.xml and the errors I get are: Non-resolvable import POM: Could not transfer artifact org.glassfish.jersey:jersey-bom:pom:2.9 from/to central (http://repo.maven.apache.org/maven2): repo.maven.apache.org @ line 14, column 25: Unknown host repo.maven.apache.org and 'dependencies.dependency.version' for org.glassfish.jersey.containers:jersey-container-grizzly2-http:jar is missing. @ line 25, column 21 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001

How to implement jaxrs Application without web.xml [duplicate]

此生再无相见时 提交于 2020-01-02 06:18:29
问题 This question already has answers here : How to set up JAX-RS Application using annotations only (no web.xml)? (6 answers) Closed 6 years ago . I am trying to deploy a really simple jaxrs application with without a web.xml config and cannot get it working. My URL I'd expect to access is serverandport/{appname}/rest/welcomes/hello and I think I must be missing something dead obvious. Application @ApplicationPath("/rest") public class EngineApp extends Application { @Override public Set<Class<?

Jersey RESTful Web服务

北城以北 提交于 2020-01-02 04:10:20
Jersey是一个RESTFUL请求服务JAVA框架,与常规的JAVA编程使用的struts框架类似,它主要用于处理业务逻辑层。与Struts类似,它同样可以和hibernate,spring框架整合。 由于Struts2+hibernate+spring整合在市场的占有率太高,所以很少一部分人去关注Jersey。所以网上有关于Jersey的介绍很少。但是它确实是一个非常不错的框架。对于请求式服务,对于GET,DELETE请求,你甚至只需要给出一个URI即可完成操作。 举个简单的例子:如果你想获得服务器数据库中的所有数据;那么你可以在浏览器或者利用Ajax的GET方法,将路径设置好;例如:localhost:8080/Student (项目名称) /studentinfo (项目服务总体前缀) /student( 处理student对象的签注 )/getStudentInfo( 最后前缀 )。这样就可以获取所有学生信息。你可以选择GET获取的数据的返回类型:JSON,XML,TEXT_HTML(String)..获取之后,你可以通过JS将这些数据塞到html或者jsp页面上。 下面是详解: web.xml的设置: <!--定义Jersey的拦截器 -->   <servlet>   <servlet-name>JerseyServlet</servlet-name>   

Authorization with RolesAllowedDynamicFeature and Jersey

冷暖自知 提交于 2020-01-02 02:38:10
问题 I'm trying to authenticate users with a JAX-RS filter what seems to work so far. This is the filter where I'm setting a new SecurityContext: @Provider public class AuthenticationFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext requestContext) throws IOException { requestContext.setSecurityContext(new SecurityContext() { @Override public Principal getUserPrincipal() { return new Principal() { @Override public String getName() { return "Joe";

Jersey/JAX-RS : Return Content-Length in response header instead of chunked transfer encoding

淺唱寂寞╮ 提交于 2020-01-02 01:45:27
问题 I'm using Jersey to create RESTful API resources, and ResponseBuilder to generate the response. Example code for the RESTful resource: public class infoResource{ @GET @Path("service/{id}") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getCompany(@PathParam("id")String id) { //company is just a POJO. Company company = getCompany(id); return Response.status(200).entity(company).build(); } } In the response, it's returning chunked transfer encoding in the

What is the Jersey 2 replacement for ResourceContext.matchResource(URI)?

强颜欢笑 提交于 2020-01-02 01:14:08
问题 How do I find out what Resource an arbitrary URI maps to under Jersey 2.0? Under Jersey 1.x I'd use ResourceContext.matchResource(URI). What I'm trying to do : I'm trying to process an incoming request that references another resource by URI. For example, here is an operation that links a user to a department. POST /departments/5 { "user": "http://example.com/users/10" } POST /departments/5 resolves to: class DepartmentResource { @POST void linkUser() { ... } } In order to honor this request,

Jersey: JSON and StringMessageProvider clash, application/json methods generate invalid JSON

为君一笑 提交于 2020-01-01 19:33:42
问题 I have a jax-rs web services on jetty+jersey and tried different JSON message providers (e.g. Jackson and Gson). With all of them POJO <-> JSON works just fine but methods like this: @GET @Path("test") @Produces(MediaType.APPLICATION_JSON) public String test() { return "This string should be \"quoted\" by message writer"; } produce string This string should be "quoted" by message writer which is of course not a valid JSON and causes browser's ajax calls to fail. I expect it to be "This string

Is it possible to use dagger2 with jersey the same way it is possible with guice?

半世苍凉 提交于 2020-01-01 19:02:12
问题 Is it possible to use dagger2 with jersey the same way it is possible with guice? Is there any dagger2 servlet or dagger2 jersey project? 回答1: So, short answer is no, there is not a great way to do this while getting all of the features of Jersey in your application. However, there are ways to partially do this. You can simply register your resource in an application servlet ( see an example of that here https://github.com/cogman/gluews/blob/master/src/main/java/com/cogman/glue

How do I set Content-Length when returning large objects in Jersey JAX-RS server

喜欢而已 提交于 2020-01-01 12:04:19
问题 I sometimes want to return a large (several MB) binary object as a response from a JAX-RS resource method. I know the size of the object, and I want the Content-Length header to be set on the response, and I don't want chunked transfer encoding to be used. In Jersey 1.x, I solved this with a custom MessageBodyWriter: public class Blob { public InputStream stream; public long length; } @Provider public class BlobWriter extends MessageBodyWriter<Blob> { public boolean isWriteable(Class<?> type,

Jersey problems with Maven - Shade Plugin

喜你入骨 提交于 2020-01-01 10:04:22
问题 My problem is very similar to: Jersey exception only thrown when depencencies assembled into a single jar I run my application (jetty embedded + jersey) and everything works. When i try to create a executable JAR i get the error: org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo GRAVE: MessageBodyWriter not found for media type=application/json, type=class My POM.XML: <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>