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"));
}
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\""));
}
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);
}
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);
}
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);
}
Aggregations