[jira] [Commented] (CXF-8119) Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (CXF-8119) Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint

Colm O hEigeartaigh (Jira)

    [ https://issues.apache.org/jira/browse/CXF-8119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16940797#comment-16940797 ]

Marco Tenti commented on CXF-8119:
----------------------------------

I maybe found a "patch" solution, but i need help to finalize.
I'have tried to customize a cxf inteceptor to capture the value on the body of the message and try to set on the header of the message.
here a example of the interceptors


{code:java}
public class MessageChangeInterceptor extends AbstractPhaseInterceptor<Message> {

    public MessageChangeInterceptor() {
        super(Phase.PRE_STREAM);  
    }

    public MessageChangeInterceptor(String phase) {
    super(phase);
        }

        @Override
    public void handleMessage(Message message) throws Fault {
    try {    
    HttpServletRequest httpRequest1 = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
    String method = httpRequest1.getMethod();
    //https://stackoverflow.com/questions/9179375/servlet-filter-vs-cxf-interceptor-for-modifying-request-response-content
        //https://stackoverflow.com/questions/10743000/how-to-get-parameters-name-and-value-in-requesthandler-of-jax-rs-based-service-i
        String queryString = (String) message.get(Message.QUERY_STRING);        
            MultivaluedMap<String, String> queryMap = JAXRSUtils.getStructuredParams(queryString, "&", false, false);
            Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);    
               
               //HOW CAN I PAS THE VALUE TO THE HEADER SO I CAN MAKE WORK
               //THE INJECT FOR "javax.ws.rs.core.Context" ?
              ...

        } catch (Exception ce) {
        Fault fault = new Fault(ce.getMessage(), Logger.getGlobal());
            fault.setStatusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode());
            fault.setMessage(ce.getMessage());
            throw fault;
        }


{code}

It's not a ideal solution, but if anyone know how to do this , i can in the meanwhile go on with the project.

> 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:}
>  <from id="myRestSereer" uri="cxfrs:bean:myRestSereer?performInvocation=true&amp;bindingStyle=SimpleConsumer&amp;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 = httpHeaders.getRequestHeader(header).get(0);
> stringBuffer.append(header + ": " + headerValue + "\n");
> }
> logger.info(stringBuffer.toString());
> return Response.status(200).entity(stringBuffer.toString()).build();
> }
> {code}
> Anyone know what i'm doing wrong with camel-blueprint?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)