当前位置: 首页>>代码示例>>Java>>正文


Java Message.copyFrom方法代码示例

本文整理汇总了Java中org.apache.camel.Message.copyFrom方法的典型用法代码示例。如果您正苦于以下问题:Java Message.copyFrom方法的具体用法?Java Message.copyFrom怎么用?Java Message.copyFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.Message的用法示例。


在下文中一共展示了Message.copyFrom方法的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);
    }
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:27,代码来源:PLC4XProducer.java

示例2: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    try {
        Message in = exchange.getIn();

        @SuppressWarnings("unchecked")
        List<T> list = expression.evaluate(exchange, List.class);
        Collections.sort(list, comparator);

        if (exchange.getPattern().isOutCapable()) {
            Message out = exchange.getOut();
            out.copyFrom(in);
            out.setBody(list);
        } else {
            in.setBody(list);
        }
    } catch (Exception e) {
        exchange.setException(e);
    }

    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:SortProcessor.java

示例3: testCopyFromSameHeadersInstance

import org.apache.camel.Message; //导入方法依赖的package包/类
public void testCopyFromSameHeadersInstance() {
    Exchange exchange = new DefaultExchange(context);

    Message in = exchange.getIn();
    Map<String, Object> headers = in.getHeaders();
    headers.put("foo", 123);

    Message out = new DefaultMessage();
    out.setBody("Bye World");
    out.setHeaders(headers);

    out.copyFrom(in);

    assertEquals(123, headers.get("foo"));
    assertEquals(123, in.getHeader("foo"));
    assertEquals(123, out.getHeader("foo"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:MessageSupportTest.java

示例4: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception { //NOPMD
    InputStream stream = exchange.getIn().getMandatoryBody(InputStream.class);
    try {
        // lets setup the out message before we invoke the signing
        // so that it can mutate it if necessary
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());
        verify(stream, out);
        clearMessageHeaders(out);
    } catch (Exception e) {
        // remove OUT message, as an exception occurred
        exchange.setOut(null);
        throw e;
    } finally {
        IOHelper.close(stream, "input stream");
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:XmlVerifierProcessor.java

示例5: getMessageForResponse

import org.apache.camel.Message; //导入方法依赖的package包/类
private Message getMessageForResponse(Exchange exchange) {
	if (exchange.getPattern().isOutCapable()) {
		Message out = exchange.getOut();
		out.copyFrom(exchange.getIn());
		return out;
	}

	return exchange.getIn();
}
 
开发者ID:highsource,项目名称:aufzugswaechter,代码行数:10,代码来源:DynamicSnsProducer.java

示例6: toProcessor

import org.apache.camel.Message; //导入方法依赖的package包/类
@Converter
public static Processor toProcessor(final Predicate predicate) {
    return new Processor() {
        public void process(Exchange exchange) throws Exception {
            boolean answer = predicate.matches(exchange);
            Message out = exchange.getOut();
            out.copyFrom(exchange.getIn());
            out.setBody(answer);
        }
    };

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:CamelConverter.java

示例7: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    try {
        Object newBody = expression.evaluate(exchange, Object.class);

        if (exchange.getException() != null) {
            // the expression threw an exception so we should break-out
            callback.done(true);
            return true;
        }

        boolean out = exchange.hasOut();
        Message old = out ? exchange.getOut() : exchange.getIn();

        // create a new message container so we do not drag specialized message objects along
        // but that is only needed if the old message is a specialized message
        boolean copyNeeded = !(old.getClass().equals(DefaultMessage.class));

        if (copyNeeded) {
            Message msg = new DefaultMessage();
            msg.copyFrom(old);
            msg.setBody(newBody);

            // replace message on exchange
            ExchangeHelper.replaceMessage(exchange, msg, false);
        } else {
            // no copy needed so set replace value directly
            old.setBody(newBody);
        }

    } catch (Throwable e) {
        exchange.setException(e);
    }

    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:SetBodyProcessor.java

示例8: process

import org.apache.camel.Message; //导入方法依赖的package包/类
public boolean process(Exchange exchange, AsyncCallback callback) {
    ObjectHelper.notNull(dataFormat, "dataFormat");

    // if stream caching is enabled then use that so we can stream accordingly
    // for example to overflow to disk for big streams
    OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);

    Message in = exchange.getIn();
    Object body = in.getBody();

    // lets setup the out message before we invoke the dataFormat
    // so that it can mutate it if necessary
    Message out = exchange.getOut();
    out.copyFrom(in);

    try {
        dataFormat.marshal(exchange, body, osb);
        out.setBody(osb.build());
    } catch (Throwable e) {
        // remove OUT message, as an exception occurred
        exchange.setOut(null);
        exchange.setException(e);
    }

    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:MarshalProcessor.java

示例9: process

import org.apache.camel.Message; //导入方法依赖的package包/类
public boolean process(Exchange exchange, AsyncCallback callback) {
    ObjectHelper.notNull(dataFormat, "dataFormat");

    InputStream stream = null;
    Object result = null;
    try {
        stream = exchange.getIn().getMandatoryBody(InputStream.class);

        // lets setup the out message before we invoke the dataFormat so that it can mutate it if necessary
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());

        result = dataFormat.unmarshal(exchange, stream);
        if (result instanceof Exchange) {
            if (result != exchange) {
                // it's not allowed to return another exchange other than the one provided to dataFormat
                throw new RuntimeCamelException("The returned exchange " + result + " is not the same as " + exchange + " provided to the DataFormat");
            }
        } else if (result instanceof Message) {
            // the dataformat has probably set headers, attachments, etc. so let's use it as the outbound payload
            exchange.setOut((Message) result);
        } else {
            out.setBody(result);
        }
    } catch (Throwable e) {
        // remove OUT message, as an exception occurred
        exchange.setOut(null);
        exchange.setException(e);
    } finally {
        // The Iterator will close the stream itself
        if (!(result instanceof Iterator)) {
            IOHelper.close(stream, "input stream");
        }
    }
    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:UnmarshalProcessor.java

示例10: copyResultsPreservePattern

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Copies the <code>source</code> exchange to <code>target</code> exchange
 * preserving the {@link ExchangePattern} of <code>target</code>.
 *
 * @param source source exchange.
 * @param result target exchange.
 */
public static void copyResultsPreservePattern(Exchange result, Exchange source) {

    // --------------------------------------------------------------------
    //  TODO: merge logic with that of copyResults()
    // --------------------------------------------------------------------

    if (result == source) {
        // we just need to ensure MEP is as expected (eg copy result to OUT if out capable)
        // and the result is not failed
        if (result.getPattern() == ExchangePattern.InOptionalOut) {
            // keep as is
        } else if (result.getPattern().isOutCapable() && !result.hasOut() && !result.isFailed()) {
            // copy IN to OUT as we expect a OUT response
            result.getOut().copyFrom(source.getIn());
        }
        return;
    }

    // copy in message
    result.getIn().copyFrom(source.getIn());

    // copy out message
    if (source.hasOut()) {
        // exchange pattern sensitive
        Message resultMessage = source.getOut().isFault() ? result.getOut() : getResultMessage(result);
        resultMessage.copyFrom(source.getOut());
    }

    // copy exception
    result.setException(source.getException());

    // copy properties
    if (source.hasProperties()) {
        result.getProperties().putAll(source.getProperties());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:44,代码来源:ExchangeHelper.java

示例11: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception { //NOPMD

    try {
        LOG.debug("XML signature generation started using algorithm {} and canonicalization method {}", getConfiguration()
                .getSignatureAlgorithm(), getConfiguration().getCanonicalizationMethod().getAlgorithm());

        // lets setup the out message before we invoke the signing
        // so that it can mutate it if necessary
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());

        Document outputDoc = sign(out);

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        XmlSignatureHelper.transformNonTextNodeToOutputStream(outputDoc, outStream, omitXmlDeclaration(out), getConfiguration().getOutputXmlEncoding());
        byte[] data = outStream.toByteArray();
        out.setBody(data);
        setOutputEncodingToMessageHeader(out);
        clearMessageHeaders(out);
        LOG.debug("XML signature generation finished");
    } catch (Exception e) {
        // remove OUT message, as an exception occurred
        exchange.setOut(null);
        throw e;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:XmlSignerProcessor.java

示例12: getMessageForResponse

import org.apache.camel.Message; //导入方法依赖的package包/类
private Message getMessageForResponse(final Exchange exchange) {
    if (exchange.getPattern().isOutCapable()) {
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());
        return out;
    }
    return exchange.getIn();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:HipchatProducer.java

示例13: getMessageForResponse

import org.apache.camel.Message; //导入方法依赖的package包/类
private Message getMessageForResponse(Exchange exchange) {
    if (exchange.getPattern().isOutCapable()) {
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());
        return out;
    }

    return exchange.getIn();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:IronMQProducer.java

示例14: setResult

import org.apache.camel.Message; //导入方法依赖的package包/类
private void setResult(Exchange exchange, Object result) {
    Message message;
    if (exchange.getPattern().isOutCapable()) {
        message = exchange.getOut();
        message.copyFrom(exchange.getIn());
    } else {
        message = exchange.getIn();
    }
    message.setBody(result);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:AbstractRedisProcessorCreator.java

示例15: getMessageForResponse

import org.apache.camel.Message; //导入方法依赖的package包/类
public static Message getMessageForResponse(final Exchange exchange) {
    if (exchange.getPattern().isOutCapable()) {
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());
        return out;
    }
    return exchange.getIn();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:AwsExchangeUtil.java


注:本文中的org.apache.camel.Message.copyFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。