use of javax.xml.ws.WebServiceException in project cxf by apache.
the class AbstractHeaderServiceRpcLitTest method verifyFaults.
public void verifyFaults(HeaderTester ht) {
getLogger().debug("Client: calling pingMe user fault");
PingMeT in = new PingMeT();
try {
in.setFaultType("USER");
ht.pingMe(in);
fail("Should throw a PingeMeFault exception");
} catch (PingMeFault pmf) {
FaultDetailT detail = pmf.getFaultInfo();
assertNotNull(detail);
assertEquals("Major Version should be 1", (short) 1, detail.getMajor());
assertEquals("Minor Version should be 2", (short) 2, detail.getMinor());
if (isFaultCodeCheckEnabled()) {
verifyFaultCode(port);
}
}
getLogger().debug("Client: calling pingMe Cxf System Fault");
try {
in.setFaultType("SYSTEM");
ht.pingMe(in);
fail("Should throw a CXF Fault exception");
} catch (WebServiceException fault) {
assertFalse("Wrong message: " + fault.getMessage(), -1 == fault.getMessage().lastIndexOf(HeaderTesterUtil.EX_STRING));
if (isFaultCodeCheckEnabled()) {
verifyFaultCode(port);
}
} catch (PingMeFault pmf) {
fail("Should not receive PingMefault");
}
getLogger().debug("Client: calling pingMe java runtime exception");
try {
in.setFaultType("RUNTIME");
ht.pingMe(in);
fail("Should throw a CXF Fault exception");
} catch (WebServiceException fault) {
assertFalse(-1 == fault.getMessage().lastIndexOf(HeaderTesterUtil.EX_STRING));
if (isFaultCodeCheckEnabled()) {
verifyFaultCode(port);
}
} catch (PingMeFault pmf) {
fail("Should not receive PingMefault");
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class SequenceTest method testInactivityTimeout.
@Test
public void testInactivityTimeout() throws Exception {
init("org/apache/cxf/systest/ws/rm/inactivity-timeout.xml");
greeter.greetMe("one");
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
// ignore
}
try {
greeter.greetMe("two");
fail("Expected fault.");
} catch (WebServiceException ex) {
SoapFault sf = (SoapFault) ex.getCause();
assertEquals("Unexpected fault code.", Soap11.getInstance().getSender(), sf.getFaultCode());
assertNull("Unexpected sub code.", sf.getSubCode());
assertTrue("Unexpected reason.", sf.getReason().endsWith("is not a known Sequence identifier."));
}
awaitMessages(3, 3, 5000);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
// Expected outbound:
// CreateSequence
// + two requests (second request does not include acknowledgement for first response as
// in the meantime the client has terminated the sequence
String[] expectedActions = new String[3];
expectedActions[0] = RM10Constants.CREATE_SEQUENCE_ACTION;
for (int i = 1; i < expectedActions.length; i++) {
expectedActions[i] = GREETME_ACTION;
}
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2" }, true);
mf.verifyLastMessage(new boolean[3], true);
mf.verifyAcknowledgements(new boolean[] { false, false, false }, true);
// Expected inbound:
// createSequenceResponse
// + 1 response with acknowledgement
// + 1 fault without acknowledgement
mf.verifyMessages(3, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, RM10_GENERIC_FAULT_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, "1", null }, false);
mf.verifyAcknowledgements(new boolean[] { false, true, false }, false);
// the third inbound message has a SequenceFault header
mf.verifySequenceFault(RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, false, 2);
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class SequenceTest method testCreateSequenceRefused.
@Test
public void testCreateSequenceRefused() throws Exception {
init("org/apache/cxf/systest/ws/rm/limit-seqs.xml");
RMManager manager = greeterBus.getExtension(RMManager.class);
assertEquals("Unexpected maximum sequence count.", 1, manager.getDestinationPolicy().getMaxSequences());
greeter.greetMe("one");
// hold onto the greeter to keep the sequence open
Closeable oldGreeter = (Closeable) greeter;
// force greeter to be re-initialized so that a new sequence is created
initProxy(false, null);
try {
greeter.greetMe("two");
fail("Expected fault.");
} catch (WebServiceException ex) {
// sequence creation refused
}
// the third inbound message has a SequenceFault header
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifySequenceFault(RM10Constants.CREATE_SEQUENCE_REFUSED_FAULT_QNAME, false, 2);
String[] expectedActions = new String[3];
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, RM10_GENERIC_FAULT_ACTION };
mf.verifyActions(expectedActions, false);
// now close the old greeter to cleanup the sequence
oldGreeter.close();
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class ValidationClientServerTest method testSchemaValidationServerForMethod.
@Test
public void testSchemaValidationServerForMethod() throws Exception {
SchemaValidation validation = createService(Boolean.FALSE, "SoapPortMethodValidate");
ComplexStruct complexStruct = new ComplexStruct();
complexStruct.setElem1("one");
complexStruct.setElem3(3);
try {
validation.setComplexStruct(complexStruct);
fail("Set ComplexStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
assertTrue(e.getMessage(), e.getMessage().indexOf(expected) != -1);
}
SchemaValidation novlidation = createService(Boolean.FALSE, "SoapPort");
try {
novlidation.setComplexStruct(complexStruct);
} catch (WebServiceException e) {
fail("Exception is not expected :" + e);
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class ValidationClientServerTest method doProviderTest.
private void doProviderTest(String postfix) throws Exception {
SchemaValidation validation = createService(Boolean.FALSE, postfix);
SomeRequest req = new SomeRequest();
req.setId("9999999999");
try {
validation.doSomething(req);
fail("Should have faulted");
} catch (DoSomethingFault e) {
assertEquals("1234", e.getFaultInfo().getErrorCode());
}
req.setId("8888888888");
try {
validation.doSomething(req);
fail("Should have faulted");
} catch (DoSomethingFault e) {
fail("Should not have happened");
} catch (WebServiceException e) {
String expected = "Value '1' is not facet-valid";
assertTrue(e.getMessage().indexOf(expected) != -1);
}
((java.io.Closeable) validation).close();
}
Aggregations