本文整理汇总了Java中org.apache.camel.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.apache.camel包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.camel.Message; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
Address address = in.getHeader(Constants.ADDRESS_HEADER, Address.class);
Class<?> datatype = in.getHeader(Constants.DATATYPE_HEADER, Class.class);
Object value = in.getBody(Object.class);
PlcWriteRequest plcSimpleWriteRequest = new PlcWriteRequest(datatype, address, value);
PlcWriter plcWriter = plcConnection.getWriter().orElseThrow(() -> new IllegalArgumentException("Writer for driver not found"));
CompletableFuture<PlcWriteResponse> completableFuture = plcWriter.write(plcSimpleWriteRequest);
int currentlyOpenRequests = openRequests.incrementAndGet();
try {
log.debug("Currently open requests including {}:{}", exchange, currentlyOpenRequests);
PlcWriteResponse plcWriteResponse = completableFuture.get();
if (exchange.getPattern().isOutCapable()) {
Message out = exchange.getOut();
out.copyFrom(exchange.getIn());
out.setBody(plcWriteResponse);
} else {
in.setBody(plcWriteResponse);
}
} finally {
int openRequestsAfterFinish = openRequests.decrementAndGet();
log.trace("Open Requests after {}:{}", exchange, openRequestsAfterFinish);
}
}
示例2: onCompletion
import org.apache.camel.Message; //导入依赖的package包/类
@Override
public void onCompletion(Exchange exchange) {
if (wrappedAggregationStrategy != null
&& wrappedAggregationStrategy instanceof CompletionAwareAggregationStrategy) {
((CompletionAwareAggregationStrategy) wrappedAggregationStrategy).onCompletion(exchange);
}
// Remove exception, fault and redelivery info from exchange
exchange.setException(null);
exchange.removeProperty(Exchange.FAILURE_HANDLED);
exchange.removeProperty(Exchange.FAILURE_ENDPOINT);
exchange.removeProperty(Exchange.FAILURE_ROUTE_ID);
exchange.removeProperty(Exchange.ERRORHANDLER_CIRCUIT_DETECTED);
exchange.removeProperty(Exchange.ERRORHANDLER_HANDLED);
exchange.removeProperty(Exchange.EXCEPTION_HANDLED);
exchange.removeProperty(Exchange.EXCEPTION_CAUGHT);
Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
message.setFault(false);
message.removeHeader(Exchange.REDELIVERED);
message.removeHeader(Exchange.REDELIVERY_COUNTER);
message.removeHeader(Exchange.REDELIVERY_DELAY);
message.removeHeader(Exchange.REDELIVERY_EXHAUSTED);
message.removeHeader(Exchange.REDELIVERY_MAX_COUNTER);
}
示例3: process
import org.apache.camel.Message; //导入依赖的package包/类
@Override
public final void process(final Exchange exchange) throws Exception {
if (exchange.isFailed()) {
return;
}
if (type == null) {
return;
}
final Message message = message(exchange);
final String bodyAsString = message.getBody(String.class);
if (bodyAsString == null) {
return;
}
try {
final Object output = MAPPER.readValue(bodyAsString, type);
message.setBody(output);
} catch (final IOException e) {
exchange.setException(e);
}
}
示例4: process
import org.apache.camel.Message; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
Status status = exchange.getIn().getBody(Status.class);
User user = status.getUser();
String name = user.getName();
String screenName = user.getScreenName();
Contact contact = new Contact();
contact.setLastName(name);
contact.setTwitterScreenName__c(screenName);
in.setBody(contact);
}
示例5: process
import org.apache.camel.Message; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
String actionName = in.getHeader(SpongeConstants.SPONGE_ACTION, String.class);
if (actionName != null) {
// Remove the header so it won't be propagated.
in.removeHeader(SpongeConstants.SPONGE_ACTION);
}
if (actionName == null) {
actionName = action != null ? action : CamelProducerAction.NAME;
}
Object result = engine.getOperations().call(actionName, exchange);
exchange.getIn().setBody(result);
}
示例6: process
import org.apache.camel.Message; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
OrientDBEndpoint endpoint = (OrientDBEndpoint)getEndpoint();
curDb = endpoint.databaseOpen();
Object input = exchange.getIn().getBody();
Message out = exchange.getOut();
out.getHeaders().putAll(exchange.getIn().getHeaders());
if (input instanceof List){
out.setBody(endpoint.makeOutObject(processList((List<?>)input, endpoint, curDb)));
}else if (input instanceof String && isJSONList((String)input)){
List<String> inputList = strToJSONsList((String)input);
out.setBody(endpoint.makeOutObject(processList(inputList, endpoint, curDb)));
}else{
out.setBody(endpoint.makeOutObject(processSingleObject(input, endpoint, curDb)));
}
endpoint.databaseClose(curDb);
curDb=null;
}
示例7: bind
import org.apache.camel.Message; //导入依赖的package包/类
private void bind(InvokeOnHeader handler, final Method method) {
if (handler != null && method.getParameterCount() == 1) {
method.setAccessible(true);
final Class<?> type = method.getParameterTypes()[0];
LOGGER.debug("bind key={}, class={}, method={}, type={}",
handler.value(), this.getClass(), method.getName(), type);
if (Message.class.isAssignableFrom(type)) {
bind(handler.value(), e -> method.invoke(target, e.getIn()));
} else {
bind(handler.value(), e -> method.invoke(target, e));
}
}
}
示例8: testTheCopyOfHeaders
import org.apache.camel.Message; //导入依赖的package包/类
@Test
public void testTheCopyOfHeaders() {
Message msg = new DefaultMessage();
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();
}
示例9: getOut
import org.apache.camel.Message; //导入依赖的package包/类
public <T> T getOut(Class<T> type) {
if (!hasOut()) {
return null;
}
Message out = getOut();
// eager same instance type test to avoid the overhead of invoking the type converter
// if already same type
if (type.isInstance(out)) {
return type.cast(out);
}
// fallback to use type converter
return context.getTypeConverter().convertTo(type, this, out);
}
示例10: getParentForDetachedCase
import org.apache.camel.Message; //导入依赖的package包/类
private Element getParentForDetachedCase(Document doc, Message inMessage, String referenceUri) throws XmlSignatureException {
String elementId = referenceUri;
if (elementId.startsWith("#")) {
elementId = elementId.substring(1);
}
Element el = doc.getElementById(elementId);
if (el == null) {
// should not happen because has been checked before
throw new IllegalStateException("No element found for element ID " + elementId);
}
LOG.debug("Sibling element of the detached XML Signature with reference URI {}: {} {} ",
new Object[] {referenceUri, el.getLocalName(), el.getNamespaceURI() });
Element result = getParentElement(el);
if (result != null) {
return result;
} else {
throw new XmlSignatureException(
"Either the configuration of the XML Signature component is wrong or the incoming document has an invalid structure: The element "
+ el.getLocalName() + "{" + el.getNamespaceURI() + "} which is referenced by the reference URI " + referenceUri
+ " has no parent element. The element must have a parent element in the configured detached case.");
}
}
示例11: createRouteBuilder
import org.apache.camel.Message; //导入依赖的package包/类
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
errorHandler(noErrorHandler());
from(getFromEndpointUri()).process(new Processor() {
public void process(final Exchange exchange) {
Message in = exchange.getIn();
Node node = in.getBody(Node.class);
assertNotNull(node);
XmlConverter xmlConverter = new XmlConverter();
// Put the result back
exchange.getOut().setBody(xmlConverter.toSource(RESPONSE));
}
});
}
};
}
示例12: createRouteBuilder
import org.apache.camel.Message; //导入依赖的package包/类
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// Test the filter list options
from("jetty://http://localhost:{{port}}/testFilters?filtersRef=myFilters&filterInit.keyWord=KEY").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
String request = in.getBody(String.class);
// The other form date can be get from the message header
exchange.getOut().setBody(request + " response");
}
});
}
};
}
示例13: process
import org.apache.camel.Message; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
Message inMessage = exchange.getIn();
// Get the operation name from in message
String operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME, String.class);
if ("getCustomer".equals(operationName)) {
processGetCustomer(exchange);
} else if ("updateCustomer".equals(operationName)) {
assertEquals("Get a wrong customer message header", "header1;header2", inMessage.getHeader("test"));
String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
assertEquals("Get a wrong http method", "PUT", httpMethod);
Customer customer = inMessage.getBody(Customer.class);
assertNotNull("The customer should not be null.", customer);
// Now you can do what you want on the customer object
assertEquals("Get a wrong customer name.", "Mary", customer.getName());
// set the response back
exchange.getOut().setBody(Response.ok().build());
}
}
示例14: updateMessageHeader
import org.apache.camel.Message; //导入依赖的package包/类
protected void updateMessageHeader(Message in, ChannelHandlerContext ctx) {
in.setHeader(NettyConstants.NETTY_CHANNEL_HANDLER_CONTEXT, ctx);
in.setHeader(NettyConstants.NETTY_REMOTE_ADDRESS, ctx.channel().remoteAddress());
in.setHeader(NettyConstants.NETTY_LOCAL_ADDRESS, ctx.channel().localAddress());
if (configuration.isSsl()) {
// setup the SslSession header
SSLSession sslSession = getSSLSession(ctx);
in.setHeader(NettyConstants.NETTY_SSL_SESSION, sslSession);
// enrich headers with details from the client certificate if option is enabled
if (configuration.isSslClientCertHeaders()) {
enrichWithClientCertInformation(sslSession, in);
}
}
}
示例15: parentFolderPathFor
import org.apache.camel.Message; //导入依赖的package包/类
private String parentFolderPathFor(Message message) throws Exception {
String customPath = message.getHeader(CamelCMISConstants.CMIS_FOLDER_PATH, String.class);
if (customPath != null) {
return customPath;
}
if (isFolder(message)) {
String path = (String) message.getHeader(PropertyIds.PATH);
String name = (String) message.getHeader(PropertyIds.NAME);
if (path != null && path.length() > name.length()) {
return path.substring(0, path.length() - name.length());
}
}
return "/";
}