use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class ClientServerMiscTest method testDocLitBare.
@Test
public void testDocLitBare() throws Exception {
QName portName = new QName("http://cxf.apache.org/systest/jaxws/DocLitBareCodeFirstService", "DocLitBareCodeFirstServicePort");
QName servName = new QName("http://cxf.apache.org/systest/jaxws/DocLitBareCodeFirstService", "DocLitBareCodeFirstService");
// try without wsdl
Service service = Service.create(servName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, ServerMisc.DOCLITBARE_CODEFIRST_URL);
DocLitBareCodeFirstService port = service.getPort(portName, DocLitBareCodeFirstService.class);
DocLitBareCodeFirstService.GreetMeRequest req = new DocLitBareCodeFirstService.GreetMeRequest();
DocLitBareCodeFirstService.GreetMeResponse resp;
BigInteger[] i;
req.setName("Foo");
resp = port.greetMe(req);
assertEquals(req.getName(), resp.getName());
i = port.sayTest(new DocLitBareCodeFirstService.SayTestRequest("Dan"));
assertEquals(4, i.length);
assertEquals(0, i[0].intValue());
assertEquals(1, i[1].intValue());
assertEquals(2, i[2].intValue());
assertEquals(3, i[3].intValue());
// try with wsdl
service = Service.create(new URL(ServerMisc.DOCLITBARE_CODEFIRST_URL + "?wsdl"), servName);
port = service.getPort(portName, DocLitBareCodeFirstService.class);
resp = port.greetMe(req);
assertEquals(req.getName(), resp.getName());
// try the fault
req.setName("fault");
try {
resp = port.greetMe(req);
fail("did not get fault back");
} catch (SOAPFaultException ex) {
assertEquals("mr.actor", ex.getFault().getFaultActor());
assertEquals("test", ex.getFault().getDetail().getFirstChild().getLocalName());
}
req.setName("emptyfault");
try {
resp = port.greetMe(req);
fail("did not get fault back");
} catch (SOAPFaultException ex) {
assertNull(ex.getFault().getDetail());
}
// This test will pass/fail completely dependent on the versions of JAXB picked up and what
// version of Xerces is picked up. Newer versions of JAXB will generate "--11Z" (correct per XMLSchema)
// older version will generate "--11--Z". Xerces will only parse "--11--Z". The parser in the JDK
// will depend on the JDK version used.
/*
GMonthTest gm = new GMonthTest();
XMLGregorianCalendar dt = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(2010, 11, 16, 0);
gm.setValue(dt);
GMonthTest gm2 = port.echoGMonthTest(gm);
assertEquals(gm.getValue().getMonth(), gm2.getValue().getMonth());
*/
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class ClientServerRPCLitTest method testComplexType.
@Test
public void testComplexType() throws Exception {
SOAPServiceRPCLit service = new SOAPServiceRPCLit();
assertNotNull(service);
GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
updateAddressPort(greeter, PORT);
MyComplexStruct in = new MyComplexStruct();
in.setElem1("elem1");
in.setElem2("elem2");
in.setElem3(45);
try {
((BindingProvider) greeter).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
MyComplexStruct out = greeter.sendReceiveData(in);
assertNotNull("no response received from service", out);
assertEquals(in.getElem1(), out.getElem1());
assertEquals(in.getElem2(), out.getElem2());
assertEquals(in.getElem3(), out.getElem3());
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}
try {
in.setElem2("invalid");
greeter.sendReceiveData(in);
} catch (SOAPFaultException f) {
assertTrue(f.getCause() instanceof UnmarshalException);
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class DispatchClientServerTest method testTimeout.
@Test
public void testTimeout() throws Exception {
// CXF-2384
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
// pick one of the other service/ports that would have an address
// without a service running
QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
SOAPService service = new SOAPService(wsdl, otherServiceName);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + TestUtil.getPortNumber("fake-port") + "/SOAPDispatchService/SoapDispatchPort");
DispatchImpl<?> dispImpl = (DispatchImpl<?>) disp;
HTTPConduit cond = (HTTPConduit) dispImpl.getClient().getConduit();
cond.getClient().setConnectionTimeout(500);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
assertNotNull(soapReqMsg);
try {
disp.invoke(soapReqMsg);
fail("Should have faulted");
} catch (SOAPFaultException ex) {
fail("should not be a SOAPFaultException");
} catch (WebServiceException ex) {
// expected
assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.net.ConnectException || ex.getCause() instanceof java.net.SocketTimeoutException);
}
dispImpl.close();
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class DispatchClientServerTest method test404.
@Test
public void test404() throws Exception {
// CXF-2384
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
// pick one of the other service/ports that would have an address
// without a service running
QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
SOAPService service = new SOAPService(wsdl, otherServiceName);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SomePlaceWithNoServiceRunning/SoapDispatchPort");
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
assertNotNull(soapReqMsg);
try {
disp.invoke(soapReqMsg);
fail("Should have faulted");
} catch (SOAPFaultException ex) {
fail("should not be a SOAPFaultException");
} catch (WebServiceException ex) {
// expected
assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.io.IOException);
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class HandlerInvocationTest method testServerEndpointRemoteFault.
@Test
public void testServerEndpointRemoteFault() throws PingException {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleFault(LogicalMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
LogicalMessage msg = ctx.getMessage();
String payload = convertDOMToString(msg.getPayload());
assertTrue(payload.indexOf("<faultstring>" + "servant throws SOAPFaultException" + "</faultstring>") > -1);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
private String convertDOMToString(Source s) throws TransformerException {
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.transform(s, streamResult);
return stringWriter.toString();
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {
public boolean handleFault(SOAPMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
SOAPEnvelope env = ctx.getMessage().getSOAPPart().getEnvelope();
assertTrue("expected SOAPFault in SAAJ model", env.getBody().hasFault());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
try {
handlerTest.pingWithArgs("servant throw SOAPFaultException");
fail("did not get expected Exception");
} catch (SOAPFaultException sfe) {
// expected
}
assertEquals(1, handler1.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleMessageInvoked());
assertEquals(1, soapHandler1.getHandleMessageInvoked());
assertEquals(1, soapHandler2.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleFaultInvoked());
assertEquals(1, handler1.getHandleFaultInvoked());
assertEquals(1, soapHandler1.getHandleFaultInvoked());
assertEquals(1, soapHandler2.getHandleFaultInvoked());
assertEquals(1, handler1.getCloseInvoked());
assertEquals(1, handler2.getCloseInvoked());
assertEquals(1, soapHandler1.getCloseInvoked());
assertEquals(1, soapHandler2.getCloseInvoked());
assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
Aggregations