简体   繁体   中英

attach certificate with web service request in java

I have to create client code for soap web service in java.which has input as basic authentication and ssl certificate. I couldn't find way to attach certificate with post request.Can you tell me how to attach certificate and password with Post request

If you are using apache CXF, this code might help you:

    Client client = ClientProxy.getClient(service);
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();

    TLSClientParameters tlsConfig = new TLSClientParameters();
    try {
        //Set up the keyStore for CXF
        InputStream keyStoreInputStream = new FileOrClasspathResource(keyStorePath).openStream();
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(keyStoreInputStream, keyStorePassword.toCharArray());
        TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustFactory.init(keyStore);
        TrustManager[] tm = trustFactory.getTrustManagers();
        tlsConfig.setTrustManagers(tm);
    } catch (Exception e) {
        log.error("Couldn't initialize keyStore with name " + keyStorePath, e);
    }

    httpConduit.setTlsClientParameters(tlsConfig);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM