You could try moving the following after the
HttpsURLConnection.setDefaultSSLSocketFactory
call:
SetSaleRequest request = new SetSaleRequest();
SetSaleResponse response = new SetSaleResponse();
Alternatively, why not just download the WSDL and refer to it locally in
your service class? That avoids the need to call out over HTTPS to download
the WSDL.
Failing that, there's a WSDL First HTTPs example in CXF here:
https://github.com/apache/cxf/tree/master/distribution/src/main/release/samples/wsdl_first_https
Spring config:
https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/wsdl_first_https/src/main/resources/SecureClient.xml
Colm.
On Tue, Jan 30, 2018 at 10:25 AM, Al Grant <[email protected]> wrote:
> Here is the code that I have been using:
>
> SetSaleRequest request = new SetSaleRequest();
> SetSaleResponse response = new SetSaleResponse();
>
>
> // CXF CLIENT FOR MUTUAL TLS
>
> // Setup TLS client params
> TLSClientParameters tlsParams = new TLSClientParameters();
> /* Get the JKS contents */
> final char[] JKS_PASSWORD = "somepassword".toCharArray();
> final char[] KEY_PASSWORD = "somepassword".toCharArray();
>
> // KEYSTORE
> final KeyStore keyStore = KeyStore.getInstance("JKS");
> try (final InputStream is = new
> FileInputStream("C:\\Users\\Owner\\IdeaProjects\\sales\\
> src\\main\\resources\\keystore.jks"))
> {
> keyStore.load(is, JKS_PASSWORD);
> }
> final KeyManagerFactory kmf =
> KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
> kmf.init(keyStore, KEY_PASSWORD);
>
> // TRUSTSTORE
> final KeyStore trustStore = KeyStore.getInstance("JKS");
> try (final InputStream is = new
> FileInputStream("C:\\Users\\Owner\\IdeaProjects\\sales\\
> src\\main\\resources\\truststore.jks"))
> {
> trustStore.load(is, JKS_PASSWORD);
> }
> TrustManagerFactory tmf =
> TrustManagerFactory.getInstance(TrustManagerFactory.
> getDefaultAlgorithm());
> tmf.init(trustStore);
>
> tlsParams.setTrustManagers(tmf.getTrustManagers());
> tlsParams.setDisableCNCheck(true);
>
> //CODE FROM COLM
> SSLContext sc = SSLContext.getInstance("TLS");
> try {
> sc.init(null, tmf.getTrustManagers(), null);
> } catch (KeyManagementException e) {
> e.printStackTrace();
> }
>
>
> HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
>
>
> // SENDS DATA
> request.setSale(Sale);
> request.getPeople().add(person);
> RSIService RSIService = new RSIService();
> IRSIService iRSIService = RSIService.getPort(IRSIService.class);
>
> // APACHE CXF CLIENT SETUP - MESSAGE SIGNING
>
>
> ((BindingProvider)iRSIService).getRequestContext().put(
> SecurityConstants.ENCRYPT_PROPERTIES,
> "client_sign.properties");
>
> ((BindingProvider)iRSIService).getRequestContext().put(
> SecurityConstants.SIGNATURE_PROPERTIES,
> "client_sign.properties");
>
> ((BindingProvider)iRSIService).getRequestContext().put(
> SecurityConstants.SIGNATURE_USERNAME,
> "signingonly");
>
> ((BindingProvider)iRSIService).getRequestContext().put(
> SecurityConstants.CALLBACK_HANDLER,
> ClientCallbackHandler.class.getName());
>
> // Logging
> LoggingOutInterceptor loi = new LoggingOutInterceptor();
> LoggingInInterceptor lii = new LoggingInInterceptor();
>
> org.apache.cxf.endpoint.Client client =
> org.apache.cxf.frontend.ClientProxy.getClient(iRSIService);
> org.apache.cxf.endpoint.Endpoint cxfEndpoint =
> client.getEndpoint();
>
> cxfEndpoint.getOutInterceptors().add(loi);
> cxfEndpoint.getInInterceptors().add(lii);
>
>
>
> //Client client = ClientProxy.getClient(port);
> HTTPConduit http = (HTTPConduit) client.getConduit();
> http.setTlsClientParameters(tlsParams);
>
>
>
> // Sending the data
> response = iRSIService.setSale(request);
>
> System.out.println(response.isSuccess());
> System.out.println("Sent");
>
> }
>
> If there is no obvious error above that could be the cause of the stack
> trace do you have a link to defining the keys in spring?
>
> Cheers
>
> AG
>
>
>
>
> --
> Sent from: http://cxf.547215.n5.nabble.com/cxf-user-f547216.html
>
--
Colm O hEigeartaigh
Talend Community Coder
http://coders.talend.com