Here are the examples of the java api org.apache.camel.ProducerTemplate.sendBody() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
190 Examples
19
Source : MessageDrivenBean.java
with Apache License 2.0
from wildfly-extras
with Apache License 2.0
from wildfly-extras
@Override
public void onMessage(Message message) {
try {
String messagePayload = ((TextMessage) message).getText();
template.sendBody(messagePayload);
} catch (JMSException e) {
throw new IllegalStateException("Error processing JMS message", e);
}
}
19
Source : ODataUpdateTests.java
with Apache License 2.0
from syndesisio
with Apache License 2.0
from syndesisio
@Test
public void testPatchODataRouteWithNoKeyPredicate() throws Exception {
Step directStep = createDirectStep();
Connector odataConnector = createODataConnector(new PropertyBuilder<String>().property(SERVICE_URI, defaultTestServer.servicePlainUri()));
String resourcePath = defaultTestServer.resourcePath();
String nameProperty = "Name";
Step odataStep = createODataStep(odataConnector, resourcePath);
ObjectNode newProduct = OBJECT_MAPPER.createObjectNode();
String newProductName = "NEC Screen";
newProduct.put(nameProperty, newProductName);
Step mockStep = createMockStep();
Integration odataIntegration = createIntegration(directStep, odataStep, mockStep);
RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
context.addRoutes(routes);
DirectEndpoint directEndpoint = context.getEndpoint("direct://start", DirectEndpoint.clreplaced);
ProducerTemplate template = context.createProducerTemplate();
context.start();
String inputJson = OBJECT_MAPPER.writeValuereplacedtring(newProduct);
replacedertThatThrownBy(() -> {
template.sendBody(directEndpoint, inputJson);
}).isInstanceOf(CamelExecutionException.clreplaced).hasMessageContaining("No Key Predicate available");
}
19
Source : StartProcessingMessagePolicyFactoryTest.java
with Apache License 2.0
from OpenWiseSolutions
with Apache License 2.0
from OpenWiseSolutions
/**
* Test when actual node is running.
*
* @throws Exception all errors
*/
@Test
public void testNodeRun() throws Exception {
inputRouteMock.setExpectedMessageCount(1);
inputUriMock.setExpectedMessageCount(1);
outputRouteMock.setExpectedMessageCount(1);
producer.sendBody("direct:inputRoute", "Body");
producer.sendBody("direct:inputUri", "Body");
producer.sendBody("direct:outputRoute", "Body");
replacedertIsSatisfied(inputRouteMock, inputUriMock, outputRouteMock);
}
19
Source : TraceHeaderProcessorTest.java
with Apache License 2.0
from OpenWiseSolutions
with Apache License 2.0
from OpenWiseSolutions
@Test
public void testValidateTraceIdNotAllowedValues() throws Exception {
final TraceHeaderProcessor processor = new TraceHeaderProcessor(true, Collections.<TraceIdentifierValidator>singletonList(new TraceIdentifierValidator() {
@Override
public boolean isValid(TraceIdentifier traceIdentifier) {
return false;
}
}));
prepareRoute(processor);
String request = "<notifyCollectionStepRequest xmlns=\"http://openhubframework.org/ws/NotificationsService-v1\">" + " <traceIdentifier xmlns=\"http://openhubframework.org/ws/Common-v1\">" + " <applicationID>ERP</applicationID>" + " <timestamp>2013-09-27T10:23:34.6987744+02:00</timestamp>" + " <correlationID>da793349-b486-489a-9180-200789b7007f</correlationID>" + " <processID>process123</processID>" + " </traceIdentifier>" + " <externalCustomerAccountID>2065</externalCustomerAccountID>" + " <eventDate>2013-09-26T00:00:00</eventDate>" + " <stepType>1</stepType>" + " <debtAmount>679</debtAmount>" + " <invoiceNo>130000000378</invoiceNo>" + " <variableSymbol>7002065001</variableSymbol>" + " </notifyCollectionStepRequest>";
// send message
try {
producer.sendBody(request);
fail("request must be rejected since traceId does not have the valid value");
} catch (Exception ex) {
Throwable origExp = ex.getCause();
replacedertThat(origExp, instanceOf(ValidationException.clreplaced));
replacedertThat(((ValidationException) origExp).getError().getErrorCode(), is(InternalErrorEnum.E120.getErrorCode()));
}
}
19
Source : AbstractCircuitBreakerTest.java
with Apache License 2.0
from OpenWiseSolutions
with Apache License 2.0
from OpenWiseSolutions
// util methods
protected void sendBodyInTryCatch(Object body) {
try {
producer.sendBody(body);
} catch (Exception ex) {
// do nothing
}
}
19
Source : AbstractCircuitBreakerTest.java
with Apache License 2.0
from OpenWiseSolutions
with Apache License 2.0
from OpenWiseSolutions
protected void sendBodyInTryCatch(ProducerTemplate producer, Object body) {
try {
producer.sendBody(body);
} catch (Exception ex) {
// do nothing
}
}
19
Source : ConfirmationPollExecutor.java
with Apache License 2.0
from OpenWiseSolutions
with Apache License 2.0
from OpenWiseSolutions
@Override
public void run() {
LOG.debug("Confirmation pooling starts ...");
// is there confirmation for processing?
ExternalCall extCall = null;
int lockFailureCount = 0;
while (true) {
try {
extCall = confirmationPool.getNextConfirmation();
if (extCall != null) {
// sends confirmation for next processing
producerTemplate.sendBody(targetURI, extCall);
} else {
// there is no new confirmation for processing
// => finish this executor and try it again after some time
break;
}
} catch (LockFailureException ex) {
// try again to acquire next message with lock
lockFailureCount++;
if (lockFailureCount > LOCK_FAILURE_LIMIT) {
LOG.warn("Probably problem with locking confirmations - count of lock failures exceeds limit (" + LOCK_FAILURE_LIMIT + ").");
break;
}
} catch (Exception ex) {
LOG.error("Error occurred while getting confirmations " + (extCall != null ? extCall.toHumanString() : ""), ex);
}
}
LOG.debug("Confirmation pooling finished.");
}
19
Source : ThrottlingComponentTest.java
with Apache License 2.0
from OpenWiseSolutions
with Apache License 2.0
from OpenWiseSolutions
private void callComponent(final String uri) throws Exception {
RouteBuilder testRoute = new AbstractBasicRoute() {
@Override
public void doConfigure() throws Exception {
from("direct:start").to(uri);
}
};
getCamelContext().addRoutes(testRoute);
// send message
producer.sendBody("someBody");
}
19
Source : CircuitComponentTest.java
with Apache License 2.0
from OpenWiseSolutions
with Apache License 2.0
from OpenWiseSolutions
@Test
public void test_preplacedThrough() throws Exception {
mock.expectedMessageCount(2);
producer.sendBody("payload-1");
producer.sendBody("payload-2");
mock.replacedertIsSatisfied();
}
19
Source : XpathProperty.java
with Apache License 2.0
from monodot
with Apache License 2.0
from monodot
@Test
public void testChoice() throws Exception {
mockOutputChoice.expectedMessageCount(1);
template.sendBody("direct:choice", "<greeting><text>Hello, world!</text></greeting>");
mockOutputChoice.replacedertIsSatisfied();
}
19
Source : XpathProperty.java
with Apache License 2.0
from monodot
with Apache License 2.0
from monodot
@Test
public void testFilter() throws Exception {
mockOutputFilter.expectedMessageCount(1);
template.sendBody("direct:filter", "<greeting><text>Hello, world!</text></greeting>");
mockOutputFilter.replacedertIsSatisfied();
}
19
Source : SpringRoutingLanguagesTest.java
with Apache License 2.0
from monodot
with Apache License 2.0
from monodot
@Test
public void simple() throws Exception {
mockSimple.expectedMessageCount(1);
template.sendBody("direct:simple", "Hello, world!");
mockSimple.replacedertIsSatisfied(1000L);
}
19
Source : SpringRoutingLanguagesTest.java
with Apache License 2.0
from monodot
with Apache License 2.0
from monodot
@Test
public void xpath() throws Exception {
mockXpath.expectedMessageCount(1);
template.sendBody("direct:xpath", "<greeting><text>Hello, world!</text></greeting>");
mockXpath.replacedertIsSatisfied(1L, TimeUnit.SECONDS);
}
19
Source : DatabaseTxApplicationTest.java
with Apache License 2.0
from monodot
with Apache License 2.0
from monodot
/**
* This test is a little crappy, but it proves the point.
* Since the route has 'transacted', the failure of the second
* database insert causes the first insert to be rolled back.
* @throws Exception
*/
@Test
public void testThatTheTransactionIsRolledBack() throws Exception {
try {
template.sendBody("direct:start", "");
} catch (CamelExecutionException ex) {
// Do nothing. We expect there to be an exception.
}
mockEndpoint.expectedMessageCount(1);
mockEndpoint.replacedertIsSatisfied(10, TimeUnit.SECONDS);
// there should be 0 rows in the database because we've rolled back
int rows = jdbcTemplate.queryForObject("select count(*) from customers", Integer.clreplaced);
replacedertEquals(0, rows);
}
19
Source : CamelArtemisApplicationTest.java
with Apache License 2.0
from monodot
with Apache License 2.0
from monodot
/**
* Test that we can send a message to our second route, and it arrives
* at the mock endpoint unchanged
* @throws InterruptedException
*/
@Test
public void testReceiveRouteReceivesOK() throws InterruptedException {
// These MUST appear first! Otherwise the replacedertions are set up after the message has been sent.
mockProcessedEndpoint.expectedMessageCount(1);
mockProcessedEndpoint.expectedBodiesReceived("Just a test message");
// Send a message to the new replacement "direct:receive" endpoint
template.sendBody("direct:receive", "Just a test message");
// This preplacedes because there is no mock
mockProcessedEndpoint.replacedertIsSatisfied();
}
19
Source : TestReturnValueFromFlowable.java
with Apache License 2.0
from flowable
with Apache License 2.0
from flowable
@Deployment
public void testReturnResultFromNewProcess() throws Exception {
resultEndpoint.expectedPropertyReceived("exampleCamelReturnValue", "hello world.");
template.sendBody("hello");
resultEndpoint.replacedertIsSatisfied();
}
19
Source : PojoMessageProducer.java
with The Unlicense
from diegopacheco
with The Unlicense
from diegopacheco
public void sendMessageIn(String body) {
jmsProducerIn.sendBody(body);
}
19
Source : PojoMessageProducer.java
with The Unlicense
from diegopacheco
with The Unlicense
from diegopacheco
public void sendMessageOut(String body) {
jmsProducerOut.sendBody(body);
}
19
Source : DataBean.java
with The Unlicense
from diegopacheco
with The Unlicense
from diegopacheco
@Consume(uri = "file:src/main/data?noop=true")
public void onFileSendToQueue(String body) {
producer.sendBody(body);
}
19
Source : XPathPropertyPlaceholderTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void testChoice2() throws Exception {
mockOutputChoice2.expectedMessageCount(1);
template.sendBody("direct:choice2", "<greeting><text>Bye, world!</text></greeting>");
mockOutputChoice2.replacedertIsSatisfied();
}
19
Source : XPathPropertyPlaceholderTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void testChoice() throws Exception {
mockOutputChoice.expectedMessageCount(1);
template.sendBody("direct:choice", "<greeting><text>Bye, world!</text></greeting>");
mockOutputChoice.replacedertIsSatisfied();
}
19
Source : ComponentRouteTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void shouldNotProvideConverter() throws InterruptedException {
// Given
String msg = "msg";
mock.expectedBodiesReceived(msg);
// When
producerTemplate.sendBody("direct:componentRoute", msg);
// Then
mock.replacedertIsSatisfied();
}
19
Source : CamelSpringBootShutdownTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void test2() throws Exception {
try {
// Starts a Thread to close the context in 500 ms
new DelayedCloser(context, 500).start();
// Send the same body, and let the context be closed before the processing happens
template.sendBody("direct:start", "42");
} catch (CamelExecutionException e) {
// unwrap Exception
throw (Exception) e.getCause();
}
}
19
Source : CamelSpringBootShutdownTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void test1() throws Exception {
try {
// Send a String body that need to be converted to an InputStream
template.sendBody("direct:start", "42");
} catch (CamelExecutionException e) {
// unwrap Exception
throw (Exception) e.getCause();
}
}
19
Source : CamelEventNotifierTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void testEventNotifier() throws InterruptedException {
MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:result", MockEndpoint.clreplaced);
mockEndpoint.expectedMessageCount(1);
producerTemplate.sendBody("direct:start", "Hello World");
mockEndpoint.replacedertIsSatisfied();
MyEventNotifier notifier = (MyEventNotifier) camelContext.getManagementStrategy().getEventNotifiers().get(0);
replacedertNotNull(notifier);
replacedertTrue(notifier.getCount() > 0);
}
19
Source : CamelAutoConfigurationPropertiesTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
// Tests
@Test
public void shouldResolveBothCamelAndSpringPlaceholders() throws InterruptedException {
// Given
MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:test", MockEndpoint.clreplaced);
mockEndpoint.expectedMessageCount(1);
// When
producerTemplate.sendBody(from, "msg");
// Then
mockEndpoint.replacedertIsSatisfied();
}
19
Source : CamelAnnotationsTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void shouldInjectEndpoint() throws InterruptedException {
mockEndpoint.setExpectedMessageCount(1);
producerTemplate.sendBody("direct:test", "msg");
mockEndpoint.replacedertIsSatisfied();
}
19
Source : EncryptedProperiesTestBase.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testEncryption(String uri, String expected) {
Object o = producer.sendBody(uri, InOut, "Hi from Camel!");
replacedertEquals(expected, mock.replacedertExchangeReceived(0).getIn().getBody());
mock.reset();
}
19
Source : NsqResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/send")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public void send(String msg) {
log(LOG, "Invoking send(%s)", msg);
template.sendBody("direct:send", msg.getBytes(MESSAGE_CHARSET));
}
19
Source : NettyResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/udp/codec")
@POST
public Object sendNettyUdpMessageWithCodec(String message) {
producerTemplate.sendBody("netty:udp://localhost:{{camel.netty.test-codec-udp-port}}?sync=false" + "&udpByteArrayCodec=true", message.getBytes(StandardCharsets.UTF_8));
return consumerTemplate.receiveBody("seda:custom-udp-codec", 5000, String.clreplaced);
}
19
Source : NettyResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/tcp/codec")
@POST
public Object sendNettyTcpMessageWithCodec(String message) {
producerTemplate.sendBody("netty:tcp://localhost:{{camel.netty.test-codec-tcp-port}}?disconnect=true" + "&sync=false&allowDefaultCodec=false" + "&decoders=#tcpNullDelimitedHandler,#bytesDecoder" + "&encoders=#bytesEncoder", createNullDelimitedMessage(message));
return consumerTemplate.receiveBody("seda:custom-tcp-codec", 5000, String.clreplaced);
}
19
Source : NatsResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/send")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public void send(@HeaderParam("sendToEndpointUri") String sendToEndpointUri, String message) {
LOG.debugf("Invoking send with (%s, %s)", sendToEndpointUri, message);
template.sendBody(sendToEndpointUri, message);
}
19
Source : JmsResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/sjms/{queueName}")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response produceSjmsMessage(@PathParam("queueName") String queueName, String message) throws Exception {
producerTemplate.sendBody("sjms2:queue:" + queueName, message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : JmsResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/paho/{queueName}")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response producePahoMessage(@PathParam("queueName") String queueName, String message) throws Exception {
producerTemplate.sendBody("paho:" + queueName + "?retained=true", message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : JmsResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/jms/{queueName}")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response produceJmsQueueMessage(@PathParam("queueName") String queueName, String message) throws Exception {
producerTemplate.sendBody("jms:queue:" + queueName, message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : HazelcastPolicyResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@POST
public Response post(String message) {
producerTemplate.sendBody("direct:in-policy", message);
return Response.accepted().build();
}
19
Source : GooglePubsubResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@POST
public Response sendStringToTopic(String message) {
producerTemplate.sendBody("google-pubsub:{{project.id}}:{{topic.name}}", message);
return Response.created(URI.create("https://camel.apache.org")).build();
}
19
Source : GooglePubsubResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/pojo")
@POST
public Response sendPojoToTopic(String fruitName) {
Fruit fruit = new Fruit(fruitName);
producerTemplate.sendBody("google-pubsub:{{project.id}}:{{topic.name}}", fruit);
return Response.created(URI.create("https://camel.apache.org")).build();
}
19
Source : SedaResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/post")
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response post(String message) throws Exception {
LOG.infof("Sending to seda: %s", message);
producerTemplate.sendBody("seda:foo", message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : AzureStorageQueueResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/queue/delete")
@DELETE
public Response deleteQueue() throws Exception {
producerTemplate.sendBody(componentUri(QueueOperationDefinition.deleteQueue), null);
return Response.noContent().build();
}
19
Source : AzureStorageQueueResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/queue/message")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response addMessage(String message) throws Exception {
producerTemplate.sendBody(componentUri(QueueOperationDefinition.sendMessage), message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : AzureStorageBlobResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/blob/delete")
@DELETE
public Response deleteBlob() throws Exception {
producerTemplate.sendBody(componentUri(BlobOperationsDefinition.deleteBlob), null);
return Response.noContent().build();
}
19
Source : AzureStorageBlobResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/blob/create")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response createBlob(String message) throws Exception {
producerTemplate.sendBody(componentUri(BlobOperationsDefinition.uploadBlockBlob), message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : AzureQueueResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/queue/message")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response addMessage(String message) throws Exception {
producerTemplate.sendBody("azure-queue://" + azureStorageAccountName + "/" + QUEUE_NAME + "?operation=addMessage&azureQueueClient=#azureQueueClient&validateClientURI=false", message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : AzureBlobResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/blob/create")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response createBlob(String message) throws Exception {
BlobBlock blob = new BlobBlock(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
producerTemplate.sendBody("azure-blob://" + azureStorageAccountName + "/" + azureBlobContainerName + "/" + BLOB_NAME + "?operation=uploadBlobBlocks&azureBlobClient=#azureBlobClient&validateClientURI=false", blob);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : AmqpResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/{queueName}")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response produceAmqpMessage(@PathParam("queueName") String queueName, String message) throws Exception {
producerTemplate.sendBody("amqp:queue:" + queueName, message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : ActiveMQResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/{queueName}")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response produceActiveMQMessage(@PathParam("queueName") String queueName, String message) throws Exception {
producerTemplate.sendBody("activemq:queue:" + queueName, message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : AzureStorageDatalakeResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/filesystem/{filesystem}")
@DELETE
@Produces(MediaType.TEXT_PLAIN)
public void deleteFileSystem(@PathParam("filesystem") String filesystem) throws Exception {
producerTemplate.sendBody(componentUri(filesystem, DataLakeOperationsDefinition.deleteFileSystem), null);
}
19
Source : AzureStorageDatalakeResource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Path("/filesystem/{filesystem}")
@POST
@Produces(MediaType.TEXT_PLAIN)
public Response createFileSystem(@PathParam("filesystem") String filesystem) throws Exception {
producerTemplate.sendBody(componentUri(filesystem, DataLakeOperationsDefinition.createFileSystem), null);
return Response.created(new URI("https://camel.apache.org/")).build();
}
19
Source : SimpleTransformAnnotationsBlueprintTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Test
public void testPayloadIsTransformed() throws InterruptedException {
mockOut.setExpectedMessageCount(1);
mockOut.message(0).body().isEqualTo("Modified: Cheese");
producerTemplate.sendBody("Cheese");
replacedertMockEndpointsSatisfied();
}
See More Examples