jersey

Using Spring and Jersey together

。_饼干妹妹 提交于 2021-01-29 18:42:17
问题 I want to create a small standalone RESTful API web-app which I can deploy. I want to use Spring for dependency injection and Jersey for the RESTful stuff. Is this something that can be done? Or should I be using whatever RESTful features that Spring uses? If using both Spring and Jersey together makes sense, how do I combine them? What does my web.xml need to have in it? 回答1: integration is quite easy. you can find a lot tutorial on net. see example here 回答2: Well I just worked on the same

Jersey JAX-RS application returns 404

≡放荡痞女 提交于 2021-01-29 11:47:42
问题 Everytime I run the application on server and enter the url I don't get any response. It says the following (image): Java code is as follows: package application; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.Path; import javax.ws.rs.core.Application; import javax.ws.rs.ApplicationPath; @Path("demo") public class FRITZ { @GET @Produces

Form data to rest PUT method in java

安稳与你 提交于 2021-01-29 09:01:34
问题 I am beginner for Java and REST API. I have a problem passing form data from HTML to rest PUT method. When I google about this, most solutions available are for POST method, that recommended to use FormParam . In my case, it shows below error: The method received in the request-line is known by the origin server but not supported by the target resource. Even I use PathParam , same error is returned: The method received in the request-line is known by the origin server but not supported by the

Spring Cloud Contract with Jersey

爷,独闯天下 提交于 2021-01-29 03:30:02
问题 I have a simple project Spring boot project. It contains one Jersey based Controller: @Path("persons") @Produces(MediaType.APPLICATION_JSON) public class PersonsController { @GET public Person get() { return new Person("James", 20); } } It returns json response as expected (url: http://localhost:PORT/persons): { "name": "James", "age": 20 } My aim is to add Spring Cloud Contract tests for this controller. I have added all required mvn configurations, and test: public class MvcTest { @Before

Jersey error when trying to suspend a connection of an asynchronous request

こ雲淡風輕ζ 提交于 2021-01-28 11:58:00
问题 Im doing a small test on suspending a asynch request using jersey but im getting an error. Let me show you what im trying to do and by the way the server is up and running just this request is failing: Path("/json/metallica") public class JSONService { @GET @Path("/test") @Produces(MediaType.APPLICATION_JSON) public void getAsynchHealthyTracks(@Suspended AsyncResponse asyncResponse){ HealthService.getInstance().getHealththyTracks(asyncResponse); } } when i call this from my local host on

How to make post ajax call with JSON data to Jersey rest service?

你离开我真会死。 提交于 2021-01-28 07:00:30
问题 I have been through this link. but this did not helped me out. I am using jersey lib v1.17.1. My jersey rest service: @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) @Path("/post1") public ResponseBean post1(@QueryParam("param1")String param1) { return ResponseFactory.createResponse(param1, "TEST", "TEST", null, true); } url is: /test/post1 My ajax call: var d = {"param1":"just a dummy data"}; $.ajax({ type : "POST", url : "http://localhost:7070/scl/rs

Getting HttpServletRequest.getParts() to work with jersey

别说谁变了你拦得住时间么 提交于 2021-01-28 05:21:09
问题 I have @MultipartConfig(location="/tmp", fileSizeThreshold=1048576, maxFileSize=20848820, maxRequestSize=418018841) @Path("/helloworld") public class HelloWorld extends HttpServlet { @POST @Consumes(MediaType.MULTIPART_FORM_DATA) //@Consumes() @Produces("text/plain") public void doPost(@Context HttpServletRequest httpRequest) { System.out.println("pinged"); //... } } and I want to access the parts and get the files. But when I do httpRequest.getPart("token") I get java.lang

Java rest webservice display name

时间秒杀一切 提交于 2021-01-28 02:01:33
问题 I've just started building my own rest webservice and I started off by going through this excellent tutorial: http://www.vogella.com/articles/REST/article.html#first_project However there is something that I don't quite understand. It has to do with the path to the service. The path is now this for the hello resource: http://localhost:8080/de.vogella.jersey.first/rest/hello This is default from the tutorial. However i would like to change this to a more convenient link, for example like this:

How to put and get UTF-8 string from HTTP header with jersey?

社会主义新天地 提交于 2021-01-27 18:09:43
问题 I have a problem that I was asked to put some of the parameters into HTTP header of the request. The web server (with jersey 1.17) will parse the parameters from the header fields. However, the values of the parameters should be formed by UTF-8. Is it possible to put an UTF-8 string in the HTTP header? If it is possible, how can I simulate it using rest client (such as RESTClient in Firefox plugin)? I have tried to search for this question by google, and a question (What character encoding

Validating path to nested resource

不打扰是莪最后的温柔 提交于 2021-01-27 14:37:35
问题 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(