jersey-2.0

calling flush() on Jersey StreamingOutput has no effect

…衆ロ難τιáo~ 提交于 2019-11-28 08:08:43
问题 I am using a Jersey StreamingOutput that was working just fine until we upgraded to Jersey 2.16. Here's the thing. My StreamingOuput produces output very slowly in some circumstances. I do write data regularly, but I write it pretty slowly and just a little of it at a time. I call flush() on the OutputStream passed to StreamingOutput.write() every time I write any bytes, but the flush() appears to have no effect. Nothing is sent over the wire until 8K has been written to the OutputStream .

Do we still need JacksonFeature.class for Jersey 2.17 projects?

不问归期 提交于 2019-11-28 07:26:32
问题 I have been trying to know if JacksonFeature.class is still needed for Jersey 2.17. I can't see any difference between the outputs between codes that JacksonFeature.class is registered or not. Then, I forked a code from codingpedia codingpedia, removed JacksonFeature.class, upgraded to Spring 4.1.2 and jersey 2.17, updated the codes and the test still passed. So I created a very simple web service to test this again github link, having in mind to remove all the moving parts and still worked.

Unable to Mock Glassfish Jersey Client response object

♀尐吖头ヾ 提交于 2019-11-28 07:22:35
问题 I am having problems with creating a mock Response object to use with my unit tests. I am using org.glassfish.jersey.core.jersey-client version 2.3.1 to implement my RESTful client and mockito version 1.9.5 to help me with mock objects. Here is my test's code: @Test public void testGetAll() throws IOException { // Given String expectedResource = "expectedResource" final Response expectedRes = Response.ok(expectedResource, MediaType.APPLICATION_JSON).build(); String receivedResource;

jersey 2 context injection based upon HttpRequest without singleton

╄→гoц情女王★ 提交于 2019-11-28 06:27:03
问题 I want to inject a Datastore for a single request by field, like @Context protected HttpServletRequest request; Currently I have implemented a similar approach to this: Jersey 2.x Custom Injection Annotation With Attributes as follows: @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER, ElementType.FIELD}) public @interface TenantDatastore {} public class TenantDatastoreFactory extends AbstractContainerRequestValueFactory<Datastore> { public TenantDatastoreFactory() {}

Is java Jersey 2.1 client thread safe?

人走茶凉 提交于 2019-11-28 06:16:57
Documentation for jersey 2.0 says : Client instances are expensive resources. It is recommended a configured instance is reused for the creation of Web resources. The creation of Web resources, the building of requests and receiving of responses are guaranteed to be thread safe. Thus a Client instance and WebResource instances may be shared between multiple threads Is client still thread-safe in version 2.1? I cannot find information about thread safety in docs for 2.1. Yes, the Jersey 2.1 client is thread safe and it should be thread safe even in the future Jersey version. You can create many

Jersey 2.0 equivalent to POJOMappingFeature

风格不统一 提交于 2019-11-28 06:15:42
I have some experience using Jersey < 2.0. Now I am trying to build a war application to provide a JSON Webservice API. I am now struggling for a considerable amount of time trying to configure Moxy and it seams to be way more complicated than what was adding <init-param> <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> <param-value>true</param-value> </init-param> to your web.xml back in Jersey < 2.0. Is there some possibility to just say "please add json support"? Currently I just get a lot of Internal Server Error errors without any log entries on the server and just

Is it correct to return 404 when a REST resource is not found?

假如想象 提交于 2019-11-28 04:22:01
Let's say I have a simple Jersey REST resource as follows: @Path("/foos") public class MyRestlet extends BaseRestlet { @GET @Path("/{fooId}") @Produces(MediaType.APPLICATION_XML) public Response getFoo(@PathParam("fooId") final String fooId) throws IOException, ParseException { final Foo foo = fooService.getFoo(fooId); if (foo != null) { return Response.status(Response.Status.OK).entity(foo).build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } } Based on the code above, is it correct to return a NOT_FOUND status ( 404 ), or should I be returning 204 , or some other

Introspecting Jersey resource model Jersey 2.x

て烟熏妆下的殇ゞ 提交于 2019-11-28 01:05:44
问题 I have written my own scanner to go through my JAX-RS resources and print out the method names and paths using jersey-server-1.18.1 . The problem is when I migrate my same code to 2.16 (changing the package names from com.sun.* to org.glassfish.* ), It just won't work. Digging deep I found that those required jersey-server classes are no long public. Anyone knows the reason why? And how can I migrate my code below from 1.x to 2.x ? There is literally no documentation on this migration. All

Server Sent Event Client with additional Cookie

人盡茶涼 提交于 2019-11-28 00:11:18
问题 I am trying to unit test a Server Sent Event resource with an additional cookie. I am already using Jersey for the EventSource and JavaX for the client. The following code works fine: WebTarget target = ClientBuilder.newBuilder() .register(SseFeature.class) .build() .target("http://localhost:8080/sse"); EventSource eventSource = EventSource.target(target).build(); EventListener listener = new EventListener() { @Override public void onEvent(InboundEvent inboundEvent) { LOG.info(inboundEvent

how to send json object from REST client using javax.ws.rs.client.WebTarget

天涯浪子 提交于 2019-11-27 21:58:35
I have a POJO given below which I want to PUT to the server as JSON or XML. This is what I have done CLIENT: ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); WebTarget target = client.target(getBaseURI()); public void putFriend(String uri , Friend friend) { System.out.println(friend.toString()); target = target.path(some_path).path(uri); ClientResponse response = target.request(MediaType.APPLICATION_JSON).put(Entity.entity(friend,MediaType.APPLICATION_JSON),ClientResponse.class); } Examples I found on web were using WebResource. I don't know how to do