如何从独立java文件调用JAX WS?

如何从独立java文件调用JAX WS?,java,web-services,jax-ws,Java,Web Services,Jax Ws,我试图从一个独立的java类(包含main方法)调用jax ws web服务。我已经在soapui中尝试过了,它在那里返回了响应 我的Java代码:在main()方法中: GInformation getGMInfo = new GInformation(); GInformationResult getGMResult = new GInformationResult(); GKService GKProxy = getProxy(); //Set the Request XMLGrego

我试图从一个独立的java类(包含
main
方法)调用jax ws web服务。我已经在soapui中尝试过了,它在那里返回了响应

我的Java代码:main()方法中:

GInformation getGMInfo = new GInformation();
GInformationResult getGMResult = new GInformationResult();

GKService GKProxy = getProxy();

//Set the Request
XMLGregorianCalendar xmlGreg = null;
getGMInfo.setRequestId("");
getGMInfo.setMessageDateTime(xmlGreg);

try {
    //Get the response
    getGMResult = GKProxy.getGInformation(getGMInfo);
    System.out.println("Address: "+getGMResult.getInfo());
} catch (OperationFaultException e) {
    e.printStackTrace();
} catch (SystemFaultException e) {
    e.printStackTrace();
} 
但它失败了,出现了如下错误:

org.apache.axis2.AxisFault:ws7130e:没有安全套接字层(SSL)配置可用于https://mklip.verd.Gin/WS/v2.8 端点。

很长一段时间以来,我一直在试图纠正这一点,现在我快要发疯了。
有人能告诉我我做错了什么吗?可以从独立java类调用jax ws吗?或者我们需要web服务器吗?但此应用程序没有web服务器。

您是否尝试将端点地址设置为您的web服务地址。 在我的例子中,我使用客户机代码从WSDL文件生成了jar

我的测试用例中的一个例子是

public static void main(String[] args){
          SecurityRefServiceLocator securityRefServiceLocator = new SecurityRefServiceLocator();
            securityRefServiceLocator.setSecurityrefPortEndpointAddress("http://xxxxx:13600/my_ss/webservice/refreshSecurity?wsdl");
            WebserviceClient webserviceClient = new WebserviceClient();
            webserviceClient.setSecurityRefServiceLocator(securityRefServiceLocator);
            System.out.println(webserviceClient.refreshSecurity(8798789l,"1114"));

}

}
WebServiceClient代码

public WebServiceReturnCode refreshSecurity(Long securityId, String productId) {

    try{
        SecurityRef securityRef = securityRefServiceLocator.getSecurityrefPort();

        SecurityServiceBindingStub  securityServiceBindingStub=
            (SecurityServiceBindingStub) securityRef;

        securityServiceBindingStub.setUsername("user");
        securityServiceBindingStub.setPassword("password");

        securityServiceBindingStub.setTimeout(timeout);

        SecurityServiceRequest parameter = new SecurityServiceRequest();

        parameter.setMessageId("MSG-" + securityId);
        parameter.setSecurityId(securityId.toString());
        SecurityServiceResponse refreshSecurity = securityRef.refreshSecurity(parameter);
        ResponseType msgResponse = refreshSecurity.getMsgResponse();
        //evaluate msg response and send E200; if fail
        if(msgResponse.equals(ResponseType.SUCCESS)){
            return WebServiceReturnCode.SUCCESS;
        }
        // Response was not favorable
        return "WSE200";

    }catch(Exception e){
        // Exception occurred. Mark this as technical failure to webservice call.
        return "WSE100";
    }finally{
}
}

public SecurityRefServiceLocator getSecurityRefServiceLocator() {
    return securityRefServiceLocator;
}

public void setSecurityRefServiceLocator(
        SecurityRefServiceLocator securityRefServiceLocator) {
    this.securityRefServiceLocator = securityRefServiceLocator;
}

为了解决这个问题,我不得不越挖越深。我遇到的问题是可信证书问题。因此,首先,我得到了调用服务所需的证书(cert1.cer、cert2.cer)

然后,我使用以下步骤在本地集成证书:

1. Place the below cry certificates in the path "C:\Program Files\IBM\SDP\jdk\jre\lib\security"

   cert1.cer, cert2.cer 

2. cacerts is the trusStore file. It's present in :
   C:/Program Files/IBM/SDP/jdk/jre/lib/security/cacerts

3. In command prompt perform the below execution
C:\Program Files\IBM\SDP\jdk\jre\lib\security>"C:\Program Files\IBM\SDP\jdk\jre\bin\keytool" -import -alias cert1 -file cert1.cer -keystore cacerts

4. If it asks keystore password, mention changeit, which is the default keystore password

Enter keystore password: changeit

Trust this certificate? [no]:  yes
Certificate was added to keystore

5. Peform the steps 3 and 4 for the second certificate(cert2.cer).
但这还不够。我必须以编程方式设置
javax.net.ssl
,如下所示:

System.setProperty("javax.net.ssl.trustStore", "C:\\Program Files\\IBM\\SDP\\jdk\\jre\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStore", "C:\\Program Files\\IBM\\SDP\\jdk\\jre\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
上面几行代码确保在WS-call期间为SSL调用设置了
trustStore
keyStore


这并不容易获得,因此我在这里提供了解释和答案,以便在某些人确实存在相同问题的情况下,他/她可以将其作为缓解其问题的参考。干杯

将下面的行作为程序的第一行。这将解决问题。
System.setProperty(“com.ibm.SSL.ConfigURL”,“文件:C:\ibm\WebSphere\AppServer\profiles\AppSrv01\properties\SSL.client.props”)

@PaulVargas的可能复制品:不要认为它是复制品。我知道这是个证书问题。但真正的问题是如何避开它?这里有可能解决问题吗?如果是,我怎么做?或者我需要来自wsdl服务宿主的证书才能使其工作吗?只有在希望通过HTTPS调用服务器时,才需要配置SSL。如果不需要安全连接,可以将地址更改为HTTP one。是的,我已经尝试使用以下代码执行此操作:
bp.getRequestContext().put(BindingProvider.ENDPOINT\u address\u属性,“https://mklip.verd.Gin/WS/v2.8?wsdl");。这不起作用,并给出了相同的异常。请尝试按我的方式…从wsdl生成客户机代码。请获取从URL生成的WSDL文件。然后试着测试它。我在这里看到的唯一区别是,您的URL具有SSL,而在我的情况下,它不是一个安全的URL。可能这需要一种不同的方法,我会对此进行平行研究。从端点url获取WSDL文件不是一个好主意。有时,您从这样的url获得的wsdl会给您一个未开发的wsdl,而没有适当的
xsd
引用(比如在我的例子中,我甚至无法使用该wsdl生成客户端,因为它给了我几个
wsdl解析错误,因为它没有适当的xsd引用)。因此,我使用了旧的wsdl,并使用我在上面发布的答案来解决SSL配置问题。