jersey-2.0

Catch all Exceptions and also return custom Errors in Jersey

喜你入骨 提交于 2019-12-17 09:41:19
问题 I want to catch all unexpected Exceptions in a jersey rest service. Therefore i wrote an ExceptionMapper: @Provider public class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<Exception> { private static Logger logger = LogManager.getLogManager().getLogger(ExceptionMapper.class.getName()); @Override public Response toResponse(Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Internal error").type("text

How to get JAXRS 2 (Jersey) verbose Trace to work with ResourceConfig

跟風遠走 提交于 2019-12-14 03:56:56
问题 I wish to output debugging logging for JAXRS like this (as per documentation)... 3 X-Jersey-Tracing-000: START [ ---- / ---- ms | ---- %] baseUri=[http://localhost:9998/ALL/] requestUri=[http://localhost:9998/ALL/root/sub-resource-locator/sub-resource-method] method=[POST] authScheme=[n/a] accept=[application/x-jersey-test] accept-encoding=n/a accept-charset=n/a accept-language=n/a content-type=[application/x-jersey-test] content-length=[11] 4 X-Jersey-Tracing-001: PRE-MATCH [ 0.01 / 0.68 ms

Enabling JSON using jersey and grizzly

允我心安 提交于 2019-12-14 03:46:49
问题 I am playing with Jersey hosted with Grizzly and want to be able to consume and produce JSON, however I am getting 500 from the server in get request and media type unsupported in POST my server code is org.glassfish.jersey.server.ResourceConfig rc = new ResourceConfig(); rc.packages("RestServer.controllers"); final Map<String, Object> initParams = new HashMap<String, Object>(); initParams.put("com.sun.jersey.config.property.packages", "rest"); initParams.put("com.sun.jersey.api.json

@Context injection not working in Jersey ContainerRequestFilter (Dropwizard)

ⅰ亾dé卋堺 提交于 2019-12-13 13:28:23
问题 @Context injection works with classes but not able to make it work with Objects. httpServletRequest in ContainerRequestFilter produces null pointer. Dropwizard Version:- 1.1.0 ContainerRequestFilter public class ApplicationIPAuthFilter implements ContainerRequestFilter { private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationIPAuthFilter.class); private HerculesRestAccessor restAccessor; private String applicationName; @Context private HttpServletRequest httpServletRequest;

Jersey: org.glassfish.jersey.server.mvc cannot be resolved

你离开我真会死。 提交于 2019-12-13 08:14:16
问题 I want to use Jersey MVC in my project. I've never used Jersey MVC before. I'm working in: Eclipse (Version: Neon.1a Release (4.6.1)) , using: Jersey 2.25.1 Apache Tomcat 7.0.76. Here's the example I'm trying to run: Hello.java MyApp.java NewFile.jsp I have downloaded jersey 2.25.1 from here and added all jar files in Here's how I call my web service: The underlined import line tells: So this is the problem I want to solve. Because I have not found any information related to this problem I

Jersey reading nested Multipart (multipart/mixed)

我只是一个虾纸丫 提交于 2019-12-13 06:48:56
问题 In Jersey I can send multipart/mixed data like this : MultiPart multipartWrapper = new MultiPart(MultiPartMediaTypes.MULTIPART_MIXED_TYPE); for (IMessageContainer msgCont : input.getMessages()) { MultiPart m = new MultiPart(MultiPartMediaTypes.MULTIPART_MIXED_TYPE) .bodyPart( new BodyPart(msgCont.getDescription(), MediaType.APPLICATION_JSON_TYPE)) .bodyPart( new BodyPart(msgCont.getDetails(), MediaType.APPLICATION_OCTET_STREAM_TYPE)); //nest the new multipart into a bodypart within the root

Jersey2: Navigating from a Resource to an instance

三世轮回 提交于 2019-12-13 05:51:17
问题 I am attempting to answer this question: What is the Jersey 2 replacement for ResourceContext.matchResource(URI)? I've managed to navigate from a ResourceModel to a matching Resource , but it's not clear how to instantiate the corresponding user class. Meaning, given org.glassfish.jersey.server.model.Resource that maps to some user-defined class CompaniesResource , how do I get a CompaniesResource instance out of the Resource ? The tricky part is that this needs to invoke subresource locators

Jetty web.xml 503

ぃ、小莉子 提交于 2019-12-13 05:03:27
问题 So I'm trying to set up Jetty for a school project, using Jersey on the server side and Gradle to build and run it. I have my web.xml and a test that I'm trying to hit with curl. Here's what I got: web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <servlet>

java ee: class not found despite valid import?!

为君一笑 提交于 2019-12-13 04:21:58
问题 I use jersey to create some sort of RESTful API. To get information about the current request, I use the HttpServletRequest Object. I am able to compile the project without problems or errors, but when I run it, I get the following error: [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ backend --- [WARNING] java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl

WELD-001408: Unsatisfied dependencies for type in GlassFish + Jersey 2

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:13:12
问题 I am trying to inject a class into my Jersey JAX-RS application using HK2, running on GlassFish. But when I try to run my application I get this error: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied