use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class Soap12ClientServerTest method testFaultMessage.
@Test
public void testFaultMessage() throws Exception {
Greeter greeter = getGreeter();
try {
greeter.sayHi();
fail("Should throw Exception!");
} catch (SOAPFaultException ex) {
assertEquals("sayHiFault Caused by: Get a wrong name <sayHi>", ex.getMessage());
StackTraceElement[] element = ex.getCause().getStackTrace();
assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl12", element[0].getClassName());
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class CircuitBreakerFailoverTest method testWithNoAlternativeEndpoints.
@Test
public void testWithNoAlternativeEndpoints() throws Exception {
final Greeter g = getGreeter(REPLICA_E);
try {
g.greetMe("fred");
fail("Expecting communication exception");
} catch (WebServiceException ex) {
assertThat(ex.getMessage(), equalTo("Could not send Message."));
}
try {
g.greetMe("fred");
fail("Expecting no alternative endpoints exception");
} catch (SOAPFaultException ex) {
assertThat(ex.getMessage(), equalTo("None of alternative addresses are available at the moment"));
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class WSAClientServerTest method testDuplicateHeaders.
// CXF-3456
@Test
public void testDuplicateHeaders() throws Exception {
URL wsdl = getClass().getResource("/wsdl_systest_wsspec/add_numbers.wsdl");
assertNotNull("WSDL is null", wsdl);
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
QName portName = new QName("http://apache.org/cxf/systest/ws/addr_feature/", "AddNumbersPort");
Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE, new AddressingFeature(false, false));
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/add");
InputStream msgIns = getClass().getResourceAsStream("./duplicate-wsa-header-msg.xml");
String msg = new String(IOUtils.readBytesFromStream(msgIns));
msg = msg.replaceAll("$PORT", PORT);
ByteArrayInputStream bout = new ByteArrayInputStream(msg.getBytes());
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, bout);
assertNotNull(soapReqMsg);
try {
disp.invoke(soapReqMsg);
fail("SOAPFaultFxception is expected");
} catch (SOAPFaultException ex) {
assertTrue("WSA header exception is expected", ex.getMessage().indexOf("A header representing a Message Addressing") > -1);
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class WSAFromJavaTest method testAddNumbersJaxWsContext.
@Test
public void testAddNumbersJaxWsContext() throws Exception {
ByteArrayOutputStream output = setupOutLogging();
AddNumberImpl port = getPort();
BindingProvider bp = (BindingProvider) port;
java.util.Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, "cxf");
try {
assertEquals(3, port.addNumbers(1, 2));
fail("Should have thrown an ActionNotSupported exception");
} catch (SOAPFaultException ex) {
// expected
}
assertLogContains(output.toString(), "//wsa:Action", "cxf");
assertTrue(output.toString(), output.toString().indexOf("SOAPAction=\"cxf\"") != -1);
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class WSAFromWSDLTest method testNonAnonToAnon.
@Test
public void testNonAnonToAnon() throws Exception {
try (AddNumbersPortTypeProxy port = getPort()) {
port.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/addAnon");
AddressingProperties maps = new AddressingProperties();
EndpointReferenceType ref = new EndpointReferenceType();
AttributedURIType add = new AttributedURIType();
add.setValue("http://localhost:" + INVALID_PORT + "/not/a/real/url");
ref.setAddress(add);
maps.setReplyTo(ref);
maps.setFaultTo(ref);
port.getRequestContext().put("javax.xml.ws.addressing.context", maps);
try {
port.addNumbers3(-1, 2);
} catch (SOAPFaultException e) {
assertTrue(e.getFault().getFaultCode().contains("OnlyAnonymousAddressSupported"));
}
}
}
Aggregations