use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class WSAPureWsdlTest method testDispatchActionMissmatch.
@Test
public void testDispatchActionMissmatch() throws Exception {
String req = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<S:Body><addNumbers3 xmlns=\"http://apache.org/cxf/systest/ws/addr_feature/\">" + "<number1>1</number1><number2>2</number2></addNumbers3>" + "</S:Body></S:Envelope>";
// String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
String expectedOut = "http://bad.action";
URL wsdl = getClass().getResource("/wsdl_systest_wsspec/add_numbers.wsdl");
assertNotNull("WSDL is null", wsdl);
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
Dispatch<Source> disp = service.createDispatch(AddNumbersService.AddNumbersPort, Source.class, Mode.MESSAGE);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/add");
// manually set the action
disp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, expectedOut);
disp.getRequestContext().put(ContextUtils.ACTION, expectedOut + "/wsaAction");
try {
disp.invoke(new StreamSource(new StringReader(req)));
fail("no exception");
} catch (SOAPFaultException f) {
// expected
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class WSSecurityClientTest method testDecoupledFaultFromSecurity.
@Test
public void testDecoupledFaultFromSecurity() throws Exception {
Dispatch<Source> dispatcher = null;
java.io.InputStream is = null;
//
// Sending no security headers should result in a Fault
//
dispatcher = createUsernameTokenDispatcher(true, test.getPort());
is = getClass().getResourceAsStream("test-data/NoHeadersRequest.xml");
try {
dispatcher.invoke(new StreamSource(is));
fail("exception should have been generated");
} catch (SOAPFaultException ex) {
assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
}
//
// Sending and empty header should result in a Fault
//
dispatcher = createUsernameTokenDispatcher(true, test.getPort());
is = getClass().getResourceAsStream("test-data/EmptyHeaderRequest.xml");
try {
dispatcher.invoke(new StreamSource(is));
fail("exception should have been generated");
} catch (SOAPFaultException ex) {
assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
}
//
// Sending and empty security header should result in a Fault
//
dispatcher = createUsernameTokenDispatcher(true, test.getPort());
is = getClass().getResourceAsStream("test-data/EmptySecurityHeaderRequest.xml");
try {
dispatcher.invoke(new StreamSource(is));
fail("exception should have been generated");
} catch (SOAPFaultException ex) {
assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
}
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class JavaFirstPolicyServiceTest method testOperationNoClientCertAlternativePolicy.
@Test
public void testOperationNoClientCertAlternativePolicy() {
System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslnocertclient.xml" });
OperationSimpleService simpleService = clientContext.getBean("OperationSimpleServiceClient", OperationSimpleService.class);
// no security on ping!
simpleService.ping();
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);
}
// this is successful because the alternative policy allows a password to be specified.
wssOut.setProperties(getPasswordProperties("alice", "password"));
simpleService.doStuff();
clientContext.close();
}
use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.
the class JavaFirstPolicyServiceTest method testNoAltOperationClientCertPolicy.
@Test
public void testNoAltOperationClientCertPolicy() {
System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslcertclient.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"));
simpleService.doStuff();
wssOut.setProperties(getPasswordProperties("alice", "password"));
try {
simpleService.doStuff();
fail("Expected exception as 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 JavaFirstPolicyServiceTest method testBindingClientCertAlternativePolicy.
@Test
public void testBindingClientCertAlternativePolicy() {
System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslcertclient.xml" });
BindingSimpleService simpleService = clientContext.getBean("BindingSimpleServiceClient", BindingSimpleService.class);
try {
simpleService.doStuff();
fail("Expected exception as no credentials");
} catch (SOAPFaultException e) {
assertTrue(true);
}
WSS4JOutInterceptor wssOut = addToClient(simpleService);
wssOut.setProperties(getNoPasswordProperties("alice"));
simpleService.doStuff();
wssOut.setProperties(getPasswordProperties("alice", "password"));
// this is successful because the alternative policy allows a password to be specified.
simpleService.doStuff();
clientContext.close();
}
Aggregations