Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.example.calculatorws.camel.processor;
- import java.util.Map;
- import org.apache.camel.Exchange;
- import org.apache.camel.Processor;
- import org.example.calculatorws.CalculatorRequest;
- import org.example.calculatorws.CalculatorResponse;
- public class CalculatePayloadProcessor implements Processor
- {
- public void process(Exchange exchange) throws Exception
- {
- System.out.println("Entry :::: CalculatePayloadProcessor.process()");
- CalculatorRequest request = exchange.getIn().getBody(CalculatorRequest.class);
- CalculatorResponse response = new CalculatorResponse();
- int operand1 = request.getOperand1();
- int operand2 = request.getOperand2();
- String operation = request.getOperation();
- String responseContent = "";
- if(operation.equals("+"))
- {
- long result = operand1+operand2;
- responseContent = "Response from calculate operation is ::: " +operand1 +" + "+ operand2+" = "+ result;
- }
- else if(operation.equals("-"))
- {
- long result = operand1-operand2;
- responseContent = "Response from calculate operation is ::: " +operand1 +" - "+ operand2+" = "+ result;
- }
- else if(operation.equals("*"))
- {
- long result = operand1*operand2;
- responseContent = "Response from calculate operation is ::: " +operand1 +" * "+ operand2+" = "+ result;
- }
- else if(operation.equals("/"))
- {
- long result = operand1/operand2;
- responseContent = "Response from calculate operation is ::: " +operand1 +" / "+ operand2+" = "+ result;
- }
- else
- {
- responseContent = "Response from calculate operation is ::: Unsupported operation ["+operation+"] only [+,-,*,/] allowed";
- }
- response.setResponse(responseContent);
- exchange.getOut().setBody(response);
- Map<String, Object> headers = exchange.getIn().getHeaders();
- headers.put("operationName", "calculate");
- exchange.getOut().setHeaders(headers);
- System.out.println("Exit :::: CalculatePayloadProcessor.process()");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement