如何在Java中使用SSL使用SOAP Web服务?

时间:2016-10-24 16:34:42

标签: java web-services ssl soap

我有一个连接到一系列SOAP Web服务的Java应用程序。这些Web服务使用HTTP并且工作正常,但我们需要它们使用SSL。

这是一个示例Web服务。所有其他的看起来都一样。

public Usuario LoginUsuario(String user, String password, int perfil){
     SOAPConnectionFactory soapConnectionFactory;
    try {
        soapConnectionFactory = SOAPConnectionFactory.newInstance();

        SOAPConnection soapConnection = soapConnectionFactory.createConnection();

        // Sends SOAP message to SOAP server
        Properties props = new Properties();
        props.load(new FileInputStream("ws.properties"));

        String url = props.getProperty("ws");
        SOAPMessage soapResponse = soapConnection.call(createSOAPRequestLogin(user, password, perfil), url);

        // Gets SOAP response and then processes it
        Usuario usu = getSOAPResponseLogin(soapResponse);

        return usu;
    }
    catch (SOAPException ex) {
        Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedOperationException ex) {
        Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

我知道我必须在我的JVM中安装证书,如果我没有弄错,但我仍然不确定。

编辑:如果我想连接到SSL网络服务,我是否应该修改上述代码中的任何内容?如果是这样怎么样?

提前致谢

0 个答案:

没有答案
相关问题