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


Java ExchangeHelper.convertToMandatoryType方法代码示例

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


在下文中一共展示了ExchangeHelper.convertToMandatoryType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printImage

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
 * Writes the image file to the output stream.
 *
 * @param graph    the object graph
 * @param exchange the camel exchange
 * @param stream   the output stream
 */
private void printImage(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception {
    final String payload = ExchangeHelper
            .convertToMandatoryType(exchange, String.class, graph);
    final MultiFormatWriter writer = new MultiFormatWriter();

    // set values
    final String type = this.params.getType().toString();

    // create code image  
    final BitMatrix matrix = writer.encode(
            payload,
            this.params.getFormat(),
            this.params.getWidth(),
            this.params.getHeight(),
            writerHintMap);

    // write image back to stream
    MatrixToImageWriter.writeToStream(matrix, type, stream);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:BarcodeDataFormat.java

示例2: marshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    ObjectOutput out = ExchangeHelper.convertToMandatoryType(exchange, ObjectOutput.class, stream);
    try {
        out.writeObject(graph);
    } finally {
        out.flush();
        try {
            out.close();
        } catch (IOException e) {
            // ignore
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:SerializationDataFormat.java

示例3: unmarshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
    ObjectInput in = ExchangeHelper.convertToMandatoryType(exchange, ObjectInput.class, stream);
    try {
        return in.readObject();
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            // ignore
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:SerializationDataFormat.java

示例4: unmarshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
    String body = ExchangeHelper.convertToMandatoryType(exchange, String.class, inputStream);
    SyslogMessage message = SyslogConverter.parseMessage(body.getBytes());

    exchange.getOut().setHeader(SyslogConstants.SYSLOG_FACILITY, message.getFacility());
    exchange.getOut().setHeader(SyslogConstants.SYSLOG_SEVERITY, message.getSeverity());
    exchange.getOut().setHeader(SyslogConstants.SYSLOG_HOSTNAME, message.getHostname());
    // use java.util.Date as timestamp
    Date time = message.getTimestamp() != null ? message.getTimestamp().getTime() : null;
    if (time != null) {
        exchange.getOut().setHeader(SyslogConstants.SYSLOG_TIMESTAMP, time);
    }

    // Since we are behind the fact of being in an Endpoint...
    // We need to pull in the remote/local via either Mina or Netty.

    if (exchange.getIn().getHeader("CamelMinaLocalAddress") != null) {
        message.setLocalAddress(exchange.getIn().getHeader("CamelMinaLocalAddress", String.class));
        exchange.getOut().setHeader(SyslogConstants.SYSLOG_LOCAL_ADDRESS, message.getLocalAddress());
    }

    if (exchange.getIn().getHeader("CamelMinaRemoteAddress") != null) {
        message.setRemoteAddress(exchange.getIn().getHeader("CamelMinaRemoteAddress", String.class));
        exchange.getOut().setHeader(SyslogConstants.SYSLOG_REMOTE_ADDRESS, message.getRemoteAddress());
    }

    if (exchange.getIn().getHeader("CamelNettyLocalAddress") != null) {
        message.setLocalAddress(exchange.getIn().getHeader("CamelNettyLocalAddress", String.class));
        exchange.getOut().setHeader(SyslogConstants.SYSLOG_LOCAL_ADDRESS, message.getLocalAddress());
    }

    if (exchange.getIn().getHeader("CamelNettyRemoteAddress") != null) {
        message.setRemoteAddress(exchange.getIn().getHeader("CamelNettyRemoteAddress", String.class));
        exchange.getOut().setHeader(SyslogConstants.SYSLOG_REMOTE_ADDRESS, message.getRemoteAddress());
    }

    return message;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:40,代码来源:SyslogDataFormat.java

示例5: process

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
    Jaxp11XMLReaderCreator xmlCreator = new Jaxp11XMLReaderCreator();
    DefaultValidationErrorHandler errorHandler = new DefaultValidationErrorHandler();

    PropertyMapBuilder mapBuilder = new PropertyMapBuilder();
    mapBuilder.put(ValidateProperty.XML_READER_CREATOR, xmlCreator);
    mapBuilder.put(ValidateProperty.ERROR_HANDLER, errorHandler);
    PropertyMap propertyMap = mapBuilder.toPropertyMap();

    Validator validator = getSchema().createValidator(propertyMap);

    Message in = exchange.getIn();
    SAXSource saxSource = in.getBody(SAXSource.class);
    if (saxSource == null) {
        Source source = exchange.getIn().getMandatoryBody(Source.class);
        saxSource = ExchangeHelper.convertToMandatoryType(exchange, SAXSource.class, source);
    }
    InputSource bodyInput = saxSource.getInputSource();

    // now lets parse the body using the validator
    XMLReader reader = xmlCreator.createXMLReader();
    reader.setContentHandler(validator.getContentHandler());
    reader.setDTDHandler(validator.getDTDHandler());
    reader.setErrorHandler(errorHandler);
    reader.parse(bodyInput);

    errorHandler.handleErrors(exchange, schema);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:JingValidator.java

示例6: getRecordValues

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
private Iterable<?> getRecordValues(Exchange exchange, Object data) throws NoTypeConversionAvailableException {
    // each row must be a map or list based
    Map<?, ?> map = exchange.getContext().getTypeConverter().tryConvertTo(Map.class, exchange, data);
    if (map != null) {
        return getMapRecordValues(map);
    }
    return ExchangeHelper.convertToMandatoryType(exchange, List.class, data);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:CsvMarshaller.java

示例7: unmarshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
    byte[] body = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, inputStream);
    String charsetName = HL7Charset.getCharsetName(body, guessCharsetName(body, exchange));
    String bodyAsString = new String(body, charsetName);
    Message message = HL7Converter.parse(bodyAsString, parser);

    // add MSH fields as message out headers
    Terser terser = new Terser(message);
    for (Map.Entry<String, String> entry : HEADER_MAP.entrySet()) {
        exchange.getOut().setHeader(entry.getKey(), terser.get(entry.getValue()));
    }
    exchange.getOut().setHeader(HL7_CONTEXT, hapiContext);
    exchange.getOut().setHeader(Exchange.CHARSET_NAME, charsetName);
    return message;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:HL7DataFormat.java

示例8: calculateSignature

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void calculateSignature(Exchange exchange, Signature signer) throws Exception {
    Object payload = exchange.getIn().getBody();
    if (payload != null) {
        InputStream payloadStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, payload);
        try {
            byte[] buffer = new byte[config.getBufferSize()];
            int read;
            while ((read = payloadStream.read(buffer)) > 0) {
                signer.update(buffer, 0, read);
            }
        } finally {
            IOHelper.close(payloadStream);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:DigitalSignatureProcessor.java

示例9: marshalStreaming

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
private void marshalStreaming(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    InputStream decoded = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);

    Base64OutputStream base64Output = new Base64OutputStream(stream, true, lineLength, lineSeparator);
    try {
        IOHelper.copy(decoded, base64Output);
    } finally {
        IOHelper.close(decoded, base64Output);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:Base64DataFormat.java

示例10: marshalUrlSafe

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
private void marshalUrlSafe(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    byte[] decoded = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, graph);

    Base64 codec = new Base64(lineLength, lineSeparator, true);
    byte[] encoded = codec.encode(decoded);

    stream.write(encoded);
    stream.flush();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:Base64DataFormat.java

示例11: process

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    // use atomic integer to be able to pass reference and keep track on the values
    AtomicInteger index = new AtomicInteger();
    AtomicInteger count = new AtomicInteger();
    AtomicBoolean doWhile = new AtomicBoolean();

    try {
        if (expression != null) {
            // Intermediate conversion to String is needed when direct conversion to Integer is not available
            // but evaluation result is a textual representation of a numeric value.
            String text = expression.evaluate(exchange, String.class);
            int num = ExchangeHelper.convertToMandatoryType(exchange, Integer.class, text);
            count.set(num);
        } else {
            boolean result = predicate.matches(exchange);
            doWhile.set(result);
        }
    } catch (Exception e) {
        exchange.setException(e);
        callback.done(true);
        return true;
    }

    // we hold on to the original Exchange in case it's needed for copies
    final Exchange original = exchange;
    
    // per-iteration exchange
    Exchange target = exchange;

    // set the size before we start
    if (predicate == null) {
        exchange.setProperty(Exchange.LOOP_SIZE, count);
    }

    // loop synchronously
    while ((predicate != null && doWhile.get()) || (index.get() < count.get())) {

        // and prepare for next iteration
        // if (!copy) target = exchange; else copy of original
        target = prepareExchange(exchange, index.get(), original);
        // the following process method will in the done method re-evaluate the predicate
        // so we do not need to do it here as well
        boolean sync = process(target, callback, index, count, doWhile, original);

        if (!sync) {
            LOG.trace("Processing exchangeId: {} is continued being processed asynchronously", target.getExchangeId());
            // the remainder of the loop will be completed async
            // so we break out now, then the callback will be invoked which then continue routing from where we left here
            return false;
        }

        LOG.trace("Processing exchangeId: {} is continued being processed synchronously", target.getExchangeId());

        // check for error if so we should break out
        if (!continueProcessing(target, "so breaking out of loop", LOG)) {
            break;
        }
    }

    // we are done so prepare the result
    ExchangeHelper.copyResults(exchange, target);
    LOG.trace("Processing complete for exchangeId: {} >>> {}", exchange.getExchangeId(), exchange);
    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:67,代码来源:LoopProcessor.java

示例12: marshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception {
    SyslogMessage message = ExchangeHelper.convertToMandatoryType(exchange, SyslogMessage.class, body);
    stream.write(SyslogConverter.toString(message).getBytes());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:6,代码来源:SyslogDataFormat.java

示例13: marshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
    Message message = ExchangeHelper.convertToMandatoryType(exchange, Message.class, body);
    String charsetName = HL7Charset.getCharsetName(message, exchange);
    String encoded = HL7Converter.encode(message, parser);
    outputStream.write(encoded.getBytes(charsetName));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:HL7DataFormat.java

示例14: marshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void marshal(Exchange exchange, Object body, OutputStream out) throws Exception {
    SyndFeed feed = ExchangeHelper.convertToMandatoryType(exchange, SyndFeed.class, body);
    String xml = RssConverter.feedToXml(feed);
    out.write(xml.getBytes());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:6,代码来源:RssDataFormat.java

示例15: unmarshal

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public Object unmarshal(Exchange exchange, InputStream in) throws Exception {
    String xml = ExchangeHelper.convertToMandatoryType(exchange, String.class, in);
    return RssConverter.xmlToFeed(xml);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:5,代码来源:RssDataFormat.java


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