use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class JavaFirstPolicyServiceTest method testNoAltOperationNoClientCertPolicy.
@Test
public void testNoAltOperationNoClientCertPolicy() {
System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslnocertclient.xml" });
NoAlternativesOperationSimpleService simpleService = clientContext.getBean("NoAlternativesOperationSimpleServiceClient", NoAlternativesOperationSimpleService.class);
try {
simpleService.doStuff();
fail("Expected exception as no credentials");
} catch (SOAPFaultException e) {
assertTrue(true);
}
WSS4JOutInterceptor wssOut = addToClient(simpleService);
wssOut.setProperties(getNoPasswordProperties("alice"));
try {
simpleService.doStuff();
fail("Expected exception as no password and no client cert");
} catch (SOAPFaultException e) {
assertTrue(true);
}
wssOut.setProperties(getPasswordProperties("alice", "password"));
try {
simpleService.doStuff();
fail("Expected exception as no client cert and password not allowed");
} catch (SOAPFaultException e) {
assertTrue(true);
}
wssOut.setProperties(getNoPasswordProperties("alice"));
try {
simpleService.ping();
fail("Expected exception as no password");
} catch (SOAPFaultException e) {
assertTrue(true);
}
wssOut.setProperties(getPasswordProperties("alice", "password"));
simpleService.ping();
clientContext.close();
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class CachingTest method testSTSClientCaching.
// @Ignore'd because failing too often on slow Jenkins machines
@org.junit.Test
@org.junit.Ignore
public void testSTSClientCaching() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CachingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CachingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1Port");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
((BindingProvider) port).getRequestContext().put("thread.local.request.context", "true");
updateAddressPort(port, PORT);
// Make a successful invocation
doubleIt(port, 25);
// Change the STSClient so that it can no longer find the STS
BindingProvider p = (BindingProvider) port;
clearSTSClient(p, bus);
// This should succeed as the token is cached
doubleIt(port, 30);
// This should fail as the cached token is manually removed
Client client = ClientProxy.getClient(port);
Endpoint ep = client.getEndpoint();
ep.remove(SecurityConstants.TOKEN_ID);
ep.remove(SecurityConstants.TOKEN);
try {
doubleIt(port, 35);
fail("Expected failure on clearing the cache");
} catch (SOAPFaultException ex) {
// Expected
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class CachingTest method testDisableProxyCaching.
@org.junit.Test
public void testDisableProxyCaching() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CachingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CachingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1Port2");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
((BindingProvider) port).getRequestContext().put("thread.local.request.context", "true");
updateAddressPort(port, PORT);
// Disable storing tokens per-proxy
((BindingProvider) port).getRequestContext().put(SecurityConstants.CACHE_ISSUED_TOKEN_IN_ENDPOINT, "false");
// Make a successful invocation
doubleIt(port, 25);
// Change the STSClient so that it can no longer find the STS
BindingProvider p = (BindingProvider) port;
clearSTSClient(p, bus);
// This should fail as it can't get the token
try {
doubleIt(port, 35);
fail("Expected failure");
} catch (SOAPFaultException ex) {
// Expected
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class TestHandler method createSOAPFaultException.
private SOAPFaultException createSOAPFaultException(String faultString) {
try {
SOAPFault fault = SOAPFactory.newInstance().createFault();
fault.setFaultString(faultString);
SAAJUtils.setFaultCode(fault, new QName("http://cxf.apache.org/faultcode", "Server"));
return new SOAPFaultException(fault);
} catch (SOAPException e) {
// do nothing
}
return null;
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class TestSOAPHandler method createSOAPFaultExceptionWithDetail.
private SOAPFaultException createSOAPFaultExceptionWithDetail(String faultString) throws SOAPException {
SOAPFault fault = SOAPFactory.newInstance().createFault();
QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server");
SAAJUtils.setFaultCode(fault, faultName);
fault.setFaultActor("http://gizmos.com/orders");
fault.setFaultString(faultString);
Detail detail = fault.addDetail();
QName entryName = new QName("http://gizmos.com/orders/", "order", "PO");
DetailEntry entry = detail.addDetailEntry(entryName);
entry.addTextNode("Quantity element does not have a value");
QName entryName2 = new QName("http://gizmos.com/orders/", "order", "PO");
DetailEntry entry2 = detail.addDetailEntry(entryName2);
entry2.addTextNode("Incomplete address: no zip code");
return new SOAPFaultException(fault);
}
Aggregations