jersey-2.0

Server Side Event not firing in Jersey 2.8 using SSE

大兔子大兔子 提交于 2019-12-01 22:17:34
问题 I am trying with a sample example given in the official documentation of Jersey SSE Refer " 14.5.2. Asynchronous SSE processing with EventSource " in the below link https://jersey.github.io/documentation/2.8/user-guide.html#example-simple-sse My Code is as below Client code - public class ClientSSEEventManager { public void WaitForEvents() { // Client client = ClientBuilder.newBuilder() // .register(SseFeature.class).build(); // WebTarget target = // client.target("http://localhost:8080

Java Restful Service eclipse tomcat HTTP Error 404

帅比萌擦擦* 提交于 2019-12-01 22:00:29
i try to keep up with a java rest service. So i found some tutorials, which explain always the same way. But i cant get this running :(. I made Dynamic Web Project in Version 2.5 and Tomcat 7.0 in eclipse. Then i load following jars to WEB-INF/lib My Projectname is com.freespots.rest. I created following web.xml Ok now iam going to create the java-class right? Well i did it Java Resources/src/com.freespots.rest.service: If i start Tomcat and type url to my browser like localhost:8080/com.freespots.rest the Tomcat shows my index.html file. But if i go to url localhost:8080/com.freespots.rest

Limit path media type mappings in Jersey

你说的曾经没有我的故事 提交于 2019-12-01 21:45:39
I have configured MEDIA_TYPE_MAPPINGS for my Jersey apps. Unfortunately, this causes some trouble with a generic upload service in my app. @PUT @Path("files/{filename}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response uploadFile( @PathParam("filename") @NotNull @Size(max = 240) String filename, DataSource dataSource) If someone uploads .../files/file.xml the extension is chopped of. Is there a way to tell Jersey to skip that filtering for this resource? Edit : After peeskillet's answer, my assumption was confirmed. I have filed an improvement request: https

Uploading and downloading images with Jersey + hibernate RESTful web service

ⅰ亾dé卋堺 提交于 2019-12-01 20:15:30
I decided to go store the image as a byte array in the database. I'm getting an error. My entity model (with getters and setters): @Entity @Table(name="USER", schema="test") @XmlRootElement public class User { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) @Column(name="user_id") private long userId; @Lob @Column(name="profile_photo") private byte[] profilePhoto; public User() { } } Then I have a resource to create a user like below: @Path("/users") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public class UserResource { private UserService userService =

Jersey 2.x Security context does not work?

偶尔善良 提交于 2019-12-01 19:30:57
While i am trying to create java jersey application authentication roles does not work for me. Java code :- package org.student.resource; import javax.annotation.security.PermitAll; import javax.annotation.security.RolesAllowed; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.ext.Provider; @Path("/resource") @PermitAll public class Resource { @GET public String get(){ return "GET"; } @RolesAllowed("admin") @POST public String post(){ return "Post content."; } } Deployment descriptor :- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

NoClassDefFoundError ProcessingException while migrating from jersey 1.x to jersey 2.x ( 2.8 )

血红的双手。 提交于 2019-12-01 18:18:20
I developed a web service application which was working fine with jersey 1.x ( 1.16 ) I recently tried to migrate to latest stable jersey version 2.8 I deleted all jersey jar files of v1.16 then I downloaded jersey jars of v2.8 from the link - https://jersey.java.net/download.html As per documentation I came to know that, I should have latest servlet jar, servlet jar 2.5 or above, So I downloaded servlet-api-2.5.jar and added the same to /libs folder. I downloaded javax.ws.rs-api-2.0-m09.jar and added it to /libs I also added latest jettison v 1.3.3 to /libs But I am getting exception when I

Jersey client to download and save file

一笑奈何 提交于 2019-12-01 16:58:00
I Am new to jersey/JAX-RS implementation. Please find below my jersey client code to download file: Client client = Client.create(); WebResource wr = client.resource("http://localhost:7070/upload-0.0.1-SNAPSHOT/rest/files/download"); Builder wb=wr.accept("application/json,application/pdf,text/plain,image/jpeg,application/xml,application/vnd.ms-excel"); ClientResponse clientResponse= wr.get(ClientResponse.class); System.out.println(clientResponse.getStatus()); File res= clientResponse.getEntity(File.class); File downloadfile = new File("C://Data/test/downloaded/testnew.pdf"); res.renameTo

A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by“@Consumes” and “@Produces” annotations

谁说胖子不能爱 提交于 2019-12-01 16:54:17
How can the following produce this error when they have different URLs ? @Path("/job/{empId}/empProfile") public EmpProfileResource delegateToEventProfileResource() { EmpProfileResource resource = new EmpProfileResource(); locator.inject(resource); return resource; } @Path("/job/{empId}/empTask") public EmpTaskResource getClientLevelAttendees(@PathParam("clientId") long clientId){ EmpTaskResource resource = new EmpTaskResource (empId); locator.inject(resource); return resource; } @Path("/") public class EmpTaskResource{ } @Path("/") public class EmpProfileResource{ } Yes, they both are GET and

Jersey jax.rs client 2.5 follow redirect from HTTP to HTTPS

独自空忆成欢 提交于 2019-12-01 15:18:07
I have a setup where tomcat server hosting my REST servers redirects calls from HTTP (port 9080) to HTTPS ( port 9443 ). I'm using jersey 2.5 implementation and cannot manage to configure the clients to follow redirections. I've found this SO question( Jersey client doesn't follow redirects ), however it's provided for jersey 1.X series and the API has changed. I've tried to adapt it for 2.5 with the following test code : SSLContextProvider ssl = new TrustAllSSLContextImpl(); // just trust all certs Response response = ClientBuilder.newBuilder() .sslContext(ssl.getContext()).newClient()

Jersey client to download and save file

会有一股神秘感。 提交于 2019-12-01 15:08:02
问题 I Am new to jersey/JAX-RS implementation. Please find below my jersey client code to download file: Client client = Client.create(); WebResource wr = client.resource("http://localhost:7070/upload-0.0.1-SNAPSHOT/rest/files/download"); Builder wb=wr.accept("application/json,application/pdf,text/plain,image/jpeg,application/xml,application/vnd.ms-excel"); ClientResponse clientResponse= wr.get(ClientResponse.class); System.out.println(clientResponse.getStatus()); File res= clientResponse