@Override public Book getBook(Long id) { return producer.requestBodyAndHeaders(JMS_URI, null, getRestHeaders("GET", "/" + id), Book.class); }
@Override public BookList listBooks() { return producer.requestBodyAndHeaders(JMS_URI, null, getRestHeaders("GET", "/"), BookList.class); }
public <T> T sendMessageAndReceiveResponse(String destinationId, Object messageBody, Map<String, Object> metadata, Class<T> requiredType) throws IntegrationProcessingException, IllegalArgumentException { try { return this.camelTemplate.requestBodyAndHeaders(destinationId, messageBody, metadata, requiredType); } catch(final ClassCastException ex) { throw new IllegalArgumentException("The response message body is of incompatible type with passed in argument"); } catch (final Throwable e) { throw new IntegrationProcessingException(e); } } }
@Override public Response addBook(Book book) { return producer.requestBodyAndHeaders(JMS_URI, book, getRestHeaders("POST", "/"), Response.class); }
public <T> T fromBus(String channel, Class<T> responseType, Header... headers) { byte[] busResponse = producerTemplate.requestBodyAndHeaders("amqp:" + channel, null, arguments(headers), byte[].class); return decodedPayload(busResponse, responseType); }
from("direct:getContact") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { CamelContext context = exchange.getContext(); ProducerTemplate producerTemplate = context.createProducerTemplate(); //Call another route not the rest endpoint Future<Contact> contact = producerTemplate.requestBodyAndHeaders( "direct:RetrieveContactRoute", null, headers, Contact.class); logger.info("Contact is: " + new ObjectMapper().writeValueAsString(contact.get())); //Set the In Body not the Out Body exchange.getIn().setBody(contact.get()); });
public void toBusAndWait(String channel, Object payload, Header... headers) { Map<String, Object> collectedHeaders = new HashMap<>(); for(Header header : headers) { collectedHeaders.put(header.key(), header.value()); } byte[] busResponse = producerTemplate.requestBodyAndHeaders("amqp:" + channel, encodedPayload(payload), collectedHeaders, byte[].class); payloadEncoding.decode(busResponse); }
public <T> T fromBus(String channel, Object payload, Class<T> responseType, Header... headers) { byte[] busResponse = producerTemplate.requestBodyAndHeaders("amqp:" + channel, encodedPayload(payload), arguments(headers), byte[].class); return decodedPayload(busResponse, responseType); }
@Test public void testNoSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); String headerName = "testHeaderName"; String headerValue = "testHeaderValue"; Person person = new Person(); person.setName("Mauricio"); InsertObjectCommand cmd = (InsertObjectCommand) CommandFactory.newInsert(person, "salaboy"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(headerName, headerValue); headers.put(KieComponent.KIE_LOOKUP, "ksession1"); // set mock expectations mockResult.expectedMessageCount(1); mockResult.expectedHeaderReceived(headerName, headerValue); template.requestBodyAndHeaders("direct:test-no-session-withHeader", cmd, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null); mockResult.assertIsSatisfied(); }
@Test public void testSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); Person person = new Person(); person.setName("Mauricio"); InsertObjectCommand cmd = (InsertObjectCommand) CommandFactory.newInsert(person, "salaboy"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put("testHeaderName", "testHeaderValue"); template.requestBodyAndHeaders("direct:test-with-session-withHeader", cmd, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") instanceof FactHandle); mockResult.assertIsSatisfied(); }
mockResult.expectedHeaderReceived(headerName,headerValue); template.requestBodyAndHeaders("direct:test-no-session-withHeader", cmd,headers);
@Test public void testSessionBatchExecutionCommandWithHeader() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); String headerName = "testHeaderName"; String headerValue = "testHeaderValue"; Person john = new Person(); john.setName("John Smith"); List<Command> commands = new ArrayList<Command>(); commands.add(CommandFactory.newInsert(john, "john")); BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(commands); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(headerName, headerValue); // set mock expectations mockResult.expectedMessageCount(1); mockResult.expectedHeaderReceived(headerName, headerValue); // do test template.requestBodyAndHeaders("direct:test-with-session-withHeader", batchExecutionCommand, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") instanceof FactHandle); mockResult.assertIsSatisfied(); }
template.requestBodyAndHeaders("direct:test-with-session-withHeader", batchExecutionCommand,headers);
template.requestBodyAndHeaders( "direct:test-with-session-withHeader", cmd,headers );