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


Java Message.setBody方法代码示例

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


在下文中一共展示了Message.setBody方法的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 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);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:25,代码来源:UnmarshallProcessor.java

示例3: 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);
}
 
开发者ID:syndesisio,项目名称:connectors,代码行数:17,代码来源:TweetToContactMapper.java

示例4: 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;
}
 
开发者ID:OrienteerBAP,项目名称:camel-orientdb,代码行数:21,代码来源:OrientDBProducer.java

示例5: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@SuppressWarnings({"unused", "unchecked"})
public void process(Exchange exchange) {
	Message in = exchange.getIn();
	Map<String, String> exchangeData = in.getBody(Map.class);
	String content_header = exchangeData.get("content_header");
	StringBuilder data = new StringBuilder();
	if(content_header != null) {
		data.append(START_DIV).append(HEADER_STYLE).append(content_header).append(END_DIV);
	}
	data.append(exchangeData.get("body"));
	String content_footer = exchangeData.get("content_footer");
	if(content_footer != null) {
		data.append(START_DIV).append(FOOTER_STYLE).append(content_footer).append(END_DIV);
	}
	exchangeData.put("body", data.toString());
	in.setBody(exchangeData);
}
 
开发者ID:LuatixHQ,项目名称:openex-worker,代码行数:18,代码来源:EmailHeaders.java

示例6: sendMultipartEmail

import org.apache.camel.Message; //导入方法依赖的package包/类
private void sendMultipartEmail(boolean useInlineattachments) throws Exception {
    Mailbox.clearAll();

    // create an exchange with a normal body and attachment to be produced as email
    MailEndpoint endpoint = context.getEndpoint("smtp://[email protected]?password=secret", MailEndpoint.class);
    endpoint.getConfiguration().setUseInlineAttachments(useInlineattachments);
    endpoint.getConfiguration().setAlternativeBodyHeader(MailConstants.MAIL_ALTERNATIVE_BODY);

    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody(htmlBody);
    in.setHeader(MAIL_ALTERNATIVE_BODY, alternativeBody);
    in.addAttachment("cid:myCoolLogo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

    // create a producer that can produce the exchange (= send the mail)
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.message(0).header(MailConstants.MAIL_ALTERNATIVE_BODY).isNull();

    context.createProducerTemplate().send(endpoint, exchange);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MimeMultipartAlternativeWithLongerFilenameTest.java

示例7: getNextElement

import org.apache.camel.Message; //导入方法依赖的package包/类
private Message getNextElement() {
    if (zipInputStream == null) {
        return null;
    }
    
    try {
        ZipEntry current = getNextEntry();

        if (current != null) {
            LOGGER.debug("read zipEntry {}", current.getName());
            Message answer = new DefaultMessage();
            answer.getHeaders().putAll(inputMessage.getHeaders());
            answer.setHeader("zipFileName", current.getName());
            answer.setHeader(Exchange.FILE_NAME, current.getName());
            answer.setBody(new ZipInputStreamWrapper(zipInputStream));
            return answer;
        } else {
            LOGGER.trace("close zipInputStream");
            return null;
        }
    } catch (IOException exception) {
        //Just wrap the IOException as CamelRuntimeException
        throw new RuntimeCamelException(exception);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:ZipIterator.java

示例8: describeInstances

import org.apache.camel.Message; //导入方法依赖的package包/类
private void describeInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    } 
    DescribeInstancesResult result;
    try {
        result = ec2Client.describeInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Describe Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    Message message = getMessageForResponse(exchange);
    message.setBody(result);        
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:EC2Producer.java

示例9: jsonMarshalIfRequired

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Lets marshal the body to JSON using Jackson if we require it.
 * <br>
 * The current rules are to only marshal to JSON if we don't have a {@link Exchange#CONTENT_TYPE} header.
 * If we can convert the body to a String then we test if its already JSON and if not we marshal it using the JSON
 * data format with the Jackson library
 */
public void jsonMarshalIfRequired(Exchange exchange) throws Exception {
    Message in = exchange.getIn();
    if (in == null) {
        return;
    }
    String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class);
    if (!Strings.isEmpty(contentType)) {
        // lets preserve existing content types as it could be XML, YAML or something else
        return;
    }
    Object body = in.getBody();
    if (body != null) {
        if (isPossibleJsonClass(exchange, body.getClass(), body)) {
            try {
                String text = in.getBody(String.class);
                if (text != null) {
                    if (isJsonLookingString(text.trim())) {
                        in.setHeader(Exchange.CONTENT_TYPE, JSON_CONTENT_TYPE);
                    }
                    in.setBody(text);
                    return;
                }
            } catch (Exception e) {
                // ignore
            }
        }

        in.setHeader(Exchange.CONTENT_TYPE, JSON_CONTENT_TYPE);

        jsonMarshalProducer.process(exchange);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:40,代码来源:JsonEndpoint.java

示例10: process

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

    final String body = in.getBody(String.class);
    if (body == null) {
        return;
    }

    final JsonNode payload;
    try {
        payload = MAPPER.readTree(body);
    } catch (final JsonProcessingException e) {
        LOG.warn("Unable to parse payload, continuing without conversion", e);

        return;
    }

    payload.with("parameters").fields().forEachRemaining(e -> in.setHeader(e.getKey(), e.getValue().asText()));

    final JsonNode requestBody = payload.get("body");
    if (requestBody == null) {
        in.setBody(null);
    } else {
        in.setBody(MAPPER.writeValueAsString(requestBody));
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:28,代码来源:PayloadConverter.java

示例11: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(final Exchange exchange) throws Exception {
    // parse input json and extract Id field
    final Message in = exchange.getIn();
    final String body = in.getBody(String.class);

    if (body == null) {
        return;
    }

    final ObjectNode node = (ObjectNode) MAPPER.readTree(body);

    final String idPropertyName = determineIdProperty(exchange);

    final JsonNode idProperty = node.remove(idPropertyName);
    if (idProperty == null) {
        exchange.setException(
            new SalesforceException("Missing option value for Id or " + SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, 404));

        return;
    }

    final String idValue = idProperty.textValue();
    if ("Id".equals(idPropertyName)) {
        in.setHeader(SalesforceEndpointConfig.SOBJECT_ID, idValue);
    } else {
        in.setHeader(SalesforceEndpointConfig.SOBJECT_EXT_ID_VALUE, idValue);
    }

    // base fields are not allowed to be updated
    clearBaseFields(node);

    // update input json
    in.setBody(MAPPER.writeValueAsString(node));
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:36,代码来源:AdaptObjectForUpdateProcessor.java

示例12: shouldNotConvertFailedExchanges

import org.apache.camel.Message; //导入方法依赖的package包/类
@Test
public void shouldNotConvertFailedExchanges() throws Exception {
    final Message out = exchange.getOut();
    out.setBody("wat");

    exchange.setException(new Exception());
    afterProducer.process(exchange);

    assertThat(out.getBody()).isEqualTo("wat");
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:SalesforceConnectorTest.java

示例13: shouldUnmarshallToSpecifiedInputType

import org.apache.camel.Message; //导入方法依赖的package包/类
@Test
public void shouldUnmarshallToSpecifiedInputType() throws Exception {
    final Message in = exchange.getIn();
    in.setBody("{}");

    beforeProducer.process(exchange);

    assertThat(in.getBody()).isInstanceOf(SalesforceIdentifier.class);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:10,代码来源:SalesforceConnectorTest.java

示例14: shouldUnmarshallToSpecifiedOutputType

import org.apache.camel.Message; //导入方法依赖的package包/类
@Test
public void shouldUnmarshallToSpecifiedOutputType() throws Exception {
    final Message out = exchange.getOut();
    out.setBody("{}");

    afterProducer.process(exchange);

    assertThat(out.getBody()).isInstanceOf(AbstractDTOBase.class);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:10,代码来源:SalesforceConnectorTest.java

示例15: process

import org.apache.camel.Message; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
	
	Message in = exchange.getIn();
	Map<String,Object> tuple= (Map<String, Object>) in.getBody();
	MoneyTransfer mt = new  MoneyTransfer();
	mt.setId((Long)tuple.get(MoneyTransfer.FIELD_ID));
	mt.setKeycode((String)tuple.get(MoneyTransfer.FIELD_KEYCODE));
	mt.setPaymentMethod((String)tuple.get(MoneyTransfer.FIELD_PAYMENT_METHOD));
	mt.setAmount_hf_sender_currency((BigDecimal)tuple.get(MoneyTransfer.FIELD_AMOUNT_HF_SENDER_CUR));
	mt.setStatus((String)tuple.get(MoneyTransfer.FIELD_STATUS));
	in.setBody(mt);
	in.setHeader(InfinispanConstants.KEY, mt.getKeycode());

}
 
开发者ID:PacktPublishing,项目名称:JBoss-Developers-Guide,代码行数:15,代码来源:AFProcessor.java


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