org.apache.camel.support.DefaultMessage Java Examples
The following examples show how to use
org.apache.camel.support.DefaultMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CamelHelperTest.java From vertx-camel-bridge with Apache License 2.0 | 6 votes |
@Test public void testTheCopyOfHeaders() { Message msg = new DefaultMessage(new DefaultCamelContext()); msg.setHeader("CamelRedelivered", false); msg.setHeader("CamelRedeliveryCounter", 0); msg.setHeader("JMSCorrelationID", ""); msg.setHeader("JMSDestination", "queue://dev.msy.queue.log.fwd"); msg.setHeader("JMSReplyTo", null); DeliveryOptions options = CamelHelper.getDeliveryOptions(msg, true); assertThat(options.getHeaders().get("CamelRedelivered")).isEqualToIgnoringCase("false"); assertThat(options.getHeaders().get("CamelRedeliveryCounter")).isEqualToIgnoringCase("0"); assertThat(options.getHeaders().get("JMSCorrelationID")).isEqualToIgnoringCase(""); assertThat(options.getHeaders().get("JMSDestination")).isEqualToIgnoringCase("queue://dev.msy.queue.log.fwd"); assertThat(options.getHeaders().get("JMSReplyTo")).isNull(); }
Example #2
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void createCinderVolume() throws Exception { ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); Message msg = new DefaultMessage(camelContext); Exchange exchange = Mockito.mock(Exchange.class); when(exchange.getIn()).thenReturn(msg); CinderEndpoint endpoint = Mockito.mock(CinderEndpoint.class); when(endpoint.getOperation()).thenReturn(OpenstackConstants.CREATE); msg.setBody(dummyVolume); Producer producer = new VolumeProducer(endpoint, client); producer.process(exchange); assertEqualVolumes(dummyVolume, msg.getBody(Volume.class)); }
Example #3
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void reserveGlanceImage() throws Exception { ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); GlanceEndpoint endpoint = Mockito.mock(GlanceEndpoint.class); when(endpoint.getOperation()).thenReturn(GlanceConstants.RESERVE); Message msg = new DefaultMessage(camelContext); msg.setBody(dummyImage); Exchange exchange = Mockito.mock(Exchange.class); when(exchange.getIn()).thenReturn(msg); Producer producer = new GlanceProducer(endpoint, client); producer.process(exchange); ArgumentCaptor<Image> captor = ArgumentCaptor.forClass(Image.class); verify(imageService).reserve(captor.capture()); assertEquals(dummyImage, captor.getValue()); Image result = msg.getBody(Image.class); assertNotNull(result.getId()); assertEqualsImages(dummyImage, result); }
Example #4
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void createKeystoneProject() throws Exception { ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); Message msg = new DefaultMessage(camelContext); Exchange exchange = Mockito.mock(Exchange.class); when(exchange.getIn()).thenReturn(msg); msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE); msg.setHeader(OpenstackConstants.NAME, dummyProject.getName()); msg.setHeader(KeystoneConstants.DESCRIPTION, dummyProject.getDescription()); msg.setHeader(KeystoneConstants.DOMAIN_ID, dummyProject.getDomainId()); msg.setHeader(KeystoneConstants.PARENT_ID, dummyProject.getParentId()); KeystoneEndpoint endpoint = Mockito.mock(KeystoneEndpoint.class); Producer producer = new ProjectProducer(endpoint, client); producer.process(exchange); ArgumentCaptor<Project> captor = ArgumentCaptor.forClass(Project.class); verify(projectService).create(captor.capture()); assertEqualsProject(dummyProject, captor.getValue()); }
Example #5
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void createNeutronNetwork() throws Exception { ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); Message msg = new DefaultMessage(camelContext); Exchange exchange = Mockito.mock(Exchange.class); when(exchange.getIn()).thenReturn(msg); msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE); msg.setHeader(OpenstackConstants.NAME, dummyNetwork.getName()); msg.setHeader(NeutronConstants.NETWORK_TYPE, dummyNetwork.getNetworkType()); msg.setHeader(NeutronConstants.TENANT_ID, dummyNetwork.getTenantId()); NeutronEndpoint endpoint = Mockito.mock(NeutronEndpoint.class); Producer producer = new NetworkProducer(endpoint, client); producer.process(exchange); ArgumentCaptor<Network> captor = ArgumentCaptor.forClass(Network.class); verify(networkService).create(captor.capture()); assertEqualsNetwork(dummyNetwork, captor.getValue()); assertNotNull(msg.getBody(Network.class).getId()); }
Example #6
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void createSwiftContainer() throws Exception { ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); Message msg = new DefaultMessage(camelContext); Exchange exchange = Mockito.mock(Exchange.class); when(exchange.getIn()).thenReturn(msg); when(containerService.create(anyString(), nullable(CreateUpdateContainerOptions.class))).thenReturn(actionResponse); when(actionResponse.isSuccess()).thenReturn(true); SwiftEndpoint endpoint = Mockito.mock(SwiftEndpoint.class); Producer producer = new ContainerProducer(endpoint, client); msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE); msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME); producer.process(exchange); ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<CreateUpdateContainerOptions> optionsCaptor = ArgumentCaptor.forClass(CreateUpdateContainerOptions.class); verify(containerService).create(containerNameCaptor.capture(), optionsCaptor.capture()); assertEquals(CONTAINER_NAME, containerNameCaptor.getValue()); assertNull(optionsCaptor.getValue()); }
Example #7
Source File: ArdulinkProducerTest.java From Ardulink-2 with Apache License 2.0 | 6 votes |
private void setup(String validSender, String commandName, List<String> commands) { try { CamelContext context = new DefaultCamelContext(); context.setTracing(true); context.addRoutes(new RouteBuilder() { @Override public void configure() { String splitter = "direct:splitter-" + identityHashCode(this); from(splitter).split(body()).to(OUT); from(IN) // .filter(header("From").isEqualToIgnoreCase(validSender)) // .choice() // .when(body().isEqualToIgnoreCase(commandName)).setBody(constant(commands)).to(splitter) // .otherwise().stop() // ; } }); context.start(); ArdulinkProducerTest.this.context = context; ArdulinkProducerTest.this.message = new DefaultMessage(context); } catch (Exception e) { throw propagate(e); } }
Example #8
Source File: DataMapperStepHandlerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testJsonTypeSourceProcessing() throws Exception { Exchange exchange = new DefaultExchange(camelContext); Map<String, Message> captured = new HashMap<>(); Message m1 = new DefaultMessage(camelContext); m1.setBody(Arrays.asList("{\"name\": \"Howard\", \"age\": 29}", "{\"name\": \"Sheldon\", \"age\": 30}")); captured.put("m1", m1); Message m2 = new DefaultMessage(camelContext); m2.setBody("{\"something\": \"else\"}"); captured.put("m2", m2); exchange.setProperty(OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP, captured); new DataMapperStepHandler.JsonTypeSourceProcessor(Arrays.asList("m1", "m2"), 2).process(exchange); assertThat(captured.get("m1").getBody(String.class)).isEqualTo("[{\"name\": \"Howard\", \"age\": 29},{\"name\": \"Sheldon\", \"age\": 30}]"); assertThat(captured.get("m2").getBody(String.class)).isEqualTo("{\"something\": \"else\"}"); }
Example #9
Source File: HttpRequestUnwrapperProcessorTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void shouldUnwrapResponses() throws Exception { final Message in = new DefaultMessage(camelContext); exchange.setIn(in); in.setBody("{\"parameters\":{\"h1\":\"v1\",\"h3\":\"v3\"},\"body\":{\"b1\":\"c1\",\"b2\":\"c2\"}}"); processor.process(exchange); assertThat(in.getHeaders()).containsOnly(entry("h1", "v1"), entry("h3", "v3")); assertThat(in.getBody()).isEqualTo("{\"b1\":\"c1\",\"b2\":\"c2\"}"); }
Example #10
Source File: HttpRequestUnwrapperProcessorTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void simpleNonStringValuesShouldBeUnwrappedVerbatim() throws Exception { final Message in = new DefaultMessage(camelContext); exchange.setIn(in); in.setBody("{\"body\":123}"); processor.process(exchange); assertThat(in.getHeaders()).containsOnly(entry(Exchange.CONTENT_TYPE, "text/plain")); assertThat(in.getBody()).isEqualTo("123"); }
Example #11
Source File: HttpRequestUnwrapperProcessorTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void simpleValuesShouldBeUnwrappedVerbatim() throws Exception { final Message in = new DefaultMessage(camelContext); exchange.setIn(in); in.setBody("{\"body\":\"simple\"}"); processor.process(exchange); assertThat(in.getHeaders()).containsOnly(entry(Exchange.CONTENT_TYPE, "text/plain")); assertThat(in.getBody()).isEqualTo("simple"); }
Example #12
Source File: HttpRequestUnwrapperProcessorTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void shouldUnwrapArrayResponses() throws Exception { final Message in = new DefaultMessage(camelContext); exchange.setIn(in); in.setBody("{\"body\":[{\"b1\":\"c1\"},{\"b2\":\"c2\"}]}"); processor.process(exchange); assertThat(in.getBody()).isEqualTo("[{\"b1\":\"c1\"},{\"b2\":\"c2\"}]"); }
Example #13
Source File: ContractVerifierCamelMessageBuilder.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
public <T> Message create(T payload, Map<String, Object> headers) { DefaultMessage message = new DefaultMessage(this.context); message.setBody(payload); if (headers != null) { message.setHeaders(headers); } return message; }
Example #14
Source File: HttpMessageToDefaultMessageProcessor.java From syndesis with Apache License 2.0 | 5 votes |
@Override public void process(Exchange exchange) throws Exception { final Message message = exchange.getIn(); if (message instanceof HttpMessage) { final Message replacement = new DefaultMessage(exchange.getContext()); replacement.copyFrom(message); ExchangeHelper.replaceMessage(exchange, replacement, false); } }
Example #15
Source File: AbstractCamelProvisioningManager.java From syncope with Apache License 2.0 | 5 votes |
protected void sendMessage(final String uri, final Object obj) { Exchange exchange = new DefaultExchange(contextFactory.getCamelContext()); DefaultMessage message = new DefaultMessage(contextFactory.getCamelContext()); message.setBody(obj); exchange.setIn(message); ProducerTemplate template = contextFactory.getCamelContext().createProducerTemplate(); template.send(uri, exchange); }
Example #16
Source File: AbstractCamelProvisioningManager.java From syncope with Apache License 2.0 | 5 votes |
protected void sendMessage(final String uri, final Object body, final Map<String, Object> properties) { DefaultExchange exchange = new DefaultExchange(contextFactory.getCamelContext()); // exclude properties with null value, otherwise DefaultExchange#properties, being a ConcurrentHashMap, // will raise NPE; no problems for later usage, as Map#get will return null for missing keys anyway exchange.setProperties(properties.keySet().stream(). filter(key -> properties.get(key) != null). collect(Collectors.toMap(Function.identity(), properties::get))); DefaultMessage message = new DefaultMessage(contextFactory.getCamelContext()); message.setBody(body); exchange.setIn(message); ProducerTemplate template = contextFactory.getCamelContext().createProducerTemplate(); template.send(uri, exchange); }
Example #17
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testNovaKeypair() throws Exception { when(osTestKeypair.getName()).thenReturn(KEYPAIR_NAME); when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey()); when(osTestKeypair.getFingerprint()).thenReturn("fp"); when(osTestKeypair.getPrivateKey()).thenReturn("prk"); ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); Message msg = new DefaultMessage(camelContext); msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE); msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME); Exchange exchange = Mockito.mock(Exchange.class); when(exchange.getIn()).thenReturn(msg); NovaEndpoint endpoint = Mockito.mock(NovaEndpoint.class); Producer producer = new KeypairProducer(endpoint, client); producer.process(exchange); ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class); verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture()); assertEquals(KEYPAIR_NAME, nameCaptor.getValue()); assertNull(keypairCaptor.getValue()); Keypair result = msg.getBody(Keypair.class); assertEquals("fp", result.getFingerprint()); assertEquals("prk", result.getPrivateKey()); assertEquals(dummyKeypair.getName(), result.getName()); assertEquals(dummyKeypair.getPublicKey(), result.getPublicKey()); }
Example #18
Source File: PayloadConverterHelper.java From syndesis with Apache License 2.0 | 5 votes |
static Exchange createExhangeWithBody(final String contentType, final String payload) { final Exchange exchange = new DefaultExchange(CONTEXT); final DefaultMessage in = new DefaultMessage(CONTEXT); in.setHeader(Exchange.CONTENT_TYPE, contentType); exchange.setIn(in); in.setBody(payload); return exchange; }
Example #19
Source File: GoogleCalendarEventsCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void shouldConvertGoogleEventToConnectorEventModel() { DefaultCamelContext cc = new DefaultCamelContext(); Exchange exchange = new DefaultExchange(cc); Message in = new DefaultMessage(cc); in.setBody(new Event()); exchange.setIn(in); GoogleCalendarEventsCustomizer.beforeConsumer(exchange); Object body = in.getBody(); assertThat(body).isInstanceOf(GoogleCalendarEventModel.class); }
Example #20
Source File: JsonSimplePredicateTest.java From syndesis with Apache License 2.0 | 5 votes |
private static Exchange exchangeWith(final Object body) { final DefaultExchange exchange = new DefaultExchange(CONTEXT); final DefaultMessage payload = new DefaultMessage(CONTEXT); payload.setBody(body); exchange.setIn(payload); return exchange; }
Example #21
Source File: DataMapperStepHandlerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testJsonTypeSourceProcessingMissingSources() throws Exception { Exchange exchange = new DefaultExchange(camelContext); Map<String, Message> captured = new HashMap<>(); Message m1 = new DefaultMessage(camelContext); m1.setBody(Collections.singletonList("{\"name\": \"Amy\", \"age\": 29}")); captured.put("m1", m1); exchange.setProperty(OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP, captured); new DataMapperStepHandler.JsonTypeSourceProcessor(Arrays.asList("m1", "m2_missing", "m3_missing"), 3).process(exchange); assertThat(captured.get("m1").getBody(String.class)).isEqualTo("[{\"name\": \"Amy\", \"age\": 29}]"); }
Example #22
Source File: HttpRequestWrapperProcessor.java From syndesis with Apache License 2.0 | 4 votes |
@Override @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") // https://github.com/spotbugs/spotbugs/issues/259 public void process(Exchange exchange) throws Exception { final Message message = exchange.getIn(); final Object body = message.getBody(); final ObjectNode rootNode = JsonUtils.copyObjectMapperConfiguration().createObjectNode(); if (!parameters.isEmpty()) { final ObjectNode parametersNode = rootNode.putObject("parameters"); final HttpServletRequest servletRequest = message.getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class); for (String parameter : parameters) { final String[] values; final String[] headerValues = message.getHeader(parameter, String[].class); if (servletRequest != null && headerValues == null) { values = servletRequest.getParameterValues(parameter); } else { values = headerValues; } putPrameterValueTo(parametersNode, parameter, values); } } if (body instanceof String) { final String string = (String) body; if (ObjectHelper.isNotEmpty(string)) { rootNode.set("body", READER.readValue(string)); } } else if (body instanceof InputStream) { try (InputStream stream = (InputStream) body) { if (stream.available() > 0) { rootNode.set("body", READER.readValue(stream)); } } } else if (body != null) { rootNode.putPOJO("body", body); } final String newBody = JsonUtils.toString(rootNode); final Message replacement = new DefaultMessage(exchange.getContext()); replacement.copyFromWithNewBody(message, newBody); // we rely on having the Content-Type match the body when we're // extracting parameters from the JSON body, otherwise we don't // know if the content is JSON or XML (or any future supported // content type) replacement.setHeader(Exchange.CONTENT_TYPE, "application/json"); ExchangeHelper.replaceMessage(exchange, replacement, false); }