[jira] [Commented] (CXF-8119) Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint
[ https://issues.apache.org/jira/browse/CXF-8119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16961919#comment-16961919 ] Marco Tenti commented on CXF-8119: -- Ty Redko . I don't want you to lose to much time on this issue, a valid workaround is to set the element @Context like property of the class and remove from the parameters of the method, like the following: {code:java} @Context private org.apache.cxf.jaxrs.ext.MessageContext messageContext; @Context private javax.ws.rs.core.Application application; //Provides access to metadata information on the JAX-RS application. @Context private javax.ws.rs.core.UriInfo uriInfo; //Provides access to application and request URI information. @Context private javax.ws.rs.core.Request request; //Provides access to the request used for the method. @Context private javax.ws.rs.core.HttpHeaders httpHeaders; //Provides access to the HTTP header information for the request. @Context private javax.ws.rs.core.SecurityContext securityContext; //Provides access to the security-related information for the request. @Context private javax.ws.rs.ext.Providers providers; //Provides runtime lookup of provider instances. @Context private javax.ws.rs.ext.ContextResolver contextResolver; @Context private javax.servlet.http.HttpServletRequest httpServletRequest ; @Context private javax.servlet.http.HttpServletResponse httpServletResponse; @Context private javax.servlet.ServletContext servletContext; @Context private javax.servlet.ServletConfig servletConfig; {code} CXF seem to inject this properties correctely so if we not find a solution i can use these. i will try anyway to found out a solution for the esposed problem. Greetings. > Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint > --- > > Key: CXF-8119 > URL: https://issues.apache.org/jira/browse/CXF-8119 > Project: CXF > Issue Type: Bug > Components: Bus, Core, JAX-RS, OSGi, Resources >Affects Versions: 3.2.7 >Reporter: Marco Tenti >Priority: Major > > I have a REST Service project build for a Red Hat Fuse. > it's a simple set up of a rest service with a "blueprint.xml" and the > "cxf:rsServer" and it's work just fine. > But i need to use the @Context annotation of javax.ws.rs and i ca't find a > way to inject dynamically the @Context on my java class. > A full project for test of the problem can be found here: > [bug-load-context-annotation-blueprint|https://github.com/p4535992/bug-load-context-annotation-blueprint] > My goal is to set the value of the field; > {code:java} > @javax.ws.rs.core.Context > public javax.ws.rs.core.HttpHeaders httpHeaders; > {code} > Another strange bug is if i call the method: > {code:java} > @GET > @Path("/ping") > @Produces(MediaType.APPLICATION_JSON) > @WebMethod(operationName = "ping") > @WebResult(name = "Response") > @ApiResponses(value = { > @ApiResponse(code = 200, message = "Success") , > @ApiResponse(code = 500, message = "Error") > } > ) > @ApiOperation( "Get operation with Response and @Default value") > public Response ping() { > logger.info("PING SIGNATURE SERVICE"); > return Response.ok().entity("PING SIGNATURE SERVICE").build(); > } > } > {code} > it's work just fine , but if i call this (i just add the @Context HttpHeaders > httpHeaders parameter on the method) : > {code:java} > @GET > @Path("/ping") > @Produces(MediaType.APPLICATION_JSON) > @WebMethod(operationName = "ping") > @WebResult(name = "Response") > @ApiResponses(value = > { @ApiResponse(code = 200, message = "Success") , @ApiResponse(code = 500, > message = "Error") } > ) > @ApiOperation( "Get operation with Response and @Default value") > public Response ping(@Context HttpHeaders httpHeaders) > { logger.info("PING SIGNATURE SERVICE"); return Response.ok().entity("PING > SIGNATURE SERVICE").build(); } > } > {code} > i get this error: > {code} > 415 Error: Unsupported Media Type > {code} > Teh documentation say something about the attribute "propagateContexts" to > true, but seem do nothing: > {code:} > uri="cxfrs:bean:myRestSereer?performInvocation=true&bindingStyle=SimpleConsumer&propagateContexts=true"/> > {code} > ANOTHER example i can't undestand, the first method is injected with succes, > the second give me the "415 Error: Unsupported Media Type": > {code:java} > /** >* THIS WORK >*/ > @GET > @Path("/getheader") > public Response getHeaderDetails( > @HeaderParam("User-Agent") String userAgent, >
[jira] [Comment Edited] (CXF-8119) Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint
[ https://issues.apache.org/jira/browse/CXF-8119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16961919#comment-16961919 ] Marco Tenti edited comment on CXF-8119 at 10/29/19 11:41 AM: - Ty Redko . I don't want you to lose to much time on this issue, a valid workaround is to set the element @Context like property of the class and remove from the parameters of the method, like the following: {code:java} @Context private org.apache.cxf.jaxrs.ext.MessageContext messageContext; @Context private javax.ws.rs.core.Application application; //Provides access to metadata information on the JAX-RS application. @Context private javax.ws.rs.core.UriInfo uriInfo; //Provides access to application and request URI information. @Context private javax.ws.rs.core.Request request; //Provides access to the request used for the method. @Context private javax.ws.rs.core.HttpHeaders httpHeaders; //Provides access to the HTTP header information for the request. @Context private javax.ws.rs.core.SecurityContext securityContext; //Provides access to the security-related information for the request. @Context private javax.ws.rs.ext.Providers providers; //Provides runtime lookup of provider instances. @Context private javax.ws.rs.ext.ContextResolver contextResolver; @Context private javax.servlet.http.HttpServletRequest httpServletRequest ; @Context private javax.servlet.http.HttpServletResponse httpServletResponse; @Context private javax.servlet.ServletContext servletContext; @Context private javax.servlet.ServletConfig servletConfig; {code} CXF seem to inject these properties correctely, so if we not find a solution i can use these. i will try anyway to found out a solution for the esposed problem. Greetings. was (Author: 4535992): Ty Redko . I don't want you to lose to much time on this issue, a valid workaround is to set the element @Context like property of the class and remove from the parameters of the method, like the following: {code:java} @Context private org.apache.cxf.jaxrs.ext.MessageContext messageContext; @Context private javax.ws.rs.core.Application application; //Provides access to metadata information on the JAX-RS application. @Context private javax.ws.rs.core.UriInfo uriInfo; //Provides access to application and request URI information. @Context private javax.ws.rs.core.Request request; //Provides access to the request used for the method. @Context private javax.ws.rs.core.HttpHeaders httpHeaders; //Provides access to the HTTP header information for the request. @Context private javax.ws.rs.core.SecurityContext securityContext; //Provides access to the security-related information for the request. @Context private javax.ws.rs.ext.Providers providers; //Provides runtime lookup of provider instances. @Context private javax.ws.rs.ext.ContextResolver contextResolver; @Context private javax.servlet.http.HttpServletRequest httpServletRequest ; @Context private javax.servlet.http.HttpServletResponse httpServletResponse; @Context private javax.servlet.ServletContext servletContext; @Context private javax.servlet.ServletConfig servletConfig; {code} CXF seem to inject this properties correctely so if we not find a solution i can use these. i will try anyway to found out a solution for the esposed problem. Greetings. > Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint > --- > > Key: CXF-8119 > URL: https://issues.apache.org/jira/browse/CXF-8119 > Project: CXF > Issue Type: Bug > Components: Bus, Core, JAX-RS, OSGi, Resources >Affects Versions: 3.2.7 >Reporter: Marco Tenti >Priority: Major > > I have a REST Service project build for a Red Hat Fuse. > it's a simple set up of a rest service with a "blueprint.xml" and the > "cxf:rsServer" and it's work just fine. > But i need to use the @Context annotation of javax.ws.rs and i ca't find a > way to inject dynamically the @Context on my java class. > A full project for test of the problem can be found here: > [bug-load-context-annotation-blueprint|https://github.com/p4535992/bug-load-context-annotation-blueprint] > My goal is to set the value of the field; > {code:java} > @javax.ws.rs.core.Context > public javax.ws.rs.core.HttpHeaders httpHeaders; > {code} > Another strange bug is if i call the method: > {code:java} > @GET > @Path("/ping") > @Produces(MediaType.APPLICATION_JSON) > @WebMethod(operationName = "ping") > @WebResult(name = "Response") > @ApiResponses(value =
[jira] [Commented] (CXF-8119) Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint
[ https://issues.apache.org/jira/browse/CXF-8119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16961951#comment-16961951 ] Andriy Redko commented on CXF-8119: --- Hi [~4535992], I actually had time to look at it but do not have a final working version just yet. So you approach is valid I think, but it will apply only to resources in your control. The case with OpenApi integration (https://issues.apache.org/jira/browse/CXF-8116), with its own resources, would still be problematic. There are 2 options I am exploring right now: - using Jetty (or a y other fronting HTTP server) and CXF with Camel transport [1] - using Jetty (or a y other fronting HTTP server) and forward to CXF endpoints My idea (not proven yet) is that in this both cases CXF would be doing all the job, including the contexts injections, etc, may be more than needed but at least it should work. [1] https://cxf.apache.org/docs/apache-camel-transport.html > Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint > --- > > Key: CXF-8119 > URL: https://issues.apache.org/jira/browse/CXF-8119 > Project: CXF > Issue Type: Bug > Components: Bus, Core, JAX-RS, OSGi, Resources >Affects Versions: 3.2.7 >Reporter: Marco Tenti >Priority: Major > > I have a REST Service project build for a Red Hat Fuse. > it's a simple set up of a rest service with a "blueprint.xml" and the > "cxf:rsServer" and it's work just fine. > But i need to use the @Context annotation of javax.ws.rs and i ca't find a > way to inject dynamically the @Context on my java class. > A full project for test of the problem can be found here: > [bug-load-context-annotation-blueprint|https://github.com/p4535992/bug-load-context-annotation-blueprint] > My goal is to set the value of the field; > {code:java} > @javax.ws.rs.core.Context > public javax.ws.rs.core.HttpHeaders httpHeaders; > {code} > Another strange bug is if i call the method: > {code:java} > @GET > @Path("/ping") > @Produces(MediaType.APPLICATION_JSON) > @WebMethod(operationName = "ping") > @WebResult(name = "Response") > @ApiResponses(value = { > @ApiResponse(code = 200, message = "Success") , > @ApiResponse(code = 500, message = "Error") > } > ) > @ApiOperation( "Get operation with Response and @Default value") > public Response ping() { > logger.info("PING SIGNATURE SERVICE"); > return Response.ok().entity("PING SIGNATURE SERVICE").build(); > } > } > {code} > it's work just fine , but if i call this (i just add the @Context HttpHeaders > httpHeaders parameter on the method) : > {code:java} > @GET > @Path("/ping") > @Produces(MediaType.APPLICATION_JSON) > @WebMethod(operationName = "ping") > @WebResult(name = "Response") > @ApiResponses(value = > { @ApiResponse(code = 200, message = "Success") , @ApiResponse(code = 500, > message = "Error") } > ) > @ApiOperation( "Get operation with Response and @Default value") > public Response ping(@Context HttpHeaders httpHeaders) > { logger.info("PING SIGNATURE SERVICE"); return Response.ok().entity("PING > SIGNATURE SERVICE").build(); } > } > {code} > i get this error: > {code} > 415 Error: Unsupported Media Type > {code} > Teh documentation say something about the attribute "propagateContexts" to > true, but seem do nothing: > {code:} > uri="cxfrs:bean:myRestSereer?performInvocation=true&bindingStyle=SimpleConsumer&propagateContexts=true"/> > {code} > ANOTHER example i can't undestand, the first method is injected with succes, > the second give me the "415 Error: Unsupported Media Type": > {code:java} > /** >* THIS WORK >*/ > @GET > @Path("/getheader") > public Response getHeaderDetails( > @HeaderParam("User-Agent") String userAgent, > @HeaderParam("Content-Type") String contentType, > @HeaderParam("Accept") String accept > ) { > String header = "User-Agent: " + userAgent + > "\nContent-Type: " + contentType + > "\nAccept: " + accept; > return Response.status(200).entity(header).build(); > } > /** >* THIS NOT WORK error "415 Error: Unsupported Media Type" >*/ > @GET > @Path("/getallheader") > public Response getAllHeader(@Context HttpHeaders httpHeaders) { > // local variables > StringBuffer stringBuffer = new StringBuffer(); > String headerValue = ""; > for(String header : httpHeaders.getRequestHeaders().keySet()) { > headerValue = > httpHea