有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在Eclipse中添加SSL证书以命中SOAPUIWebService?

我使用的SoapUI Web服务是客户端安全的。p12和。cer格式。 当我点击来自Eclipse的请求时,我得到以下控制台错误

sun.security.validator.ValidatorException: PKIX path building failed: 
sun.security.provider.certpath.SunCertPathBuilderException: unable to find 
valid certification path to requested target
javax.net.ssl.SSLHandshakeException: 
sun.security.validator.ValidatorException: PKIX path building failed: 
sun.security.provider.certpath.SunCertPathBuilderException: unable to find 
valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)

下面是我的代码

public class ClientService {
    public static String webServiceURL = "URL";
    public static String requestXMLPath = "Path for request xml";
    public static String response="";

    @Test
    public void clientMethod() throws IOException, Throwable{
        String methodname = Thread.currentThread().getStackTrace()[1].getMethodName();
        String request = new String(Files.readAllBytes(Paths.get(requestXMLPath)));

        PostMethod post = new PostMethod(webServiceURL); 
        HttpClient client = new HttpClient();

        try{
            post.setRequestHeader("Accept","application/soap+xml,application/dime,multipart/related,text/*"); 
            RequestEntity requestEntity = new StringRequestEntity(request.toString(), "text/xml", "utf-8");         
            post.setRequestEntity(requestEntity);           
            client.executeMethod(post);         
            response = post.getResponseBodyAsString();  
            System.out.println(post.getStatusCode()+"\n"+post.getStatusLine()+"\n"+post.getStatusText());
            String xmlformatresponse = response.replace("><", ">\n<");
            System.out.println("Response is "+xmlformatresponse);

        } 
        catch( Exception e){
            System.out.println(e.getMessage());

        }

 }

}

由于webservice是客户端安全的,所以我需要将SSL证书导入Eclipse。 谁能提供解决方案


共 (0) 个答案