Search in sources :

Example 1 with DoSomethingFault

use of org.apache.schema_validation.DoSomethingFault 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)

Example 2 with DoSomethingFault

use of org.apache.schema_validation.DoSomethingFault in project cxf by apache.

the class SchemaValidationImpl method doSomething.

@Override
public SomeResponse doSomething(SomeRequest in) throws DoSomethingFault {
    SomeResponse response = new SomeResponse();
    if (in.getId().equals("1234567890")) {
        // invalid transaction id
        response.setTransactionId("aaaaaaaaaaxxx");
    } else if (in.getId().equals("9999999999")) {
        SomeFault someFault = new SomeFault();
        someFault.setErrorCode("1234");
        throw new DoSomethingFault("Fault", someFault);
    } else if (in.getId().equals("8888888888")) {
        SomeFault someFault = new SomeFault();
        someFault.setErrorCode("1");
        throw new DoSomethingFault("Fault", someFault);
    } else {
        response.setTransactionId("aaaaaaaaaa");
    }
    return response;
}
Also used : DoSomethingFault(org.apache.schema_validation.DoSomethingFault) SomeFault(org.apache.schema_validation.types.SomeFault) SomeResponse(org.apache.schema_validation.types.SomeResponse)

Example 3 with DoSomethingFault

use of org.apache.schema_validation.DoSomethingFault in project cxf by apache.

the class ValidationClientServerTest method runSchemaValidationTest.

private void runSchemaValidationTest(SchemaValidation validation) {
    ComplexStruct complexStruct = new ComplexStruct();
    complexStruct.setElem1("one");
    // Don't initialize a member of the structure.
    // Client side validation should throw an exception.
    // complexStruct.setElem2("two");
    complexStruct.setElem3(3);
    try {
        /*boolean result =*/
        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);
    }
    OccuringStruct occuringStruct = new OccuringStruct();
    // Populate the list in the wrong order.
    // Client side validation should throw an exception.
    List<Serializable> floatIntStringList = occuringStruct.getVarFloatAndVarIntAndVarString();
    floatIntStringList.add(new Integer(42));
    floatIntStringList.add(new Float(4.2f));
    floatIntStringList.add("Goofus and Gallant");
    try {
        /*boolean result =*/
        validation.setOccuringStruct(occuringStruct);
        fail("Set OccuringStruct should have thrown ProtocolException");
    } catch (WebServiceException e) {
        String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
        assertTrue(e.getMessage().indexOf(expected) != -1);
    }
    try {
        // The server will attempt to return an invalid ComplexStruct
        // When validation is disabled on the server side, we'll get the
        // exception while unmarshalling the invalid response.
        /*complexStruct =*/
        validation.getComplexStruct("Hello");
        fail("Get ComplexStruct should have thrown ProtocolException");
    } catch (WebServiceException e) {
        String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
        assertTrue("Found message " + e.getMessage(), e.getMessage().indexOf(expected) != -1);
    }
    try {
        // The server will attempt to return an invalid OccuringStruct
        // When validation is disabled on the server side, we'll get the
        // exception while unmarshalling the invalid response.
        /*occuringStruct =*/
        validation.getOccuringStruct("World");
        fail("Get OccuringStruct should have thrown ProtocolException");
    } catch (WebServiceException e) {
        String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
        assertTrue(e.getMessage().indexOf(expected) != -1);
    }
    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);
    }
}
Also used : Serializable(java.io.Serializable) OccuringStruct(org.apache.schema_validation.types.OccuringStruct) DoSomethingFault(org.apache.schema_validation.DoSomethingFault) WebServiceException(javax.xml.ws.WebServiceException) SomeRequest(org.apache.schema_validation.types.SomeRequest) ComplexStruct(org.apache.schema_validation.types.ComplexStruct)

Aggregations

DoSomethingFault (org.apache.schema_validation.DoSomethingFault)3 WebServiceException (javax.xml.ws.WebServiceException)2 SomeRequest (org.apache.schema_validation.types.SomeRequest)2 Serializable (java.io.Serializable)1 SchemaValidation (org.apache.schema_validation.SchemaValidation)1 ComplexStruct (org.apache.schema_validation.types.ComplexStruct)1 OccuringStruct (org.apache.schema_validation.types.OccuringStruct)1 SomeFault (org.apache.schema_validation.types.SomeFault)1 SomeResponse (org.apache.schema_validation.types.SomeResponse)1