Search in sources :

Example 46 with WebServiceException

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");
    }
}
Also used : PingMeFault(org.apache.headers.rpc_lit.PingMeFault) WebServiceException(javax.xml.ws.WebServiceException) FaultDetailT(org.apache.headers.coloc.types.FaultDetailT) PingMeT(org.apache.headers.coloc.types.PingMeT)

Example 47 with WebServiceException

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);
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) WebServiceException(javax.xml.ws.WebServiceException) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Example 48 with WebServiceException

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();
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) RMManager(org.apache.cxf.ws.rm.RMManager) Closeable(java.io.Closeable) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Example 49 with WebServiceException

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);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ComplexStruct(org.apache.schema_validation.types.ComplexStruct) SchemaValidation(org.apache.schema_validation.SchemaValidation) Test(org.junit.Test)

Example 50 with WebServiceException

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();
}
Also used : DoSomethingFault(org.apache.schema_validation.DoSomethingFault) SomeRequest(org.apache.schema_validation.types.SomeRequest) WebServiceException(javax.xml.ws.WebServiceException) SchemaValidation(org.apache.schema_validation.SchemaValidation)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)120 Test (org.junit.Test)50 URL (java.net.URL)37 BindingProvider (javax.xml.ws.BindingProvider)25 Service (javax.xml.ws.Service)22 QName (javax.xml.namespace.QName)14 IOException (java.io.IOException)10 Message (org.apache.cxf.common.i18n.Message)9 JAXBException (javax.xml.bind.JAXBException)8 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 Bus (org.apache.cxf.Bus)7 Packet (com.sun.xml.ws.api.message.Packet)6 AuthStatus (javax.security.auth.message.AuthStatus)6 SOAPException (javax.xml.soap.SOAPException)6 SOAPMessage (javax.xml.soap.SOAPMessage)6 ArrayList (java.util.ArrayList)5 WebService (javax.jws.WebService)5 Subject (javax.security.auth.Subject)5 HttpSession (javax.servlet.http.HttpSession)5 Handler (javax.xml.ws.handler.Handler)5