use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class HandlerInvocationTest method testSOAPHandlerHandleMessageThrowsSOAPFaultExceptionServerInbound.
@Test
public void testSOAPHandlerHandleMessageThrowsSOAPFaultExceptionServerInbound() throws PingException {
try {
handlerTest.pingWithArgs("soapHandler3 inbound throw SOAPFaultExceptionWDetail");
fail("did not get expected SOAPFaultException");
} catch (SOAPFaultException e) {
assertEquals("HandleMessage throws exception", e.getMessage());
SOAPFault fault = e.getFault();
assertNotNull(fault);
assertEquals(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server"), fault.getFaultCodeAsQName());
assertEquals("http://gizmos.com/orders", fault.getFaultActor());
Detail detail = fault.getDetail();
assertNotNull(detail);
QName nn = new QName("http://gizmos.com/orders/", "order");
Element el = DOMUtils.getFirstChildWithName(detail, nn);
assertNotNull(el);
el.normalize();
assertEquals("Quantity element does not have a value", el.getFirstChild().getNodeValue());
el = DOMUtils.getNextElement(el);
el.normalize();
assertEquals("Incomplete address: no zip code", el.getFirstChild().getNodeValue());
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class DispatchSourceClient method main.
public static void main(String[] args) throws Exception {
Server.main(new String[] { "inProcess" });
Service service = Service.create(SERVICE_NAME);
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, ADDRESS);
Dispatch<Source> dispatch = service.createDispatch(PORT_NAME, Source.class, Service.Mode.PAYLOAD);
String resp;
Source response;
System.out.println("Invoking sayHi...");
setOperation(dispatch, SAYHI_OPERATION_NAME);
response = dispatch.invoke(encodeSource(SAYHI_REQUEST_TEMPLATE, null));
resp = decodeSource(response, PAYLOAD_NAMESPACE_URI, "responseType");
System.out.println("Server responded with: " + resp);
System.out.println();
System.out.println("Invoking greetMe...");
setOperation(dispatch, GREETME_OPERATION_NAME);
response = dispatch.invoke(encodeSource(GREETME_REQUEST_TEMPLATE, System.getProperty("user.name")));
resp = decodeSource(response, PAYLOAD_NAMESPACE_URI, "responseType");
System.out.println("Server responded with: " + resp);
System.out.println();
try {
System.out.println("Invoking pingMe, expecting exception...");
setOperation(dispatch, PINGME_OPERATION_NAME);
response = dispatch.invoke(encodeSource(PINGME_REQUEST_TEMPLATE, null));
} catch (SOAPFaultException ex) {
System.out.println("Expected exception: SoapFault has occurred: " + ex.getMessage());
}
System.exit(0);
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class JMSWSSecurityTest method testUnsignedSAML2AudienceRestrictionTokenBadURI.
@Test
public void testUnsignedSAML2AudienceRestrictionTokenBadURI() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
HelloWorldService service = new HelloWorldService(wsdl, serviceName);
HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
callbackHandler.setSignAssertion(true);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
ConditionsBean conditions = new ConditionsBean();
conditions.setTokenPeriodMinutes(5);
List<String> audiences = new ArrayList<>();
audiences.add("jms:jndi:dynamicQueues/test.jmstransport.text.bad");
AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
audienceRestrictionBean.setAudienceURIs(audiences);
conditions.setAudienceRestrictions(Collections.singletonList(audienceRestrictionBean));
callbackHandler.setConditions(conditions);
Map<String, Object> outProperties = new HashMap<>();
outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
outProperties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProperties);
Client client = ClientProxy.getClient(greeter);
client.getOutInterceptors().add(outInterceptor);
try {
greeter.sayHi();
fail("Failure expected on a bad audience restriction");
} catch (SOAPFaultException ex) {
// expected
}
((java.io.Closeable) greeter).close();
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class BraveTracingTest method testThatNewSpanIsCreatedInCaseOfFault.
@Test
public void testThatNewSpanIsCreatedInCaseOfFault() throws MalformedURLException {
final BookStoreService service = createJaxWsService();
try {
service.removeBooks();
fail("Expected SOAPFaultException to be raised");
} catch (final SOAPFaultException ex) {
/* expected exception */
}
assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1));
assertThat(TestSpanReporter.getAllSpans().get(0).name, equalTo("post /bookstore"));
final Map<String, List<String>> headers = getResponseHeaders(service);
assertFalse(headers.containsKey(TRACE_ID_NAME));
assertFalse(headers.containsKey(SAMPLED_NAME));
assertFalse(headers.containsKey(PARENT_SPAN_ID_NAME));
assertFalse(headers.containsKey(SPAN_ID_NAME));
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class OpenTracingTracingTest method testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault.
@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault() throws MalformedURLException {
final BookStoreService service = createJaxWsService(new Configurator() {
@Override
public void configure(final JaxWsProxyFactoryBean factory) {
factory.getFeatures().add(new OpenTracingClientFeature(tracer));
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.getInInterceptors().add(new LoggingInInterceptor());
}
});
try {
service.removeBooks();
fail("Expected SOAPFaultException to be raised");
} catch (final SOAPFaultException ex) {
/* expected exception */
}
assertThat(TestSender.getAllSpans().size(), equalTo(2));
assertThat(TestSender.getAllSpans().get(0).getOperationName(), equalTo("POST /BookStore"));
assertThat(TestSender.getAllSpans().get(1).getOperationName(), equalTo("POST http://localhost:" + PORT + "/BookStore"));
}
Aggregations