Advertisement
Guest User

Untitled

a guest
Jun 17th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package org.example.calculatorws.camel.processor;
  2.  
  3. import java.util.Map;
  4.  
  5. import org.apache.camel.Exchange;
  6. import org.apache.camel.Processor;
  7. import org.example.calculatorws.CalculatorRequest;
  8. import org.example.calculatorws.CalculatorResponse;
  9.  
  10. public class CalculatePayloadProcessor implements Processor
  11. {
  12.  
  13.     public void process(Exchange exchange) throws Exception
  14.     {
  15.         System.out.println("Entry :::: CalculatePayloadProcessor.process()");
  16.        
  17.         CalculatorRequest request = exchange.getIn().getBody(CalculatorRequest.class);
  18.         CalculatorResponse response = new CalculatorResponse();
  19.        
  20.         int operand1 = request.getOperand1();
  21.         int operand2 = request.getOperand2();
  22.         String operation = request.getOperation();
  23.         String responseContent = "";
  24.        
  25.         if(operation.equals("+"))
  26.         {
  27.             long result = operand1+operand2;
  28.             responseContent = "Response from calculate operation is ::: " +operand1 +" + "+ operand2+" = "+ result;
  29.         }
  30.         else if(operation.equals("-"))
  31.         {
  32.             long result = operand1-operand2;
  33.             responseContent = "Response from calculate operation is ::: " +operand1 +" - "+ operand2+" = "+ result;
  34.         }
  35.         else if(operation.equals("*"))
  36.         {
  37.             long result = operand1*operand2;
  38.             responseContent = "Response from calculate operation is ::: " +operand1 +" * "+ operand2+" = "+ result;
  39.         }
  40.         else if(operation.equals("/"))
  41.         {
  42.             long result = operand1/operand2;
  43.             responseContent = "Response from calculate operation is ::: " +operand1 +" / "+ operand2+" = "+ result;
  44.         }
  45.         else
  46.         {
  47.             responseContent = "Response from calculate operation is ::: Unsupported operation ["+operation+"] only [+,-,*,/] allowed";
  48.         }
  49.        
  50.         response.setResponse(responseContent);
  51.         exchange.getOut().setBody(response);
  52.         Map<String, Object> headers = exchange.getIn().getHeaders();
  53.         headers.put("operationName", "calculate");
  54.         exchange.getOut().setHeaders(headers);
  55.        
  56.         System.out.println("Exit  :::: CalculatePayloadProcessor.process()");
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement