use of org.springframework.integration.samples.rest.domain.EmployeeList in project spring-integration-samples by spring-projects.
the class EmployeeSearchService method getEmployee.
/**
* The API <code>getEmployee()</code> looks up the mapped in coming message header's id param
* and fills the return object with the appropriate employee details. The return
* object is wrapped in Spring Integration Message with response headers filled in.
* This example shows the usage of URL path variables and how the service act on
* those variables.
* @param inMessage
* @return an instance of <code>{@link Message}</code> that wraps <code>{@link EmployeeList}</code>
*/
@Secured("ROLE_REST_HTTP_USER")
public Message<EmployeeList> getEmployee(Message<?> inMessage) {
EmployeeList employeeList = new EmployeeList();
Map<String, Object> responseHeaderMap = new HashMap<String, Object>();
try {
MessageHeaders headers = inMessage.getHeaders();
String id = (String) headers.get("employeeId");
boolean isFound;
if (id.equals("1")) {
employeeList.getEmployee().add(new Employee(1, "John", "Doe"));
isFound = true;
} else if (id.equals("2")) {
employeeList.getEmployee().add(new Employee(2, "Jane", "Doe"));
isFound = true;
} else if (id.equals("0")) {
employeeList.getEmployee().add(new Employee(1, "John", "Doe"));
employeeList.getEmployee().add(new Employee(2, "Jane", "Doe"));
isFound = true;
} else {
isFound = false;
}
if (isFound) {
setReturnStatusAndMessage("0", "Success", employeeList, responseHeaderMap);
} else {
setReturnStatusAndMessage("2", "Employee Not Found", employeeList, responseHeaderMap);
}
} catch (Exception e) {
setReturnStatusAndMessage("1", "System Error", employeeList, responseHeaderMap);
logger.error("System error occured :" + e);
}
Message<EmployeeList> message = new GenericMessage<EmployeeList>(employeeList, responseHeaderMap);
return message;
}
use of org.springframework.integration.samples.rest.domain.EmployeeList in project spring-integration-samples by spring-projects.
the class RestHttpClientTest method testGetEmployeeAsXml.
/**
* @throws Exception
*/
@Test
public void testGetEmployeeAsXml() {
Map<String, Object> employeeSearchMap = getEmployeeSearchMap("0");
final String fullUrl = "http://localhost:8080/rest-http/services/employee/{id}/search";
EmployeeList employeeList = restTemplate.execute(fullUrl, HttpMethod.GET, request -> {
HttpHeaders headers = getHttpHeadersWithUserCredentials(request);
headers.add("Accept", "application/xml");
}, responseExtractor, employeeSearchMap);
logger.info("The employee list size :" + employeeList.getEmployee().size());
StringWriter sw = new StringWriter();
StreamResult sr = new StreamResult(sw);
marshaller.marshal(employeeList, sr);
logger.info(sr.getWriter().toString());
assertTrue(employeeList.getEmployee().size() > 0);
}
Aggregations