Search in sources :

Example 1 with DoubleItFault

use of org.example.contract.doubleit.DoubleItFault in project cxf by apache.

the class DoubleItPortTypeImplJavaFirst method doubleIt.

@Policies({ @Policy(uri = "classpath:/org/apache/cxf/systest/ws/fault/SymmetricUTPolicy.xml"), @Policy(uri = "classpath:/org/apache/cxf/systest/ws/fault/SignedEncryptedPolicy.xml", placement = Placement.BINDING_OPERATION_OUTPUT) })
public int doubleIt(int numberToDouble) throws DoubleItFault {
    Principal pr = wsContext.getUserPrincipal();
    if ("alice".equals(pr.getName())) {
        return numberToDouble * 2;
    }
    org.example.schema.doubleit.DoubleItFault internalFault = new org.example.schema.doubleit.DoubleItFault();
    internalFault.setMajor((short) 124);
    internalFault.setMinor((short) 1256);
    throw new DoubleItFault("This is a fault", internalFault);
}
Also used : DoubleItFault(org.example.contract.doubleit.DoubleItFault) Principal(java.security.Principal) Policies(org.apache.cxf.annotations.Policies)

Example 2 with DoubleItFault

use of org.example.contract.doubleit.DoubleItFault in project cxf by apache.

the class DoubleIt3Impl method doubleIt3.

@Override
public DoubleItResponse doubleIt3(DoubleIt3 parameters, byte[] attachment) throws DoubleItFault {
    int numberToDouble = parameters.getNumberToDouble();
    if (numberToDouble == 0) {
        throw new DoubleItFault("0 can't be doubled!");
    }
    if (!Arrays.equals(attachment, "12345".getBytes())) {
        throw new DoubleItFault("Unexpected attachment value!");
    }
    DoubleItResponse response = new DoubleItResponse();
    response.setDoubledNumber(numberToDouble * 2);
    return response;
}
Also used : DoubleItResponse(org.example.schema.doubleit.DoubleItResponse) DoubleItFault(org.example.contract.doubleit.DoubleItFault)

Example 3 with DoubleItFault

use of org.example.contract.doubleit.DoubleItFault in project cxf by apache.

the class DoubleIt3Impl method doubleIt3.

@Override
public DoubleItResponse doubleIt3(DoubleIt3 parameters, byte[] attachment) throws DoubleItFault {
    int numberToDouble = parameters.getNumberToDouble();
    if (numberToDouble == 0) {
        throw new DoubleItFault("0 can't be doubled!");
    }
    if (!Arrays.equals(attachment, "12345".getBytes())) {
        throw new DoubleItFault("Unexpected attachment value!");
    }
    DoubleItResponse response = new DoubleItResponse();
    response.setDoubledNumber(numberToDouble * 2);
    return response;
}
Also used : DoubleItResponse(org.example.schema.doubleit.DoubleItResponse) DoubleItFault(org.example.contract.doubleit.DoubleItFault)

Example 4 with DoubleItFault

use of org.example.contract.doubleit.DoubleItFault in project cxf by apache.

the class DoubleItBSTImpl method doubleIt.

public int doubleIt(int numberToDouble) throws DoubleItFault {
    if (numberToDouble == 0) {
        throw new DoubleItFault("0 can't be doubled!");
    }
    List<WSHandlerResult> results = CastUtils.cast((List<?>) wsContext.getMessageContext().get(WSHandlerConstants.RECV_RESULTS));
    Assert.assertNotNull("Security Results cannot be null", results);
    Assert.assertTrue(!results.isEmpty());
    WSHandlerResult result = results.get(0);
    List<WSSecurityEngineResult> securityResults = result.getResults();
    Assert.assertNotNull("Security Results cannot be null", securityResults);
    Assert.assertTrue(!securityResults.isEmpty());
    WSSecurityEngineResult securityResult = securityResults.get(0);
    BinarySecurity binarySecurityToken = (BinarySecurity) securityResult.get(WSSecurityEngineResult.TAG_BINARY_SECURITY_TOKEN);
    Assert.assertNotNull(binarySecurityToken);
    Assert.assertTrue(Arrays.equals(binarySecurityToken.getToken(), "This is a token".getBytes()));
    return numberToDouble * 2;
}
Also used : BinarySecurity(org.apache.wss4j.common.token.BinarySecurity) DoubleItFault(org.example.contract.doubleit.DoubleItFault) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Example 5 with DoubleItFault

use of org.example.contract.doubleit.DoubleItFault in project cxf by apache.

the class DoubleItPortTypeImpl method doubleIt.

public int doubleIt(int numberToDouble) throws DoubleItFault {
    Principal pr = wsContext.getUserPrincipal();
    if ("alice".equals(pr.getName())) {
        return numberToDouble * 2;
    }
    org.example.schema.doubleit.DoubleItFault internalFault = new org.example.schema.doubleit.DoubleItFault();
    internalFault.setMajor((short) 124);
    internalFault.setMinor((short) 1256);
    throw new DoubleItFault("This is a fault", internalFault);
}
Also used : DoubleItFault(org.example.contract.doubleit.DoubleItFault) Principal(java.security.Principal)

Aggregations

DoubleItFault (org.example.contract.doubleit.DoubleItFault)5 Principal (java.security.Principal)2 DoubleItResponse (org.example.schema.doubleit.DoubleItResponse)2 Policies (org.apache.cxf.annotations.Policies)1 BinarySecurity (org.apache.wss4j.common.token.BinarySecurity)1 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)1 WSHandlerResult (org.apache.wss4j.dom.handler.WSHandlerResult)1