use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.
the class BareInInterceptorTest method testInterceptorInbound.
@Test
public void testInterceptorInbound() throws Exception {
setUpUsingHelloWorld();
BareInInterceptor interceptor = new BareInInterceptor();
message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/GreetMeDocLiteralReq.xml")));
message.put(Message.INBOUND_MESSAGE, Message.INBOUND_MESSAGE);
interceptor.handleMessage(message);
assertNull(message.getContent(Exception.class));
List<?> parameters = message.getContent(List.class);
assertEquals(1, parameters.size());
Object obj = parameters.get(0);
assertTrue(obj instanceof GreetMe);
GreetMe greet = (GreetMe) obj;
assertEquals("TestSOAPInputPMessage", greet.getRequestType());
}
use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.
the class BareOutInterceptorTest method testWriteInbound.
@Test
public void testWriteInbound() throws Exception {
GreetMe greetMe = new GreetMe();
greetMe.setRequestType("requestType");
message.setContent(List.class, Arrays.asList(greetMe));
message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
interceptor.handleMessage(message);
writer.close();
assertNull(message.getContent(Exception.class));
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
XMLStreamReader xr = StaxUtils.createXMLStreamReader(bais);
DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
StaxUtils.toNextElement(reader);
assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "greetMe"), reader.getName());
StaxUtils.nextEvent(reader);
StaxUtils.toNextElement(reader);
assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"), reader.getName());
}
use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.
the class JAXBEncoderDecoderTest method testMarshallIntoDOM.
@Test
public void testMarshallIntoDOM() throws Exception {
String str = new String("Hello");
QName inCorrectElName = new QName("http://test_jaxb_marshall", "requestType");
MessagePartInfo part = new MessagePartInfo(inCorrectElName, null);
part.setElement(true);
part.setElementQName(inCorrectElName);
Document doc = DOMUtils.createDocument();
Element elNode = doc.createElementNS(inCorrectElName.getNamespaceURI(), inCorrectElName.getLocalPart());
assertNotNull(elNode);
Node node;
try {
JAXBEncoderDecoder.marshall(context.createMarshaller(), null, part, elNode);
fail("Should have thrown a Fault");
} catch (Fault ex) {
// expected - not a valid object
}
GreetMe obj = new GreetMe();
obj.setRequestType("Hello");
QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
part.setElementQName(elName);
JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, part, elNode);
node = elNode.getLastChild();
// The XML Tree Looks like
// <GreetMe><requestType>Hello</requestType></GreetMe>
assertEquals(Node.ELEMENT_NODE, node.getNodeType());
Node childNode = node.getFirstChild();
assertEquals(Node.ELEMENT_NODE, childNode.getNodeType());
childNode = childNode.getFirstChild();
assertEquals(Node.TEXT_NODE, childNode.getNodeType());
assertEquals(str, childNode.getNodeValue());
// Now test schema validation during marshaling
StringStruct stringStruct = new StringStruct();
// Don't initialize one of the structure members.
// stringStruct.setArg0("hello");
stringStruct.setArg1("world");
// Marshal without the schema should work.
JAXBEncoderDecoder.marshall(context.createMarshaller(), stringStruct, part, elNode);
try {
Marshaller m = context.createMarshaller();
m.setSchema(schema);
// Marshal with the schema should get an exception.
JAXBEncoderDecoder.marshall(m, stringStruct, part, elNode);
fail("Marshal with schema should have thrown a Fault");
} catch (Fault ex) {
// expected - not a valid object
}
}
use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.
the class JAXBEncoderDecoderTest method testUnmarshallFromStaxEventReader.
@Test
public void testUnmarshallFromStaxEventReader() throws Exception {
QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
MessagePartInfo part = new MessagePartInfo(elName, null);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
XMLInputFactory factory = XMLInputFactory.newInstance();
FixNamespacesXMLEventReader reader = new FixNamespacesXMLEventReader(factory.createXMLEventReader(is));
assertNull(reader.getUnmarshaller());
part.setTypeClass(GreetMe.class);
Unmarshaller um = context.createUnmarshaller();
Object val = JAXBEncoderDecoder.unmarshall(um, reader, part, true);
assertEquals(um, reader.getUnmarshaller());
assertNotNull(val);
assertTrue(val instanceof GreetMe);
assertEquals("TestSOAPInputPMessage", ((GreetMe) val).getRequestType());
is.close();
}
use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.
the class JAXBEncoderDecoderTest method setUp.
@Before
public void setUp() throws Exception {
context = JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class, StringStruct.class, ObjectWithQualifiedElementElement.class });
Method method = getMethod("greetMe");
wrapperAnnotation = method.getAnnotation(RequestWrapper.class);
InputStream is = getClass().getResourceAsStream("resources/StringStruct.xsd");
StreamSource schemaSource = new StreamSource(is);
assertNotNull(schemaSource);
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = factory.newSchema(schemaSource);
assertNotNull(schema);
}
Aggregations