Am trying to call third party web service using java apache CXF. I created the proxy using CXF apache plugin. The service is protected using X509 Authentication, Signature and Encryption.
When I call the service, am getting the below exception.
Apache CXF Policy Exception Reference to policy "X509 Authentication, Signature and Encryption" could not be resolved
This is what I tried sofar..
ServiceEnq service=new ServiceEnq(new
URL("https://.....Inquiry?wsdl"));
System.out.println("Line2 scuccess!");
InquiryPortType port=service.getInquiryPort();
Client client = ClientProxy.getClient(port);
org.apache.cxf.endpoint.Endpoint endpoint = client.getEndpoint();
HashMap<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION,
"UsernameToken Timestamp Signature Encryption");
outProps.put(WSHandlerConstants.USER, "username1");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordCallbackHandler.class.getName());
outProps.put(WSHandlerConstants.ENCRYPTION_USER, "public1");
outProps.put(WSHandlerConstants.ENC_PROP_FILE, "publicProp.properties");
outProps.put(WSHandlerConstants.SIGNATURE_USER, "pk");
outProps.put(WSHandlerConstants.SIG_PROP_FILE, "pkProp.properties");
outProps.put("timeToLive", "30");
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
endpoint.getOutInterceptors().add(wssOut);
HashMap<String, Object> inProps = new HashMap<>();
inProps.put(WSHandlerConstants.ACTION, "Encryption Signature Timestamp");
inProps.put(WSHandlerConstants.DEC_PROP_FILE, "publicProp.properties");
inProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordCallbackHandler.class.getName());
inProps.put(WSHandlerConstants.SIG_PROP_FILE, "pkProp.properties");
WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
endpoint.getInInterceptors().add(wssIn);
ObjectFactory fact=new ObjectFactory();
InquiryRequest request=fact.createInquiryRequest();
MessageHeaderIn headerIn=fact.createMessageHeaderIn();
// removed input parameters
// getting error in this line...
InquiryResponse2 res= port.Inquiry(request);
I have manually created the XML
Documentand usedwss4jto encrypt and sign XML document. Then uploaded the generated SOAP envelope toHttpURLConnectionusing POST method.Here is the java code to sign and encryption. I have avoided other code as this is more tricky part..