Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8119

Can't Inject "javax.ws.rs.core.Context" annotation with camel blueprint

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Workaround
    • 3.2.7
    • None
    • Bus, Core, JAX-RS, OSGi, Resources
    • None
    • Unknown

    Description

      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

      My goal is to set the value of the field;

      @javax.ws.rs.core.Context
      public javax.ws.rs.core.HttpHeaders httpHeaders;
      

      Another strange bug is if i call the method:

      	@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();
      	}
      }
      

      it's work just fine , but if i call this (i just add the @Context HttpHeaders httpHeaders parameter on the method) :

       @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(); }
      
      }
      

      i get this error:

      415 Error: Unsupported Media Type
       

      Teh documentation say something about the attribute "propagateContexts" to true, but seem do nothing:

       <from id="myRestSereer" uri="cxfrs:bean:myRestSereer?performInvocation=true&amp;bindingStyle=SimpleConsumer&amp;propagateContexts=true"/>
      

      ANOTHER example i can't undestand, the first method is injected with succes, the second give me the "415 Error: Unsupported Media Type":

      
      	/**
      	 * 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();
      	}
      

      Anyone know what i'm doing wrong with camel-blueprint?

      Attachments

        Activity

          People

            Unassigned Unassigned
            4535992 Marco Tenti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: