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 7079769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:42:45+00:00 2026-05-28T06:42:45+00:00

I’m trying to create a REST service defined as: @POST @Path(/path) @Consumes(MediaType.APPLICATION_XML) @Produces(multipart/mixed) public

  • 0

I’m trying to create a REST service defined as:

@POST
@Path("/path")
@Consumes(MediaType.APPLICATION_XML)
@Produces("multipart/mixed")
public MultipartOutput create(MyObject o) {}

First part of the output will be an XML, second part a text file. In the XML I have the status code that I need, but how can I use it to create the HTTP status code? Currently I receive 200, I need 201.

(For other services, without MultipartOutput, the response is created using ResponseBuilder).

  • 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-28T06:42:46+00:00Added an answer on May 28, 2026 at 6:42 am


    You can use the @Context to access the HttpServletResponse.

    Try changing your method signature and call setStatus:

    public MultipartOutput create(MyObject o, @Context HttpServletResponse response) {
        MultipartOutput mpo = ...
        response.setStatus(201);
    
        return mpo;
    }
    

    EDIT :

    Try using org.jboss.resteasy.spi.HttpResponse instead together with a PostProcessInterceptor:

    import org.jboss.resteasy.core.Dispatcher;
    import org.jboss.resteasy.core.ServerResponse;
    import org.jboss.resteasy.mock.MockDispatcherFactory;
    import org.jboss.resteasy.mock.MockHttpRequest;
    import org.jboss.resteasy.mock.MockHttpResponse;
    import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
    import org.jboss.resteasy.spi.HttpResponse;
    import org.jboss.resteasy.spi.interception.PostProcessInterceptor;
    import org.junit.Assert;
    import org.junit.Test;
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.core.Context;
    import javax.ws.rs.core.MediaType;
    import javax.xml.bind.annotation.XmlRootElement;
    
    public class MultipartTest {
        @XmlRootElement(name = "MyObject")
        static class MyObject {}
    
        @Path("/")
        public static class Service {
            @Context HttpResponse response;
    
            @GET
            @Path("/mpo")
            public MultipartOutput create() {
                response.setStatus(201);
    
                final MultipartOutput mpo = new MultipartOutput();
                mpo.addPart(new MyObject(), MediaType.APPLICATION_XML_TYPE);
    
                return mpo;
            }
        }
    
        public static class Interceptor implements PostProcessInterceptor {
            @Context HttpResponse response;
    
            @Override
            public void postProcess(ServerResponse serverResponse) {
                serverResponse.setStatus(response.getStatus());
            }
        }
    
        @Test
        public void test() throws Exception {
            Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
            dispatcher.getRegistry().addSingletonResource(new Service());
            dispatcher.getProviderFactory().getServerPostProcessInterceptorRegistry().register(new Interceptor());
    
            MockHttpRequest request = MockHttpRequest.get("/mpo");
            MockHttpResponse response = new MockHttpResponse();
    
            dispatcher.invoke(request, response);
    
            Assert.assertEquals(201, response.getStatus());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.