jax-rs

Jersey 2.7 - setting retry handler

我与影子孤独终老i 提交于 2019-12-21 05:02:31
问题 I would like to set a retry handler for Jersey client utilizing ApacheConnector . I wish to do it, because I want it to retry on timeout (my HAProxy will switch it to another server). I have no clue how to do this in Jersey 2.7 . Example code: public static void Example() { ClientConfig clientConfig = new ClientConfig(); clientConfig.connectorProvider(new ApacheConnectorProvider()); clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager());

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

Jax-rs automatic decode pathparam

一个人想着一个人 提交于 2019-12-21 03:42:36
问题 I have a jax-rs service which receives a set of parameters in the path, pathparameters. These parameters may be strings containing values not suitable for urls, so they are urlencoded on the client side using the java.net.UrlEncoder like so: String param = URLEncoder.encode(o.toString(), "UTF-8"); This is used to build the url supplier/group/param1/param2/param3 . If one of these are changed due to the urlencoding, for instance if it is only a space, the string received on the service is a +

AngularJS Client, JAX-RS Jersey Rest Service - application/json client request throwing 'Error parsing media type'

。_饼干妹妹 提交于 2019-12-21 02:55:22
问题 I am using the below AngularJS client code to perform a HTTP post request with JSON formatted payload to the jersey rest service patientMgmtModule.controller('NewPatientCtrl', function NewPatientCtrl($scope, $http) { $scope.addPatient = function (){ var patientJSON = angular.toJson($scope.Patient); console.log("Patient (JSON) is ============> " + patientJSON); $http({ method: 'POST', data: $scope.Patient, url:'/ManagePatient/AddPatient', headers: {'Content-Type':'application/x-www-form

Closing JAX-RS StreamingOutput's OutputStream

…衆ロ難τιáo~ 提交于 2019-12-20 19:41:32
问题 Should the StreamingOutput 's OutputStream be closed by the implementing class? The java-doc does not give any recommendations. I guess it just delegates to the underlying ServletOutputStream which means it should not be closed, but my guess might be wrong :) Also the javadoc makes a reference to the MessageBodyWriter interface where it's explicitly said that the output stream must not be closed. https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/StreamingOutput.html 回答1: Being unable to

What is the best way to write a test case for JERSEY web services?

混江龙づ霸主 提交于 2019-12-20 18:36:03
问题 I have a JAX-RS web service implemented with Jersey library and now I want to test it. In order to do that I'd like to host this service in my test by preinitializing it with mocked services. What is the best way to host such a service and execute the test calls? @Path("/srv") public class MyService { @GET public void action(@Context UriInfo uri) { ... } } @Test public void myTest() { MyService service = new MyService(); service.setSomething(...); // How do I host it? // How do I call it? }

Is JAX-RS Client Thread Safe

試著忘記壹切 提交于 2019-12-20 18:00:47
问题 In Java EE7, the JAX-RS Client API provides a high-level API for accessing any REST resources. According to the documentation, "Clients are heavy-weight objects that manage the client-side communication infrastructure. Initialization as well as disposal of a Client instance may be a rather expensive operation. It is therefore advised to construct only a small number of Client instances in the application. " In order to avoid create client frequently, I am going to cache the client instance

Using Java-generics template type in RESTful Response object via GenericEntity<List<T>>

拜拜、爱过 提交于 2019-12-20 10:33:29
问题 I have a generic JAX-RS resource class and I have defined a generic findAll method public abstract class GenericDataResource<T extends GenericModel> { @GET @Produces(MediaType.APPLICATION_JSON) public Response findAll() { Query query = em.createNamedQuery(modelClass.getSimpleName()+".findAll"); List<T> list = query.getResultList(); return Response.ok(new GenericEntity<List<T>>(list) {}).build(); } } and User class: public class User extends GenericModel { ... } And here is example subclass

Jersey/JAX-RS: Return a Map as XML/JSON

倾然丶 夕夏残阳落幕 提交于 2019-12-20 10:26:55
问题 It's not so obvious how to return a Map as an XML/JSON document using the Jersey/JAX-RS framework. It already has support for List s, but when it comes to Map s, there is no MessageBodyWriter . And even if I were to embed the Ma into a wrapper class, there is no map type in XML schema. Any practical advice on how to marshal a Map into an XML/JSON document in Jersey? 回答1: I know its very late to reply, but I'm hoping it will help somebody someday :) The easiest and quickest fix I applied is

Jersey/JAX-RS: Return a Map as XML/JSON

落爺英雄遲暮 提交于 2019-12-20 10:26:24
问题 It's not so obvious how to return a Map as an XML/JSON document using the Jersey/JAX-RS framework. It already has support for List s, but when it comes to Map s, there is no MessageBodyWriter . And even if I were to embed the Ma into a wrapper class, there is no map type in XML schema. Any practical advice on how to marshal a Map into an XML/JSON document in Jersey? 回答1: I know its very late to reply, but I'm hoping it will help somebody someday :) The easiest and quickest fix I applied is