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


Java Message.getHeader方法代码示例

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


在下文中一共展示了Message.getHeader方法的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 void process(Exchange exchange) throws Exception {
    Message in = exchange.getIn();
    Object message = in.getMandatoryBody();
    if (!(message == null || message instanceof String || message instanceof byte[])) {
        message = in.getMandatoryBody(String.class);
    }
    if (isSendToAllSet(in)) {
        sendToAll(store, message, exchange);
    } else {
        // look for connection key and get Websocket
        String connectionKey = in.getHeader(WebsocketConstants.CONNECTION_KEY, String.class);
        if (connectionKey != null) {
            DefaultWebsocket websocket = store.get(connectionKey);
            log.debug("Sending to connection key {} -> {}", connectionKey, message);
            sendMessage(websocket, message);
        } else {
            throw new IllegalArgumentException("Failed to send message to single connection; connetion key not set.");
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:WebsocketProducer.java

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

示例4: 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 "/";
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:CMISProducer.java

示例5: testConsumerTemplate

import org.apache.camel.Message; //导入方法依赖的package包/类
@Test
public void testConsumerTemplate() throws Exception {
    template.sendBodyAndHeader("activemq:queue:consumer", "Message1", "SIZE_NUMBER", 1505);
    template.sendBodyAndHeader("activemq:queue:consumer", "Message3", "SIZE_NUMBER", 1300);
    template.sendBodyAndHeader("activemq:queue:consumer", "Message2", "SIZE_NUMBER", 1600);

    // process every exchange which is ready. If no exchange is left break
    // the loop
    while (true) {
        Exchange ex = consumer.receiveNoWait("activemq:queue:consumer?selector=SIZE_NUMBER<1500");
        if (ex != null) {
            Message message = ex.getIn();
            int size = message.getHeader("SIZE_NUMBER", int.class);
            assertTrue("The message header SIZE_NUMBER should be less than 1500", size < 1500);
            assertEquals("The message body is wrong", "Message3", message.getBody());
        } else {
            break;
        }
    }

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

示例6: 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());
    }
    
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:CxfRsConsumerTest.java

示例7: execute

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
void execute(InfinispanConfiguration configuration, BasicCache<Object, Object> cache, Message message) {
    NotifyingFuture result;
    if (hasLifespan(message)) {
        long lifespan = message.getHeader(InfinispanConstants.LIFESPAN_TIME, long.class);
        TimeUnit timeUnit =  message.getHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.class);
        if (hasMaxIdleTime(message)) {
            long maxIdle = message.getHeader(InfinispanConstants.MAX_IDLE_TIME, long.class);
            TimeUnit maxIdleTimeUnit =  message.getHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.class);
            result = cache.putAllAsync(getMap(message), lifespan, timeUnit, maxIdle, maxIdleTimeUnit);
        } else {
            result = cache.putAllAsync(getMap(message), lifespan, timeUnit);
        }
    } else {
        result = cache.putAllAsync(getMap(message));
    }
    setResult(result, message);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:InfinispanOperation.java

示例8: execute

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
void execute(Cache<Object, Object> cache, Exchange exchange) {
    Message message = exchange.getIn();
    Set<Object> keys = message.getHeader(JCacheConstants.KEYS, Set.class);
    EntryProcessor<Object, Object, Object> entryProcessor = message.getHeader(JCacheConstants.ENTRY_PROCESSOR, EntryProcessor.class);

    Collection<Object> arguments = message.getHeader(JCacheConstants.ARGUMENTS, Collection.class);
    if (arguments == null) {
        arguments = Collections.emptyList();
    }

    message.setBody(
        keys != null
            ? cache.invokeAll(
                keys,
                entryProcessor,
                arguments)
            : cache.invoke(
                exchange.getIn().getHeader(JCacheConstants.KEY),
                entryProcessor,
                arguments)
    );
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:JCacheProducer.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: doWriteResponse

import org.apache.camel.Message; //导入方法依赖的package包/类
public void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
    // set the status code in the response. Default is 200.
    if (message.getHeader(Exchange.HTTP_RESPONSE_CODE) != null) {
        int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
        response.setStatus(code);
    }
    // set the content type in the response.
    String contentType = MessageHelper.getContentType(message);
    if (contentType != null) {
        response.setContentType(contentType);
    }

    // append headers
    // must use entrySet to ensure case of keys is preserved
    for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        // use an iterator as there can be multiple values. (must not use a delimiter)
        final Iterator<?> it = ObjectHelper.createIterator(value, null);
        while (it.hasNext()) {
            String headerValue = convertHeaderValueToString(exchange, it.next());
            if (headerValue != null && headerFilterStrategy != null
                    && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, exchange)) {
                response.addHeader(key, headerValue);
            }
        }
    }

    // write the body.
    if (message.getBody() != null) {
        if (GZIPHelper.isGzip(message)) {
            doWriteGZIPResponse(message, response, exchange);
        } else {
            doWriteDirectResponse(message, response, exchange);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:DefaultHttpBinding.java

示例11: checkChunked

import org.apache.camel.Message; //导入方法依赖的package包/类
protected boolean checkChunked(Message message, Exchange exchange) {
    boolean answer = true;
    if (message.getHeader(Exchange.HTTP_CHUNKED) == null) {
        // check the endpoint option
        Endpoint endpoint = exchange.getFromEndpoint();
        if (endpoint instanceof HttpCommonEndpoint) {
            answer = ((HttpCommonEndpoint)endpoint).isChunked();
        }
    } else {
        answer = message.getHeader(Exchange.HTTP_CHUNKED, boolean.class);
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:DefaultHttpBinding.java

示例12: toServletRequest

import org.apache.camel.Message; //导入方法依赖的package包/类
@Converter
public static HttpServletRequest toServletRequest(Message message) {
    if (message == null) {
        return null;
    }
    return message.getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:HttpConverter.java

示例13: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
	Message message = exchange.getIn();
	
	String messageType = message.getHeader(SmppConstants.MESSAGE_TYPE, String.class);
	if (messageType != null) {
		if(messageType.equals(SmppMessageType.DeliverSm.toString())) {
			handleDeliverSM(exchange);
		}
	} else {
		handleOutgoingMessage(exchange);
	}
}
 
开发者ID:opentelecoms-org,项目名称:smsrouter,代码行数:14,代码来源:SmppAddressing.java

示例14: getSchemaResourceUri

import org.apache.camel.Message; //导入方法依赖的package包/类
protected String getSchemaResourceUri(Message message) {
    String schemaResourceUri = message.getHeader(XmlSignatureConstants.HEADER_SCHEMA_RESOURCE_URI, String.class);
    if (schemaResourceUri == null) {
        schemaResourceUri = getConfiguration().getSchemaResourceUri();
    }
    LOG.debug("schema resource URI: {} ", getConfiguration().getSchemaResourceUri());
    return schemaResourceUri;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:XmlSignatureProcessor.java

示例15: getArrayProperty

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Attempts to locate a given property which is an array by name within a URI parameter or the message header.
 * A found value in a message header takes precedence over a URI parameter.
 *
 * @param name
 * @param message
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T[] getArrayProperty(String name, Message message, Class<T> clazz) {

    if (message != null) {
        Object header = message.getHeader(name);

        if (header != null) {
            if (header.getClass().isAssignableFrom(clazz)) {

                T[] headerArray = (T[]) Array.newInstance(clazz, 1);
                headerArray[0] = (T) header;
                return headerArray;

            }

            if (header.getClass().isArray()) {
                if (header.getClass().getComponentType().isAssignableFrom(clazz) || header.getClass().getDeclaringClass().isAssignableFrom(clazz)) {
                    return (T[]) header;
                }
            }
        }

    }

    return null;

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


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