on a side note, you should reuse the ProducerTemplate in your processors across subsequent requests...
minimize calls to "context.createProducerTemplate()" by using a static/class level variable to hold this reference, should help performance... WPk wrote > public class ScanningServicesProcessor implements Processor { > > private static GlobalLogger log = > GlobalLogger.getLogger(ScanningServicesProcessor.class.getName()); > private LoadServicesHandler loadServicesHandler ; > > @Autowired > public ScanningServicesProcessor (LoadServicesHandler loadHandler) > { > this.loadServicesHandler = loadHandler; > } > /** > * > * This method overrides the org.apache.camel.Processor.process > method. > * Consumes the HTTP based requests coming from the Captiva Service > and > * start processing in the method. > * > * @param loadExchange > * - The Exchange object. Returns 200 - OK - When the > processing > * is completed with no errors. Returns 444 - No Content > - When > * the Freight Management - Load Details returns 404. > Returns 500 > * - Internal Server Error - When any internal exception > is > * encountered. Returns 400 - Bad Request if the input > loadId is > * bad (Null, Empty or non-integer value). > */ > @Override > public void process(Exchange loadExchange) { > > final CamelContext context = loadExchange.getContext(); > final ProducerTemplate template = > context.createProducerTemplate(); > int freightResponseCode = 0; > Message loadMsgOut = null; > final String loadId = (String) > loadExchange.getIn().getHeader("loadId"); > Map<String, Object> headersMap = new > HashMap<String, Object>(); > > /** Start processing for a valid loadId **/ > if (null != loadId && !"".equals(loadId) && > loadId.matches("[0-9]+")) { > FetchLoadStopResponse fetchLoadStopResponse = > null; > > log.debug("Started invoking the Load Details > Service in the Freight Management Module for the Load Id: " > + loadId); > Map<String, Object> loadHeader = new > HashMap<String, Object>(); > loadHeader.put(Exchange.HTTP_PATH, loadId); > Exchange exchange = ScanningServicesUtils > .invokeCamelHTTPService( > template, > > ScanningServicesCommonConstants.FREIGHT_LOAD_SVCS_URL_PROPERTY, > loadHeader, null); > loadMsgOut = (null != exchange) ? > exchange.getOut() : null; > InputSource loadMsgSource = null != loadMsgOut ? > loadMsgOut > .getBody(InputSource.class) : > null; > freightResponseCode = (null != loadMsgOut && null > != loadMsgSource) ? (loadMsgOut > > .getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class)) : 0; > log.debug("Load Details Service in the Freight > Management Module for the Load Id: " > + loadId > + " returned a response code " > + freightResponseCode); > > /** Process the Load Details if the response code > is 200 **/ > try { > if (freightResponseCode == > ScanningServicesCommonConstants.HTTP_STATUS_SUCCESS) { > log.debug("Load Details Service in > the Freight Management Module for the Load Id: " > + loadId + " > returned" + loadMsgSource.toString()); > fetchLoadStopResponse = > loadServicesHandler > > .processPickUpStops(context, loadMsgSource); > > } > /** > * Set the Message Out Body from the > Scanning Services Web > * Service > **/ > if (null != fetchLoadStopResponse > && > fetchLoadStopResponse.getLoadStops().size() > 0) { > headersMap > > .put(Exchange.HTTP_RESPONSE_CODE, > > ScanningServicesCommonConstants.HTTP_STATUS_SUCCESS); > > ScanningServicesUtils.setExchangeBodyAndHeaders( > loadExchange, > ScanningServicesUtils.marshal( > > fetchLoadStopResponse, > > FetchLoadStopResponse.class), headersMap); > > } else if (null == fetchLoadStopResponse > && (freightResponseCode == > ScanningServicesCommonConstants.HTTP_STATUS_PAGE_NOT_FOUND > || > freightResponseCode == 0 || freightResponseCode == > ScanningServicesCommonConstants.HTTP_STATUS_INTERNAL_SERVER_ERROR)) { > String error = (null != exchange > && null != exchange > .getException()) ? > exchange.getException() > .getMessage() : > ""; > log.error("Invoke of the service > returned a response code." > + > freightResponseCode); > log.error("Invoke of the service > failed." + error); > headersMap > > .put(Exchange.HTTP_RESPONSE_CODE, > > ScanningServicesCommonConstants.HTTP_STATUS_PAGE_NOT_FOUND); > ScanningServicesUtils > > .setExchangeBodyAndHeaders( > > loadExchange, > > ScanningServicesCommonConstants.HTTP_RESPONSE_PAGE_NOT_FOUND, > > headersMap); > } else { > String error = (null != exchange > && null != exchange > .getException()) ? > exchange.getException() > .getMessage() : > ""; > log.debug("Invoke of the service > returned a response code." > + > freightResponseCode); > if("" != error) { > log.error("Invoke of the > service returned" + error); > } > headersMap > > .put(Exchange.HTTP_RESPONSE_CODE, > > ScanningServicesCommonConstants.HTTP_STATUS_NO_RESPONSE); > ScanningServicesUtils > > .setExchangeBodyAndHeaders( > > loadExchange, > > ScanningServicesCommonConstants.HTTP_RESPONSE_NO_RESPONSE, > > headersMap); > > } > > } catch (Exception e) { > headersMap > > .put(Exchange.HTTP_RESPONSE_CODE, > > ScanningServicesCommonConstants.HTTP_STATUS_INTERNAL_SERVER_ERROR); > ScanningServicesUtils > > .setExchangeBodyAndHeaders( > > loadExchange, > > ScanningServicesCommonConstants.HTTP_RESPONSE_INTERNAL_SERVER_ERROR, > > headersMap); > log.error("Exception occured while > fetching the details for the load" > + e.getMessage()); > } > > } else { > log.error("The request to Scanning Services could > not be fulfilled due to bad" > + " request."); > headersMap.put(Exchange.HTTP_RESPONSE_CODE, > > ScanningServicesCommonConstants.HTTP_STATUS_BAD_REQUEST); > > ScanningServicesUtils.setExchangeBodyAndHeaders(loadExchange, > > ScanningServicesCommonConstants.HTTP_RESPONSE_BAD_REQUEST, > headersMap); > > } > > log.debug("Exit the ScanningServicesProcessor"); > } > } ----- Ben O'Day IT Consultant -http://consulting-notes.com -- View this message in context: http://camel.465427.n5.nabble.com/Camel-Jetty-Performance-Issue-tp5733133p5733737.html Sent from the Camel - Users mailing list archive at Nabble.com.