grizzly

jersey + grizzly + hk2: Dependency injection, but not into resource

时间秒杀一切 提交于 2019-12-01 03:13:33
问题 Following up on Jersey + HK2 + Grizzly: Proper way to inject EntityManager?, I would like to understand how it is possible use dependency injection in classes which are not jersey resources . As an example, I might have background tasks running in an ExecutorService, and they might need an EntityManager. If I attempt to @Inject the EntityManager into the class, nothing happens. Injecting it into a @Path -annotated jersey resource class, injecting works fine. The application is running as a

Bean Validation 400 errors are returning default error page (html) instead of Response entity (json)

自作多情 提交于 2019-11-30 22:30:38
I have a JUnit testsuite: GrizzlyHttpServerFactory + Jersey + Bean Validation (jersey-container-grizzly2-servlet/jersey-bean-validation ver 2.12, grizzly-http-server ver 2.3.16, hibernate-validator ver 5.0.0.Final) The 400 errors generated by a ValidationException are returning Grizzly's default error page (html) instead of the Bean Validation's Response entity (json). I've tried a ClientResponseFilter and its entityStream also contains the html error page. When I run the system under Tomcat, the ValidationExceptions return a Response with a json-formatted entity. Any ideas on how to configure

Grizzly - java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName

两盒软妹~` 提交于 2019-11-30 20:40:42
I have a wsdl file for the Web service. I want to test the interaction between the client and the server. To do this, I run the mock server with embedded grizzly. The question about of implementing mock server. I generated an interface from wsdl (and xsd) using the wsimport and wrote implementation. When run on the grizzly, I get the following error: com.sun.xml.ws.server.ServerRtException: [failed to localize] cannot.load.wsdl(META-INF/wsdl/test.wsdl) I run a web service with this code: HttpHandler httpHandler = new JaxwsHandler(new TestImpl()); server.getServerConfiguration().addHttpHandler

Jersey + HK2 + Grizzly: Proper way to inject EntityManager?

混江龙づ霸主 提交于 2019-11-30 07:23:35
I've managed to set up injection (into resource classes) of my own service classes in Jersey, HK2 and a plain GrizzlyServer. (Basically followed this example .) I'm now curious what the best is to inject JPA EntityManagers into my resource classes? (I'm currently considering one request as one unit of work). One option that I'm currently exploring is to use a Factory<EntityManager> in the following way: class MyEntityManagerFactory implements Factory<EntityManager> { EntityManagerFactory emf; public MyEntityManagerFactory() { emf = Persistence.createEntityManagerFactory("manager1"); }

Swagger documentation with JAX-RS Jersey 2 and Grizzly

回眸只為那壹抹淺笑 提交于 2019-11-30 05:50:22
问题 I have implementated a Rest web service (the function is not relevant) using JAX-RS. Now I want to generate its documentation using Swagger. I have followed these steps: 1) In build.gradle I get all the dependencies I need: compile 'org.glassfish.jersey.media:jersey-media-moxy:2.13' 2) I documentate my code with Swagger annotations 3) I hook up Swagger in my Application subclass: public class ApplicationConfig extends ResourceConfig { /** * Main constructor * @param addressBook a provided

grizzly http server should keep running

亡梦爱人 提交于 2019-11-30 05:06:15
Below is the code to start Grizzly Http Server. If I press any key the server stops. Is there any way to keep it alive. Jetty has join() method, which will not exit the main program. Is there anything similar to that in Grizzly also. public static void main(String args){ ResourceConfig rc = new PackagesResourceConfig("com.test.resources"); HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, rc); logger.info(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nTry out %shelloworld\nHit enter to stop it...", BASE_URI, BASE_URI)); System.in.read();

Grizzly - java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName

落花浮王杯 提交于 2019-11-30 04:52:35
问题 I have a wsdl file for the Web service. I want to test the interaction between the client and the server. To do this, I run the mock server with embedded grizzly. The question about of implementing mock server. I generated an interface from wsdl (and xsd) using the wsimport and wrote implementation. When run on the grizzly, I get the following error: com.sun.xml.ws.server.ServerRtException: [failed to localize] cannot.load.wsdl(META-INF/wsdl/test.wsdl) I run a web service with this code:

How can I get the stack trace when 500 server error happens in Jersey?

◇◆丶佛笑我妖孽 提交于 2019-11-29 17:45:54
When in jersey server I have server 500 error: In server response don´t have stack trace or some info. In Eclipse console don´t have exception stack trace I try to catch exception in server and print trace in console, but nothing happens How can I get the stack trace when 500 server error happens? Most of the time, a generic ExceptionMapper will do the trick. @Provider public class DebugMapper implements ExceptionMapper<Throwable> { @Override public Response toResponse(Throwable t) { t.printStackTrace() return Response.serverError() .entity(t.getMessage()) .build(); } } Then just register it

Using JaaS with Jersey on Grizzly

末鹿安然 提交于 2019-11-29 12:23:42
I'm trying to find a simple, flexible way to add JaaS authentication to REST. I found a post that I think leads me in the right direction (See StevenC's answer). It sounds like the servlet container is responsible for security, not the Jersey code itself. I like this idea, but need a little guidance on implementation. Grizzly is my servlet container and I want to configure it to use JaaS for authentication. For now, a simple username/password combination would be fine, and hard-coding the username/password pairs directly in code is fine. As long as it uses JaaS, we can refine those details

How to use jersey 2.0 guice on grizzly

倾然丶 夕夏残阳落幕 提交于 2019-11-29 10:48:57
I want to use Guice + Jersey 2.0 on Grizzly. According to this How to use guice-servlet with Jersey 2.0? discussion there is no direct Guice integration for Jersey2 at present but it can be achieved using HK2 as a bridge. I also checked the sample project in Github https://github.com/piersy/jersey2-guice-example-with-test . This project is implemented using Jetty. But my problem is to implement it in Grizzly. On Jetty it is used like this @Inject public MyApplication(ServiceLocator serviceLocator) { // Set package to look for resources in packages("example.jersey"); System.out.println(