jersey

File upload with Jersey : FormDataContentDisposition is null

ε祈祈猫儿з 提交于 2019-12-06 01:39:57
问题 I'm trying to implement file upload with Jersey so I followed this example : http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/ which worked well with an HTML page. Now I adapted it to my application, here is code : public Response uploadFile( @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) throws IOException { Response.Status respStatus = Response.Status.OK; if (fileDetail == null) { respStatus =

Jersey: Pass value from ContainerRequestFilter to endpoint

北城以北 提交于 2019-12-06 01:20:21
I am using Jersey 2.9 and I have created a filter which will take an encrypted header value, and decipher it and then pass it along to the endpoint which was called on. I have no idea of how to do this, and I have been searching on the internet but not really found a concrete example of what I want to do. The filter is called, I just have issues passing a value from it to the endpoint. Could you guys help me! Here is some sample code: public class MyFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws WebApplicationException {

Custom annotation injection with Jersey 1.x

那年仲夏 提交于 2019-12-06 01:09:54
I am using jersey 1.9.1. I have rest method like following where Authorization header contained encoded credentials such as username and password and it is parsed in a method and mapped local values. @PUT @Path(SystemConstants.REST_MESSAGE_SENDSMS) @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON}) public Response sendSms(@HeaderParam("Authorization") String authorization, String param) { String[] credentials = ImosUtils.getUserCredentials(authorization); String username = credentials[0]; String password = credentials[1]; } I am trying to design a way to make this

Jersey-Guice doesn't process bound resources if injector is a child?

孤人 提交于 2019-12-06 00:14:17
I'm using Jersey-Guice to configure a Jersey app, following this template . Everything works fine if the Injector returned by the GuiceServletContextListener.getInjector() method is created by Guice.createInjector() . If that injector is instead the child of another injector, then the bound resources (e.g., MyResource in the code below) are never added to the Jersey ResourceConfig and Jersey crashes with a complaint about missing root resources. I don't think the bound resources are even scanned, because the usual "INFO: Registering my.example.MyResource as a root resource class" doesn't

老外写的关于协程的性能文章-主打http协议

99封情书 提交于 2019-12-06 00:11:25
https://dzone.com/articles/high-concurrency-http-clients-on-the-jvm HTTP is probably the most popular application-level protocol and there are many libraries that implement it on top of network I/O, which is a special (stream-oriented) case of general I/O. Since all I/O has a much in common, let’s start with some discussion about it. I’ll concentrate on I/O cases with a lots of concurrent HTTP requests, for example micro-services, where a set of higher-level HTTP services invoke several lower-level ones, some concurrently and some sequentially due to data dependencies. When serving many such

Jersey + Guice can't mix non-jersey resources with jersey resources

旧巷老猫 提交于 2019-12-05 23:34:06
How can I use non-jersey resources with jersey resources with guice ? I want "/" to be handled by a plain servlet. But I want "/users" handled by jersey. Say I have a jersey resource with @Path("/users"). Using the following bindings will not work, it tries to map the "/" request using jersey which of course is not a jersey resource and I get 404. protected void configureServlets() { serve("/").with(LoginServlet.class); serve("/*").with(GuiceContainer.class, params); } All of the examples of jersey / guice I can find do something like serve("/rest/*".with(GuiceContainer.class, params); which

Jersey JUnit Test: @WebListener ServletContextListener not invoked

泄露秘密 提交于 2019-12-05 23:11:00
I created this test in Jersey (from the docs ), which works fine, with one problem: the @WebListener ServletContextListener is not being invoked. The Resource classes that I need to test rely on an attribute set on the ServletContext by the ServletContextListener. Can I make sure it is invoked, or can I manipulate the ServletContext in some other way? public class SimpleTest extends JerseyTest { @WebListener public static class AppContextListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent event) { System.out.println("Context initialized");

Dropwizard and Protocol Buffers by example

霸气de小男生 提交于 2019-12-05 22:51:18
Please note: Although this question specifically mentions Dropwizard, I believe anyone with Jersey/JAX-RS experience should be able to answer this question, as I would imagine Dropwizard is just following Jersey/JAX-RS conventions under the hood. I have a Dropwizard service that reds/writes in JSON and works beautifully. I would like to now switch it to read/write binary data (to minimize network bandidth). I see there is the Dropwizard-Protobuf lib but I have a few concerns about implementing binary serialization in Dropwizard. First off, here's the important stuff from my current (JSON

Redirect Jersey JUL logging to Log4j2

人盡茶涼 提交于 2019-12-05 22:44:11
I need to redirect Jersey request/response log to my log4j2. I have Jersey logging enabled by using this code on my ApplicationJAXRS extends Application : @Override public Set<Class<?>> getClasses() { return new HashSet<Class<?>>() {{ add(LoggingFilter.class); }}; } It seems that Jersey uses JUL (Java Logging) internally and the default output is STDOUT. At this moment I can see the STDOUT on Eclipse Console. The Log4j2 documentation have a section about JDK Logging Adapter . It says To use the JDK Logging Adapter, you must set the system property java.util.logging.manager to org.apache

How to parse JSON array using Jersey Rest Webservices and Java

怎甘沉沦 提交于 2019-12-05 22:35:26
I am getting Json array from iOS client and want to parse the Json in server side using Java and jersey and Gson. I am sending the JSON array in POST method from iOS. I want to consume the json but stuck on how do i save the json data in Java class. This is the structure of my Json array { "friendList": [ {"id": 1, "username": "user1", "name":"person1", "friendUsername":"fUser1", "friendName":"fName1"}, {"id": 2, "username": "user2", "name":"person2", "friendUsername":"fUser2", "friendName":"fName2"}, {"id": 3, "username": "user3", "name":"person3", "friendUsername":"fUser3", "friendName":