Skip to content

rest-http POST method #108

Open
Open
@ghost

Description

i want to sent json by post method
after change integration configuration
and write test i send object but response is failed

<int-http:inbound-gateway id="inboundEmployeeSearchRequestGateway" 
        supported-methods="POST"
        request-payload-type="org.springframework.integration.samples.rest.domain.Employee"
        request-channel="employeeSearchRequest"
        reply-channel="employeeSearchResponse"
        mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
        path="/services/employee/{id}/search"
        reply-timeout="50000"  
        >
@Test
    public void testGetEmployeeAsJsonPOST() throws Exception {
        Map<String, Object> employeeSearchMap = getEmployeeSearchMap("0");

        final String fullUrl = "http://localhost:8080/rest-http/services/employee/{id}/search?format=json";
        HttpHeaders headers = getHttpHeadersWithUserCredentials(new HttpHeaders());
        headers.add("Accept", "application/json");
        Employee em=new Employee(6, "ali akbar", "azizkhani");
        HttpEntity<Employee> request = new HttpEntity<Employee>(em,headers);
        ResponseEntity<?> httpResponse = restTemplate.exchange(fullUrl, HttpMethod.POST, request,EmployeeList.class, employeeSearchMap);
        logger.info("Return Status :" + httpResponse.getHeaders().get("X-Return-Status"));
        logger.info("Return Status Message :" + httpResponse.getHeaders().get("X-Return-Status-Msg"));
        assertTrue(httpResponse.getStatusCode().equals(HttpStatus.OK));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        jaxbJacksonObjectMapper.writeValue(out, httpResponse.getBody());
        logger.info(new String(out.toByteArray()));
    }

Activity

artembilan

artembilan commented on May 26, 2014

@artembilan
Member

Your changes works for me. Share, please, the StackTrace

ghost
artembilan

artembilan commented on May 27, 2014

@artembilan
Member

Looks like you changed something else, e.g. in the EmployeeSearchService

ghost
artembilan

artembilan commented on May 27, 2014

@artembilan
Member

Do you mean this:

 Employee expl=(Employee)inMessage.getPayload();
 employeeList.getEmployee().add(expl);

?
What is your point? Just to check that we can transfer request object to response?
Although I don't see concern to add it to the sample, but there is need to understand the goal.

Thanks

ghost
artembilan

artembilan commented on May 27, 2014

@artembilan
Member

Strange: it works for me again:

09:50:11.714 INFO [main][org.springframework.integration.samples.rest.RestHttpClientTest] Return Status :[0]
09:50:11.715 INFO [main][org.springframework.integration.samples.rest.RestHttpClientTest] Return Status Message :[Success]
09:50:11.735 INFO [main][org.springframework.integration.samples.rest.RestHttpClientTest] {"employee":[{"employeeId":1,"fname":"ali","lname":"azizkhani"},{"employeeId":1,"fname":"John","lname":"Doe"},{"employeeId":2,"fname":"Jane","lname":"Doe"}],"returnStatus":"0","returnStatusMsg":"Success"}

Or you are using some old SAMPLES version, or I am wrong that test it against my Gradle branch.

I think we will add your tweaks to this sample, but already after we commit Gradle migration.

What might cause the issue, that I use Gradle and its Jetty pluging, but Maven sample uses Tomcat pluging.

As the conclusion: all your modifications are correct and have the right to life

ghost
ghost
artembilan

artembilan commented on Jun 4, 2014

@artembilan
Member

Well, does it say that you haven't shown entire changes to the sample?
Can you do it now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @artembilan

        Issue actions

          rest-http POST method · Issue #108 · spring-projects/spring-integration-samples