/** * Creates the exchange for the next processor returned by * {@link #getProcessor()} from a source exchange. * * @param source * a source exchange. * @return exchange for the next processor. */ protected Exchange createDelegateExchange(Exchange source) { DefaultExchange result = new DefaultExchange(source.getContext()); result.getIn().copyFrom(source.getIn()); return result; }
/** * Creates a new {@link Exchange} from <code>packet</code> using the * current {@link CamelContext}. * * @param packet message packet. * @return a new message exchange. */ protected Exchange createExchange(PlatformPacket packet) { DefaultExchange exchange = new DefaultExchange(camelContext); exchange.setUnitOfWork(new DefaultUnitOfWork(exchange)); exchange.setProperties(new HashMap<>(packet.getExchangeProperties())); exchange.getIn().setHeaders(new HashMap<>(packet.getMessageProperties())); setInBody(packet.getMessageBody(), exchange); return exchange; }
@Test(timeout=60000) public void checkZeroTimeout() throws Exception { System.getProperties().setProperty(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_PROPERTY, "0"); CamelContext context = getContext(); EchoRequest echoRequest = new EchoRequest(); CamelRpcRequest<EchoRequest,EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), echoRequest); CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor(); DefaultExchange defaultExchange = new DefaultExchange(context); defaultExchange.getIn().setBody(wrapper); camelRpcClientPreProcessor.process(defaultExchange); context.stop(); assertEquals(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER)); }
@Test(timeout=60000) public void checkDefinedTimeout() throws Exception { System.getProperties().setProperty(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_PROPERTY, "12345"); CamelContext context = getContext(); CamelRpcRequest<EchoRequest,EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest()); CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor(); DefaultExchange defaultExchange = new DefaultExchange(context); defaultExchange.getIn().setBody(wrapper); camelRpcClientPreProcessor.process(defaultExchange); context.stop(); assertEquals(12345L, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER)); }
@Test(timeout=60000) public void checkUndefinedTimeout() throws Exception { CamelContext context = getContext(); CamelRpcRequest<EchoRequest,EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest()); CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor(); DefaultExchange defaultExchange = new DefaultExchange(context); defaultExchange.getIn().setBody(wrapper); camelRpcClientPreProcessor.process(defaultExchange); context.stop(); assertEquals(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER)); }