Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7558987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:31:04+00:00 2026-05-30T12:31:04+00:00

We have built some REST (jax-rs) web services using Apache CXF. They return a

  • 0

We have built some REST (jax-rs) web services using Apache CXF. They return a JSON response.

I now need to modify some of the request parameters, and response content. (Basically we need to encode/encrypt some of the data that is returned by the service; and decode/decrypt the same data when it is used as a parameter in a subsequent service call.)

It seems I have at least 4 options here:

  1. Use a Servlet filter
  2. Use a CXF Interceptor
  3. Use a JAX-RS Filter
  4. Don’t use any particular pattern, and perform the encode/decode within the actual service logic.

I’ve used Servlet Filters before, and understand exactly how to modify request params and response body, so I’m leaning toward that. However, I’m open to using a CXF Interceptor or JAX-RS filter if that is the more ‘correct’ way to solve this when using CXF. But based on the documentation, I don’t really understand how to do this. For example, do I use the setContent method of the Message object to change the JSON response? What is the format parameter in that case, just String.class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:31:05+00:00Added an answer on May 30, 2026 at 12:31 pm

    Answering my own question here … I ended up using a JAX-RS filter, and it worked well, once I got past the lack of documentation. I used the (rather sparse) documentation from http://cxf.apache.org/docs/jax-rs-filters.html . Note despite it’s name, a JAX-RS filter is a CXF-specific beast, not part of the JAX-RS standard (as far as I can tell).

    Here is some example code:

    @Context
    private HttpServletRequest httpRequest;
    @Context
    private UriInfo uriInfo;
    
    /**
     * @see org.apache.cxf.jaxrs.ext.ResponseHandler#handleResponse(org.apache.cxf.message.Message, org.apache.cxf.jaxrs.model.OperationResourceInfo, javax.ws.rs.core.Response)
     */
    public Response handleResponse(Message message, OperationResourceInfo opResourceInfo, Response response) {
        try {
    
            // log the injected context data; useful for debugging CXF problems
            logContextData(httpRequest, uriInfo);
    
            OutputStream os = message.getContent(OutputStream.class);
            String relevantData = getDataFromRequest(httpRequest);
            message.setContent(OutputStream.class, new MyOutputStreamWrapper(os, relevantData));
    
        } catch (CustomException e) {
                // return some status that is related to CustomException
            return Response.status(Status.UNAUTHORIZED).build();
        } catch (Exception e) {
            return Response.status(Status.INTERNAL_SERVER_ERROR).build();
        }
    
        return response;
    }
    
    /**
     * @see org.apache.cxf.jaxrs.ext.RequestHandler#handleRequest(org.apache.cxf.message.Message, org.apache.cxf.jaxrs.model.ClassResourceInfo)
     */
    public Response handleRequest(Message message, ClassResourceInfo classResourceInfo) {
        try {
    
            // log the injected context data; useful for debugging CXF problems
            logContextData();
    
            String updatedQueryString = buildNewQueryString(this.uriInfo, httpRequest);
    
            message.put(Message.QUERY_STRING, updatedQueryString);
    
    
            // returning null tells CXF to continue the request (i.e. a non-null value would halt the request)
            return null;
    
        } catch (CustomException e) {
            // return some status that is related to CustomException
            return Response.status(Status.UNAUTHORIZED).build();
        } catch (Exception e) {
            return Response.status(Status.INTERNAL_SERVER_ERROR).build();
        }
    }
    

    I should note that the implementation of MyOutputStreamWrapper is the important part in modifying the response content. I couldn’t include that source here (in fact my implementation has a different name) due to security considerations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a custom component using some containers and a TileList. Now when
We have built some .NET controls, and we are using them as COM controls
We built some war files for our web server a while back and have
We have built a web application that accepts SOAP messages, does some processing, calls
Is http://feedly.com built using PHP, Java, or some other language/framework? I have googled for
In my web app I have an object which is built from a JSON
I know this sounds confusing: I have just built some basic prev/next pagination for
I have built a Java application that has some dependencies (~10). I would like
I have a project that comprises pre-build Dll modules, built some time in the
When updating a row, I want to have a built-in check to do some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.