Search in sources :

Example 6 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class CamelJaxbTest method testCustomXmlStreamWriterAndFiltering.

@Test
public void testCustomXmlStreamWriterAndFiltering() throws InterruptedException {
    PersonType person = new PersonType();
    person.setFirstName("foo");
    person.setLastName("bar");
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:marshalCustomWriterAndFiltering", person);
    resultEndpoint.assertIsSatisfied();
    String body = resultEndpoint.getReceivedExchanges().get(0).getIn().getBody(String.class);
    assertFalse("Non-xml character unexpectedly did not get into marshalled contents", body.contains(""));
    assertTrue("Body did not get processed correctly by custom filter", body.contains("-Foo"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PersonType(org.apache.camel.foo.bar.PersonType) Test(org.junit.Test)

Example 7 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class CamelJaxbTest method testMarshalWithSchemaLocation.

@Test
public void testMarshalWithSchemaLocation() throws Exception {
    PersonType person = new PersonType();
    person.setFirstName("foo");
    person.setLastName("bar");
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/xml");
    template.sendBody("direct:marshal", person);
    resultEndpoint.assertIsSatisfied();
    String body = resultEndpoint.getReceivedExchanges().get(0).getIn().getBody(String.class);
    assertTrue("We should get the schemaLocation here", body.contains("schemaLocation=\"person.xsd\""));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PersonType(org.apache.camel.foo.bar.PersonType) Test(org.junit.Test)

Example 8 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class MyPersonService method createPerson.

public void createPerson(Exchange exchange) {
    PersonType person = new PersonType();
    person.setFirstName("Homer");
    person.setLastName("Simpson");
    exchange.getOut().setBody(person);
}
Also used : PersonType(org.apache.camel.foo.bar.PersonType)

Example 9 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class MyPersonService method sendPerson.

public void sendPerson(Exchange exchange) {
    PersonType person = (PersonType) exchange.getIn().getBody();
    exchange.getContext().createProducerTemplate().sendBody("mock:person", person);
}
Also used : PersonType(org.apache.camel.foo.bar.PersonType)

Example 10 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class CamelJaxbFallbackConverterTest method testFilteringConverter.

@Test
public void testFilteringConverter() throws Exception {
    byte[] buffers = "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>".getBytes("UTF-8");
    InputStream is = new ByteArrayInputStream(buffers);
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
    exchange.setProperty(Exchange.FILTER_NON_XML_CHARS, true);
    TypeConverter converter = context.getTypeConverter();
    PersonType person = converter.convertTo(PersonType.class, exchange, is);
    assertNotNull("Person should not be null ", person);
    assertEquals("Get the wrong first name ", "FOO", person.getFirstName());
    assertEquals("Get the wrong second name ", "BAR ", person.getLastName());
    person.setLastName("BAR�");
    String value = converter.convertTo(String.class, exchange, person);
    assertTrue("Didn't filter the non-xml chars", value.indexOf("<lastName>BAR  </lastName>") > 0);
    exchange.setProperty(Exchange.FILTER_NON_XML_CHARS, false);
    value = converter.convertTo(String.class, exchange, person);
    assertTrue("Should not filter the non-xml chars", value.indexOf("<lastName>BAR�</lastName>") > 0);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) TypeConverter(org.apache.camel.TypeConverter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PersonType(org.apache.camel.foo.bar.PersonType) Test(org.junit.Test)

Aggregations

PersonType (org.apache.camel.foo.bar.PersonType)14 Test (org.junit.Test)12 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)10 Exchange (org.apache.camel.Exchange)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 TypeConverter (org.apache.camel.TypeConverter)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 JAXBElement (javax.xml.bind.JAXBElement)1 TypeConversionException (org.apache.camel.TypeConversionException)1