Java 类org.apache.camel.impl.DefaultMessage 实例源码

项目:vertx-camel-bridge    文件:CamelHelperTest.java   
@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();

}
项目:Camel    文件:SplitterPojoTest.java   
/**
 * The split message method returns something that is iteratable such as a java.util.List.
 *
 * @param header the header of the incoming message with the name user
 * @param body the payload of the incoming message
 * @return a list containing each part splitted
 */
public List<Message> splitMessage(@Header(value = "user") String header, @Body String body) {
    // we can leverage the Parameter Binding Annotations  
    // http://camel.apache.org/parameter-binding-annotations.html
    // to access the message header and body at same time, 
    // then create the message that we want, splitter will
    // take care rest of them.
    // *NOTE* this feature requires Camel version >= 1.6.1
    List<Message> answer = new ArrayList<Message>();
    String[] parts = header.split(",");
    for (String part : parts) {
        DefaultMessage message = new DefaultMessage();
        message.setHeader("user", part);
        message.setBody(body);
        answer.add(message);
    }
    return answer;
}
项目:Camel    文件:ObjectHelperTest.java   
public void testIteratorWithMessage() {
    Message msg = new DefaultMessage();
    msg.setBody("a,b,c");

    Iterator<?> it = ObjectHelper.createIterator(msg);
    assertEquals("a", it.next());
    assertEquals("b", it.next());
    assertEquals("c", it.next());
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("Should have thrown exception");
    } catch (NoSuchElementException nsee) {
        // expected
    }
}
项目:Camel    文件:DefaultUndertowHttpBinding.java   
@Override
public Message toCamelMessage(HttpServerExchange httpExchange, Exchange exchange) throws Exception {
    Message result = new DefaultMessage();

    populateCamelHeaders(httpExchange, result.getHeaders(), exchange);

    //extract body if the method is allowed to have one
    //body is extracted as byte[] then auto TypeConverter kicks in
    if (Methods.POST.equals(httpExchange.getRequestMethod()) || Methods.PUT.equals(httpExchange.getRequestMethod())) {
        result.setBody(readFromChannel(httpExchange.getRequestChannel()));
    } else {
        result.setBody(null);
    }

    return result;
}
项目:Camel    文件:ZipIterator.java   
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);
    }
}
项目:Camel    文件:SpringLdapProducerTest.java   
@Test
public void testSearch() throws Exception {
    String dn = "some dn";
    String filter = "filter";
    Integer scope = SearchControls.SUBTREE_SCOPE;

    Exchange exchange = new DefaultExchange(context);
    Message in = new DefaultMessage();

    Map<String, Object> body = new HashMap<String, Object>();
    body.put(SpringLdapProducer.DN, dn);
    body.put(SpringLdapProducer.FILTER, filter);

    when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.SEARCH);
    when(ldapEndpoint.scopeValue()).thenReturn(scope);

    processBody(exchange, in, body);
    verify(ldapTemplate).search(eq(dn), eq(filter), eq(scope),
            any(AttributesMapper.class));
}
项目:Camel    文件:SpringLdapProducerTest.java   
@Test
public void testBind() throws Exception {
    String dn = "some dn";
    BasicAttributes attributes = new BasicAttributes();

    Exchange exchange = new DefaultExchange(context);
    Message in = new DefaultMessage();

    Map<String, Object> body = new HashMap<String, Object>();
    body.put(SpringLdapProducer.DN, dn);
    body.put(SpringLdapProducer.ATTRIBUTES, attributes);

    when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.BIND);

    processBody(exchange, in, body);
    verify(ldapTemplate).bind(eq(dn), isNull(), eq(attributes));
}
项目:Camel    文件:CometdBinding.java   
public Message createCamelMessage(ServerSession remote, ServerMessage cometdMessage, Object data) {
    if (cometdMessage != null) {
        data = cometdMessage.getData();
    }

    Message message = new DefaultMessage();
    message.setBody(data);
    Map headers = getHeadersFromMessage(cometdMessage);
    if (headers != null) {
        message.setHeaders(headers);
    }
    message.setHeader(COMETD_CLIENT_ID_HEADER_NAME, remote.getId());

    if (cometdMessage != null && cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME) != null) {
        message.setHeader(COMETD_SUBSCRIPTION_HEADER_NAME, cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME));
    }

    if (enableSessionHeader) {
        addSessionAttributesToMessageHeaders(remote, message);
    }

    return message;
}
项目:Camel    文件:CometdProducerConsumerInOutInteractiveMain.java   
private RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() {
            CometdComponent component = (CometdComponent) context.getComponent("cometds");
            component.setSslPassword(pwd);
            component.setSslKeyPassword(pwd);
            File file = new File("./src/test/resources/jsse/localhost.ks");
            URI keyStoreUrl = file.toURI();
            component.setSslKeystore(keyStoreUrl.getPath());

            from(URI, URIS).setExchangePattern(ExchangePattern.InOut).process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    Message out = new DefaultMessage();
                    out.setBody("reply: " + exchange.getIn().getBody());
                    exchange.setOut(out);
                }
            });
        }
    };
}
项目:t5-doc    文件:ValidationErrorAckProcessorTest.java   
@Test
public void errSegmentsAreInjected() throws Exception {
    Exchange exchange = new DefaultExchange(camelContext);
    Message ackMessage = new DefaultMessage();
    ORU_R01 oruMessage = (ORU_R01) hapiContext.getGenericParser().parse(hl7Input);

    List<HL7Exception> validationErrors = new ArrayList<HL7Exception>();
    validationErrors.add(new ProfileNotFollowedException(VALIDATION_ERROR_TEXT));

    ACK ack = (ACK) oruMessage.generateACK(AcknowledgmentCode.AR, new ProfileNotFollowedException("desc"));
    ackMessage.setBody(ack);
    exchange.setIn(ackMessage);
    ackMessage.setHeader(ProfileValidationProcessor.VALIDATION_ERRORS_HEADER, validationErrors);
    ackMessage.setHeader(ProfileValidationProcessor.DEVICE_ID_LIST_HEADER, deviceIds);

    validationErrorAckProcessor.process(exchange);

    Terser terser = new Terser(ack);
    assertEquals(VALIDATION_ERROR_TEXT, terser.get("/ERR(0)-7"));
    assertEquals(MOCK_DEVICE, terser.get("/ERR(1)-7"));
}
项目:t5-doc    文件:TimeAdjustmentProcessorTest.java   
@Test
public void timeWithoutZoneIsChanged() throws Exception {
    Exchange exchange = new DefaultExchange(camelContext);
    Message message = new DefaultMessage();

    ORU_R01 oruMessage = (ORU_R01) hapiContext.getGenericParser().parse(hl7InputNoTimeZone);
    message.setBody(oruMessage);
    exchange.setIn(message);

    DTM messageDtm = oruMessage.getMSH().getDateTimeOfMessage();

    assertEquals(-99, messageDtm.getGMTOffset());
    assertEquals(MOCK_HOURS, messageDtm.getHour());

    timeAdjustmentProcessor.process(exchange);
    messageDtm = oruMessage.getMSH().getDateTimeOfMessage();

    assertEquals(200, messageDtm.getGMTOffset());
    assertEquals(MOCK_HOURS, messageDtm.getHour());

    DTM obrDtm = oruMessage.getPATIENT_RESULT(0).getORDER_OBSERVATION(0).getOBR().getObr7_ObservationDateTime();

    assertEquals(200, obrDtm.getGMTOffset());
    assertEquals(MOCK_HOURS, messageDtm.getHour());
}
项目:t5-doc    文件:TimeAdjustmentProcessorTest.java   
@Test
public void timeWithZoneIsNotChanged() throws Exception {
    Exchange exchange = new DefaultExchange(camelContext);
    Message message = new DefaultMessage();

    ORU_R01 oruMessage = (ORU_R01) hapiContext.getGenericParser().parse(hl7InputWithTimeZone);
    message.setBody(oruMessage);
    exchange.setIn(message);

    DTM messageDtm = oruMessage.getMSH().getDateTimeOfMessage();

    assertEquals(200, messageDtm.getGMTOffset());
    assertEquals(MOCK_HOURS, messageDtm.getHour());

    timeAdjustmentProcessor.process(exchange);
    messageDtm = oruMessage.getMSH().getDateTimeOfMessage();

    assertEquals(200, messageDtm.getGMTOffset());
    assertEquals(MOCK_HOURS, messageDtm.getHour());
}
项目:t5-doc    文件:TimeAdjustmentProcessorTest.java   
@Test
public void timeWithUtcZoneIsNotChanged() throws Exception {
    Exchange exchange = new DefaultExchange(camelContext);
    Message message = new DefaultMessage();

    ORU_R01 oruMessage = (ORU_R01) hapiContext.getGenericParser().parse(hl7InputWithUtcTimeZone);
    message.setBody(oruMessage);
    exchange.setIn(message);

    DTM messageDtm = oruMessage.getMSH().getDateTimeOfMessage();

    assertEquals(0, messageDtm.getGMTOffset());
    assertEquals(MOCK_HOURS, messageDtm.getHour());

    timeAdjustmentProcessor.process(exchange);
    messageDtm = oruMessage.getMSH().getDateTimeOfMessage();

    assertEquals(0, messageDtm.getGMTOffset());
    assertEquals(MOCK_HOURS, messageDtm.getHour());
}
项目:switchyard    文件:ExchangeMapper.java   
/**
 * Maps a SwitchYard exchange to a Camel exchange.  Keep in mind that the camel message created
 * during mapping is *not* associate with the exchange.  You need to call setIn() or setOut() 
 * with the returned reference depending on your use case.
 * @param syExchange switchyard exchange
 * @param camelExchange camel exchange
 * @return mapped camel message
 */
public static DefaultMessage mapSwitchYardToCamel(
        org.switchyard.Exchange syExchange,
        org.apache.camel.Exchange camelExchange) {

    DefaultMessage camelMessage = new SwitchYardMessage();
    camelMessage.setBody(syExchange.getMessage().getContent());

    mapSwitchYardPropertiesToCamel(syExchange.getContext(), camelExchange, camelMessage);

    for (String attachmentName : syExchange.getMessage().getAttachmentMap().keySet()) {
        camelMessage.addAttachment(attachmentName, 
                new DataHandler(syExchange.getMessage().getAttachment(attachmentName)));
    }

    return camelMessage;
}
项目:wildfly-camel    文件:OpenstackIntegrationTest.java   
@Test
public void createNeutronNetwork() throws Exception {
    CamelContext camelContext = Mockito.mock(CamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, dummyNetwork.getName());
    msg.setHeader(NeutronConstants.NETWORK_TYPE, dummyNetwork.getNetworkType());
    msg.setHeader(NeutronConstants.TENANT_ID, dummyNetwork.getTenantId());

    NeutronEndpoint endpoint = Mockito.mock(NeutronEndpoint.class);
    Producer producer = new NetworkProducer(endpoint, client);
    producer.process(exchange);

    ArgumentCaptor<Network> captor = ArgumentCaptor.forClass(Network.class);
    verify(networkService).create(captor.capture());

    assertEqualsNetwork(dummyNetwork, captor.getValue());
    assertNotNull(msg.getBody(Network.class).getId());
}
项目:wildfly-camel    文件:OpenstackIntegrationTest.java   
@Test
public void createKeystoneProject() throws Exception {
    CamelContext camelContext = Mockito.mock(CamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, dummyProject.getName());
    msg.setHeader(KeystoneConstants.DESCRIPTION, dummyProject.getDescription());
    msg.setHeader(KeystoneConstants.DOMAIN_ID, dummyProject.getDomainId());
    msg.setHeader(KeystoneConstants.PARENT_ID, dummyProject.getParentId());

    KeystoneEndpoint endpoint = Mockito.mock(KeystoneEndpoint.class);
    Producer producer = new ProjectProducer(endpoint, client);
    producer.process(exchange);

    ArgumentCaptor<Project> captor = ArgumentCaptor.forClass(Project.class);
    verify(projectService).create(captor.capture());

    assertEqualsProject(dummyProject, captor.getValue());
}
项目:wildfly-camel    文件:OpenstackIntegrationTest.java   
@Test
public void reserveGlanceImage() throws Exception {
    CamelContext camelContext = Mockito.mock(CamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    GlanceEndpoint endpoint = Mockito.mock(GlanceEndpoint.class);
    when(endpoint.getOperation()).thenReturn(GlanceConstants.RESERVE);

    Message msg = new DefaultMessage(camelContext);
    msg.setBody(dummyImage);

    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    Producer producer = new GlanceProducer(endpoint, client);
    producer.process(exchange);
    ArgumentCaptor<Image> captor = ArgumentCaptor.forClass(Image.class);
    verify(imageService).reserve(captor.capture());
    assertEquals(dummyImage, captor.getValue());

    Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
项目:wildfly-camel    文件:OpenstackIntegrationTest.java   
@Test
public void createCinderVolume() throws Exception {
    CamelContext camelContext = Mockito.mock(CamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    CinderEndpoint endpoint = Mockito.mock(CinderEndpoint.class);
    when(endpoint.getOperation()).thenReturn(OpenstackConstants.CREATE);
    msg.setBody(dummyVolume);

    Producer producer = new VolumeProducer(endpoint, client);
    producer.process(exchange);
    assertEqualVolumes(dummyVolume, msg.getBody(Volume.class));
}
项目:hazelcastmq    文件:DefaultMessageConverter.java   
/**
 * Converts from a Camel message to a HzMq message. The headers are simply
 * copied unmodified. The body is mapped by type:
 * <ul>
 * <li>If the content type is text/plain, the body is set as a String</li>
 * <li>all others: the body is set as a byte[] (or null)</li>
 * </ul>
 *
 * @param mqMsg the HzMq message to convert
 *
 * @return the new Camel message
 */
@Override
public Message toCamelMessage(HazelcastMQMessage mqMsg) {
  DefaultMessage camelMsg = new DefaultMessage();

  camelMsg.setHeaders((Map) mqMsg.getHeaders().getHeaderMap());

  if (mqMsg.getContentType() != null && mqMsg.getContentType().equals(
      "text/plain")) {
    camelMsg.setBody(mqMsg.getBodyAsString());
  }
  else {
    camelMsg.setBody(mqMsg.getBody());
  }

  return camelMsg;
}
项目:syndesis    文件:SalesforceConnectorTest.java   
@Before
public void setupConnector() throws Exception {
    connector.setCamelContext(context);
    connectorWithExistingProcessors.setCamelContext(context);

    final DefaultMessage out = new DefaultMessage(context);
    exchange.setOut(out);

    final DefaultConnectorEndpoint endpoint = (DefaultConnectorEndpoint) connector.createEndpoint("salesforce-connector");
    afterProducer = endpoint.getAfterProducer();
    beforeProducer = endpoint.getBeforeProducer();
}
项目:de.dentrassi.camel.milo    文件:MiloClientConsumer.java   
private Message mapMessage(final DataValue value) {
    if (value == null) {
        return null;
    }

    final DefaultMessage result = new DefaultMessage();

    Messages.fillFromDataValue(value, result);

    return result;
}
项目:de.dentrassi.camel.milo    文件:MiloServerConsumer.java   
private DefaultMessage mapToMessage(final DataValue value) {
    if (value == null) {
        return null;
    }

    final DefaultMessage result = new DefaultMessage();

    Messages.fillFromDataValue(value, result);

    return result;
}
项目:Camel    文件:SetBodyProcessor.java   
@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;
}
项目:Camel    文件:UnmarshalProcessorTest.java   
public void testDataFormatReturnsMessage() throws Exception {
    Exchange exchange = createExchangeWithBody(new DefaultCamelContext(), "body");
    Message out = new DefaultMessage();
    out.setBody(new Object());
    Processor processor = new UnmarshalProcessor(new MyDataFormat(out));

    processor.process(exchange);
    assertSame("UnmarshalProcessor did not make use of the returned OUT message", out, exchange.getOut());
    assertSame("UnmarshalProcessor did change the body bound to the OUT message", out.getBody(), exchange.getOut().getBody());
}
项目:Camel    文件:DefaultExchangeFormatterTest.java   
@Before
public void setUp() {
    camelContext = new DefaultCamelContext();
    Message message = new DefaultMessage();
    message.setBody("This is the message body");
    exchange = new DefaultExchange(camelContext);
    exchange.setIn(message);
    exchangeFormatter = new DefaultExchangeFormatter();
}
项目:Camel    文件:MessageHelperTest.java   
public void testCopyHeaders() throws Exception {
    Message source = message;
    Message target = new DefaultMessage();

    source.setHeader("foo", 123);
    source.setHeader("bar", 456);
    target.setHeader("bar", "yes");

    MessageHelper.copyHeaders(source, target, false);

    assertEquals(123, target.getHeader("foo"));
    assertEquals("yes", target.getHeader("bar"));
}
项目:Camel    文件:MessageHelperTest.java   
public void testCopyHeadersOverride() throws Exception {
    Message source = message;
    Message target = new DefaultMessage();

    source.setHeader("foo", 123);
    source.setHeader("bar", 456);
    target.setHeader("bar", "yes");

    MessageHelper.copyHeaders(source, target, true);

    assertEquals(123, target.getHeader("foo"));
    assertEquals(456, target.getHeader("bar"));
}
项目:Camel    文件:ObjectHelperTest.java   
public void testIteratorWithEmptyMessage() {
    Message msg = new DefaultMessage();
    msg.setBody("");

    Iterator<Object> it = ObjectHelper.createIterator(msg);
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("Should have thrown exception");
    } catch (NoSuchElementException nsee) {
        // expected
        assertEquals("no more element available for '' at the index 0", nsee.getMessage());
    }
}
项目:Camel    文件:ObjectHelperTest.java   
public void testIteratorWithNullMessage() {
    Message msg = new DefaultMessage();
    msg.setBody(null);

    Iterator<Object> it = ObjectHelper.createIterator(msg);
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("Should have thrown exception");
    } catch (NoSuchElementException nsee) {
        // expected
    }
}
项目:Camel    文件:BeanInfoOverloadedTest.java   
public void testBeanInfoOverloaded() throws Exception {
    BeanInfo beanInfo = new BeanInfo(context, Bean.class);

    Message message = new DefaultMessage();
    message.setBody(new RequestB());
    Exchange exchange = new DefaultExchange(context);
    exchange.setIn(message);

    MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange);
    Method method = methodInvocation.getMethod();

    assertEquals("doSomething", method.getName());

    assertEquals(RequestB.class, method.getGenericParameterTypes()[0]);
}
项目:Camel    文件:BeanInfoAMoreComplexOverloadedTest.java   
public void testRequestA() throws Exception {
    BeanInfo beanInfo = new BeanInfo(context, Bean.class);

    Message message = new DefaultMessage();
    message.setBody(new RequestA());
    Exchange exchange = new DefaultExchange(context);
    exchange.setIn(message);

    MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange);
    Method method = methodInvocation.getMethod();

    assertEquals("doSomething", method.getName());

    assertEquals(RequestA.class, method.getGenericParameterTypes()[0]);
}
项目:Camel    文件:BeanInfoAMoreComplexOverloadedTest.java   
public void testRequestB() throws Exception {
    BeanInfo beanInfo = new BeanInfo(context, Bean.class);

    Message message = new DefaultMessage();
    message.setBody(new RequestB());
    Exchange exchange = new DefaultExchange(context);
    exchange.setIn(message);

    MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange);
    Method method = methodInvocation.getMethod();

    assertEquals("doSomething", method.getName());

    assertEquals(RequestB.class, method.getGenericParameterTypes()[0]);
}
项目:Camel    文件:BeanInfoAMoreComplexOverloadedTest.java   
public void testAmbigious() throws Exception {
    BeanInfo beanInfo = new BeanInfo(context, Bean.class);

    Message message = new DefaultMessage();
    message.setBody("Hello World");
    Exchange exchange = new DefaultExchange(context);
    exchange.setIn(message);

    try {
        beanInfo.createInvocation(new Bean(), exchange);
        fail("Should have thrown an exception");
    } catch (AmbiguousMethodCallException e) {
        assertEquals(2, e.getMethods().size());
    }
}
项目:Camel    文件:DefaultCxfRsBindingTest.java   
@Test
public void testCopyProtocolHeader() {
    DefaultCxfRsBinding cxfRsBinding = new DefaultCxfRsBinding();
    cxfRsBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    Message camelMessage = new DefaultMessage();
    org.apache.cxf.message.Message cxfMessage = new MessageImpl();
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put("emptyList", Collections.EMPTY_LIST);
    headers.put("zeroSizeList", new ArrayList<String>(0));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    cxfRsBinding.copyProtocolHeader(cxfMessage, camelMessage, exchange);
    assertNull("We should get nothing here", camelMessage.getHeader("emptyList"));
    assertNull("We should get nothing here", camelMessage.getHeader("zeroSizeList"));
}
项目:Camel    文件:TarIterator.java   
private Message getNextElement() {
    if (tarInputStream == null) {
        return null;
    }

    try {
        TarArchiveEntry current = getNextEntry();

        if (current != null) {
            LOGGER.debug("Reading tarEntry {}", current.getName());
            Message answer = new DefaultMessage();
            answer.getHeaders().putAll(inputMessage.getHeaders());
            answer.setHeader(TARFILE_ENTRY_NAME_HEADER, current.getName());
            answer.setHeader(Exchange.FILE_NAME, current.getName());
            if (current.getSize() > 0) {
                answer.setBody(new TarElementInputStreamWrapper(tarInputStream));
            } else {
                // Workaround for the case when the entry is zero bytes big
                answer.setBody(new ByteArrayInputStream(new byte[0]));
            }
            return answer;
        } else {
            LOGGER.trace("Closed tarInputStream");
            return null;
        }
    } catch (IOException exception) {
        //Just wrap the IOException as CamelRuntimeException
        throw new RuntimeCamelException(exception);
    }
}
项目:Camel    文件:DockerConfigurationTest.java   
@Test
public void testPropertyFromHeader() {
    String host = "camelhost";

    Message message = new DefaultMessage();
    message.setHeader(DockerConstants.DOCKER_HOST, host);

    String configurationProp = DockerHelper.getProperty(DockerConstants.DOCKER_HOST, configuration, message, String.class);
    assertEquals(host, configurationProp);
}
项目:Camel    文件:DockerConfigurationTest.java   
@Test
public void testPropertyfromEndpointProperties() {
    String host = "camelhost";

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put(DockerHelper.transformFromHeaderName(DockerConstants.DOCKER_HOST), host);
    configuration.setParameters(parameters);

    Message message = new DefaultMessage();
    String configurationProp = DockerHelper.getProperty(DockerConstants.DOCKER_HOST, configuration, message, String.class);
    assertEquals(host, configurationProp);
}
项目:Camel    文件:DefaultUndertowHttpBinding.java   
@Override
public Message toCamelMessage(ClientExchange clientExchange, Exchange exchange) throws Exception {
    Message result = new DefaultMessage();

    //retrieve response headers
    populateCamelHeaders(clientExchange.getResponse(), result.getHeaders(), exchange);

    result.setBody(readFromChannel(clientExchange.getResponseChannel()));

    return result;
}
项目:Camel    文件:SplitAttachmentsExpression.java   
private Message extractAttachment(Message inMessage, String attachmentName) throws Exception {
    final Message outMessage = new DefaultMessage();
    outMessage.setHeader(HEADER_NAME, attachmentName);
    Object attachment = inMessage.getAttachment(attachmentName).getContent();
    if (attachment instanceof InputStream) {
        outMessage.setBody(readMimePart((InputStream) attachment));
        return outMessage;
    } else if (attachment instanceof String || attachment instanceof byte[]) {
        outMessage.setBody(attachment);
        return outMessage;
    } else {
        return null;
    }
}
项目:Camel    文件:SpringLdapProducerTest.java   
@Test(expected = NullPointerException.class)
public void testWrongBodyType() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    Message in = new DefaultMessage();
    in.setBody("");

    exchange.setIn(in);
    ldapProducer.process(exchange);
}