use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class ClientServerMiscTest method testExceptionCases.
private void testExceptionCases(DocLitWrappedCodeFirstService port) throws Exception {
/* CXF-926 test case */
try {
port.throwException(10);
fail("Expected exception not found");
} catch (ServiceTestFault ex) {
assertEquals(10L, ex.getFaultInfo().getId());
}
// CXF-1131 testcase
try {
port.throwException(-1);
fail("Expected exception not found");
} catch (ServiceTestFault ex) {
assertNull(ex.getFaultInfo());
}
// CXF-1136 testcase
try {
port.throwException(-2);
fail("Expected exception not found");
} catch (CustomException ex) {
assertEquals("CE: -2", ex.getMessage());
assertEquals("A Value", ex.getA());
assertEquals("B Value", ex.getB());
}
// CXF-1407
try {
port.throwException(-3);
fail("Expected exception not found");
} catch (ComplexException ex) {
assertEquals("Throw user fault -3", ex.getMessage());
assertEquals(3, ex.getInts().length);
}
try {
port.throwException(-3);
fail("Expected exception not found");
} catch (ComplexException ex) {
assertEquals("Throw user fault -3", ex.getMessage());
}
try {
port.throwException(-4);
fail("Expected exception not found");
} catch (WebServiceException ex) {
assertEquals("RuntimeException!!", ex.getMessage());
}
try {
Foo foo = new Foo();
foo.setNameIgnore("DoNoName");
port.modifyFoo(foo);
fail("Expected exception not found");
} catch (SOAPFaultException ex) {
assertTrue(ex.getMessage(), ex.getMessage().contains("NoName is not a valid name"));
}
try {
Foo foo = new Foo();
foo.setNameIgnore("NoName");
port.modifyFoo(foo);
fail("Expected exception not found");
} catch (SOAPFaultException ex) {
assertTrue(ex.getMessage().contains("NoName is not a valid name"));
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class DocLitBareCodeFirstServiceImpl method greetMe.
public GreetMeResponse greetMe(GreetMeRequest gmr) {
if ("fault".equals(gmr.getName())) {
try {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault fault = factory.createFault("this is a fault string!", new QName("http://foo", "FooCode"));
fault.setFaultActor("mr.actor");
fault.addDetail().addChildElement("test").addTextNode("TestText");
throw new SOAPFaultException(fault);
} catch (SOAPException ex) {
throw new WebServiceException(ex);
}
} else if ("emptyfault".equals(gmr.getName())) {
throw new RuntimeException("Empty!");
}
GreetMeResponse resp = new GreetMeResponse();
resp.setName(gmr.getName());
return resp;
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class JAXRSClientServerValidationSpringTest method testHelloSoapValidationFailsIfNameIsNull.
@Test
public void testHelloSoapValidationFailsIfNameIsNull() throws Exception {
final QName serviceName = new QName("http://bookworld.com", "BookWorld");
final QName portName = new QName("http://bookworld.com", "BookWorldPort");
final String address = "http://localhost:" + PORT + "/bwsoap";
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
BookWorld bwService = service.getPort(BookWorld.class);
BookWithValidation bw = bwService.echoBook(new BookWithValidation("WS", "123"));
assertEquals("123", bw.getId());
try {
bwService.echoBook(new BookWithValidation(null, "123"));
fail("Validation failure expected");
} catch (SOAPFaultException ex) {
// complete
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class DispatchHandlerInvocationTest method testInvokeWithSOAPMessagePayloadMode.
@Test
public void testInvokeWithSOAPMessagePayloadMode() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
assertNotNull(wsdl);
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Mode.PAYLOAD);
setAddress(disp, addNumbersAddress);
TestHandler handler = new TestHandler();
TestSOAPHandler soapHandler = new TestSOAPHandler();
addHandlersProgrammatically(disp, handler, soapHandler);
InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapReq = factory.createMessage(null, is2);
try {
disp.invoke(soapReq);
fail("Did not get expected exception");
} catch (SOAPFaultException e) {
assertTrue("Did not get expected exception message: " + e.getMessage(), e.getMessage().indexOf("is not valid in PAYLOAD mode with SOAP/HTTP binding") > -1);
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class InterceptorFaultTest method testRobustFailWithoutAddressingInUserLogicalPhase.
@Test
public void testRobustFailWithoutAddressingInUserLogicalPhase() throws Exception {
setupGreeter("org/apache/cxf/systest/interceptor/no-addr.xml", false);
control.setRobustInOnlyMode(true);
// behaviour is identicial for all phases
FaultLocation location = new org.apache.cxf.greeter_control.types.ObjectFactory().createFaultLocation();
location.setPhase("user-logical");
control.setFaultLocation(location);
try {
// writer to grab the content of soap fault.
// robust is not yet used at client's side, but I think it should
StringWriter writer = new StringWriter();
((Client) greeter).getInInterceptors().add(new LoggingInInterceptor(new PrintWriterEventSender(new PrintWriter(writer))));
// it should tell CXF to convert one-way robust out faults into real SoapFaultException
((Client) greeter).getEndpoint().put(Message.ROBUST_ONEWAY, true);
greeter.greetMeOneWay("oneway");
fail("Oneway operation unexpectedly succeded for phase " + location.getPhase());
} catch (SOAPFaultException ex) {
// expected
}
}
Aggregations