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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:19:24+00:00 2026-06-09T23:19:24+00:00

I have following method in my rest service: @POST @Path(/create) @ResponseStatus(HttpStatus.CREATED) @Consumes(MediaType.WILDCARD) public String

  • 0

I have following method in my rest service:

    @POST
    @Path("/create")
    @ResponseStatus(HttpStatus.CREATED)
    @Consumes(MediaType.WILDCARD)
    public String create( .... ) {.... return json;}

so I want to get a response with json in body and status code CREATED.

The problem is: I can’t get a response the CREATED status.

The status code is allways OK, so it seems that “@ResponseStatus(HttpStatus.CREATED)” is just ignored…

Can somebody help me with it?

I’m using hibernate 4.1, spring 3.1 and resteasy 2.3

  • 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-06-09T23:19:26+00:00Added an answer on June 9, 2026 at 11:19 pm

    As far as I know, it’s not possible to achieve this by annotating the method with @org.springframework.web.bind.annotation.ResponseStatus.

    You can return javax.ws.rs.core.Response from your method:

    return Response
            .status(Response.Status.CREATED)
            .entity("ok")
            .build();
    

    Or you can have org.jboss.resteasy.spi.HttpResponse injected, and set the status code directly.

    There might be more ways of doing this, but I’m only aware of these two.

    Working testcase:

    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.spi.HttpResponse;
    import org.jboss.resteasy.spi.NotFoundException;
    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.Response;
    
    public class ResponseTest {
    
    
        @Path("/")
        public static class Service {
            @Context HttpResponse response;
    
            @GET
            @Path("/1")
            public Response createdUsingResponse() throws NotFoundException {
                return Response
                        .status(Response.Status.CREATED)
                        .entity("ok")
                        .build();
            }
    
            @GET
            @Path("/2")
            public String created() throws NotFoundException {
                response.setStatus(Response.Status.CREATED.getStatusCode());
                return "ok";
            }
        }
    
        public static class Interceptor implements PostProcessInterceptor {
            @Context HttpResponse response;
    
            @Override
            public void postProcess(ServerResponse response) {
                if(this.response.getStatus() != 0){
                    response.setStatus(this.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("/1");
                MockHttpResponse response = new MockHttpResponse();
    
                dispatcher.invoke(request, response);
    
                Assert.assertEquals(201, response.getStatus());
            }
            {
                MockHttpRequest request = MockHttpRequest.get("/2");
                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 have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have a WCF-REST service with one method which returns a string: [ServiceContract] public
I have a WFC Data Service using OData v3. Following REST specification I created
I have following code: $.get(CurrentServerAddress + '/service/v2/rest.php', { method: set_relationship, input_type: JSON, response_type: JSON,
I have the following method: public string Phase(string phase) { return Phase 1; }
I have the following method: public static T ExecuteScalar<T>( string query, SqlConnection connection, params
Let's say that I have specified the following WCF REST Service at the address
I have a WCF Rest service as per the code snippet below [ServiceContract] public
I have a REST POST method as follows: [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Xml,
I have written a REST Service in WCF in which I have created a

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.