SOAP 请求:HTTP URLConnection Factory 的协议 https 非法

发布于 2024-12-16 12:02:11 字数 3450 浏览 2 评论 0 原文

问题

我正在调用 SOAP Web 服务,但需要在每次调用时更改 URL。但是,wsdl 中的端点是内部地址,因此我尝试自己编辑端点。假设这是正确的做法(?),我得到 java.io.IOException: Illegal Protocol https for HTTP URLConnection Factory 我正在努力解决。

代码:

    OtherCompanyWebService ws = new OtherCompanyWebService();
    OtherCompanyWebServicePortType port = ws.getOtherCompanyWebServiceHttpSoap11Endpoint();
    ServiceRequest serviceRequest = makeMyServiceRequest();

    BindingProvider bindingProvider = (BindingProvider) port;
    bindingProvider.getRequestContext().put(
                  BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                  "https://blah.blah.com/blah/services/blahWebService.blahWebServiceHttpSoap11Endpoint");

    Staff staff = port.getStaffData(serviceRequest).getStaff().getValue();

堆栈跟踪:

javax.xml.ws.soap.SOAPFaultException: Could not send Message.
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:199)
        at $Proxy52.getStudentData(Unknown Source)
        at uk.co.txttools.rm.service.RmServiceImpl.runRmJob(RmServiceImpl.java:209)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy12.runRmJob(Unknown Source)
        at uk.co.txttools.rm.quartz.RmJob.execute(RmJob.java:41)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
        at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:48)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
        ... 16 more
Caused by: java.io.IOException: Illegal Protocol https for HTTP URLConnection Factory.
        at org.apache.cxf.transport.http.HttpURLConnectionFactoryImpl.createConnection(HttpURLConnectionFactoryImpl.java:44)
        at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:480)
        at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)

Problem :

I'm calling a SOAP Webservice, but need to change the URL with each call. However, the end point within the wsdl was an internal address, so I am trying to edit the endpoint myself. Assuming this is the correct thing to do (?), I get java.io.IOException: Illegal Protocol https for HTTP URLConnection Factory which I am struggling to resolve.

Code :

    OtherCompanyWebService ws = new OtherCompanyWebService();
    OtherCompanyWebServicePortType port = ws.getOtherCompanyWebServiceHttpSoap11Endpoint();
    ServiceRequest serviceRequest = makeMyServiceRequest();

    BindingProvider bindingProvider = (BindingProvider) port;
    bindingProvider.getRequestContext().put(
                  BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                  "https://blah.blah.com/blah/services/blahWebService.blahWebServiceHttpSoap11Endpoint");

    Staff staff = port.getStaffData(serviceRequest).getStaff().getValue();

Stacktrace :

javax.xml.ws.soap.SOAPFaultException: Could not send Message.
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:199)
        at $Proxy52.getStudentData(Unknown Source)
        at uk.co.txttools.rm.service.RmServiceImpl.runRmJob(RmServiceImpl.java:209)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy12.runRmJob(Unknown Source)
        at uk.co.txttools.rm.quartz.RmJob.execute(RmJob.java:41)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
        at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:48)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
        ... 16 more
Caused by: java.io.IOException: Illegal Protocol https for HTTP URLConnection Factory.
        at org.apache.cxf.transport.http.HttpURLConnectionFactoryImpl.createConnection(HttpURLConnectionFactoryImpl.java:44)
        at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:480)
        at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我喜欢麦丽素 2024-12-23 12:02:11

我找到的解决方案远非理想,但似乎有效。如果您有更好的解决方案,请在此发布。

问题是在 wsdl 文件中,端点是 http。发生错误是因为我将端点更改为 https。 (这可能是一个错误?)

为了解决这个问题,我使用本地版本的 wsdl 文件,并放入两个端点,一个 http 和一个 https。然后,当我更改端点时,我要么更改 http 端点,要么更改 https 端点,具体取决于我想要 http 还是 https。

The solution I have found is far from ideal, but appears to work. If you have a better solution, please post it here.

The problem was that in the wsdl file, the endpoint was http. The error occurs because I'm changing the endpoint to be https. (Possibly this is a bug?)

To get round this, I am using a local version of the wsdl file, and putting in two endpoints, one http and one https. Then when I change the endpoint, I either change the http one or the https one, depending on whether I want http or https.

北恋 2024-12-23 12:02:11

当我收到此消息时,我发现我没有为 TLS 客户端 (WS) 设置 SSL 上下文。

如果代码有任何帮助:

/**
 * Configure mutal TLS on WS given in parameter
 * 
 * @param portType webservice
 * @throws Exception
 */
public static void setTLS(Object ws) throws Exception {

    if (tlsClientParameters == null) {
        if (StringUtils.hasLength(ConfigUtils.getInstance().getProxyHost()) && StringUtils.hasLength(ConfigUtils.getInstance().getProxyPort())) {
            System.setProperty("https.proxyHost", ConfigUtils.getInstance().getProxyHost());
            System.setProperty("https.proxyPort", ConfigUtils.getInstance().getProxyPort());
        }

        X509Certificate[] certificatesChain = new X509Certificate[1];

        KeyManager[] managers = new KeyManager[1];

        Pkcs12 pkcs12 = new Pkcs12();
        pkcs12.login(new ClassPathResource(ConfigUtils.getInstance().getCertificateFileName()).getURI().getPath(), ConfigUtils.getInstance().getCertificatePassword());
        certificatesChain[0] = pkcs12.getCertificate();
        managers[0] = new SSLKeyManagers(certificatesChain, pkcs12.getKey());

        Client client = ClientProxy.getClient(portType);
        SSLContext sslContext = SSLContext.getInstance("TLS");

        TrustManager[] trustManager = getServerTrustManager();

        sslContext.init(managers, trustManager, null);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();

        tlsClientParameters = new TLSClientParameters();
        if (trustManager != null) {
            tlsClientParameters.setTrustManagers(trustManager);
        }
        tlsClientParameters.setKeyManagers(managers);
        tlsClientParameters.setSSLSocketFactory(sslContext.getSocketFactory());

        tlsClientParameters.setDisableCNCheck(false);

        conduit.setTlsClientParameters(tlsClientParameters);

    } else {

        Client client = ClientProxy.getClient(portType);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();

        conduit.setTlsClientParameters(tlsClientParameters);
    }
}

/**
 * 
     * Gets the trust manager
 *  
 * @return keystore
 * @throws NoSuchAlgorithmException
 * @throws KeyStoreException
 * @throws ResourceException 
 * @throws IOException 
 * @throws CertificateException 
 */
private static TrustManager[] getServerTrustManager() throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, ResourceException {

    TrustManagerFactory factory = TrustManagerFactory.getInstance("X.509");

    KeyStore trustStore = KeyStore.getInstance("JKS");

    trustStore.load(new ClassPathResource(ConfigUtils.getInstance().getServerKeyStoreFileName()).getInputStream(), ConfigUtils.getInstance().getServerKeystorePassword().toCharArray());

    factory.init(trustStore);       
    return factory.getTrustManagers();
}

When I got this message, I found out that I did not set an SSL context to my TLS client (WS).

If the code can be of any help :

/**
 * Configure mutal TLS on WS given in parameter
 * 
 * @param portType webservice
 * @throws Exception
 */
public static void setTLS(Object ws) throws Exception {

    if (tlsClientParameters == null) {
        if (StringUtils.hasLength(ConfigUtils.getInstance().getProxyHost()) && StringUtils.hasLength(ConfigUtils.getInstance().getProxyPort())) {
            System.setProperty("https.proxyHost", ConfigUtils.getInstance().getProxyHost());
            System.setProperty("https.proxyPort", ConfigUtils.getInstance().getProxyPort());
        }

        X509Certificate[] certificatesChain = new X509Certificate[1];

        KeyManager[] managers = new KeyManager[1];

        Pkcs12 pkcs12 = new Pkcs12();
        pkcs12.login(new ClassPathResource(ConfigUtils.getInstance().getCertificateFileName()).getURI().getPath(), ConfigUtils.getInstance().getCertificatePassword());
        certificatesChain[0] = pkcs12.getCertificate();
        managers[0] = new SSLKeyManagers(certificatesChain, pkcs12.getKey());

        Client client = ClientProxy.getClient(portType);
        SSLContext sslContext = SSLContext.getInstance("TLS");

        TrustManager[] trustManager = getServerTrustManager();

        sslContext.init(managers, trustManager, null);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();

        tlsClientParameters = new TLSClientParameters();
        if (trustManager != null) {
            tlsClientParameters.setTrustManagers(trustManager);
        }
        tlsClientParameters.setKeyManagers(managers);
        tlsClientParameters.setSSLSocketFactory(sslContext.getSocketFactory());

        tlsClientParameters.setDisableCNCheck(false);

        conduit.setTlsClientParameters(tlsClientParameters);

    } else {

        Client client = ClientProxy.getClient(portType);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();

        conduit.setTlsClientParameters(tlsClientParameters);
    }
}

/**
 * 
     * Gets the trust manager
 *  
 * @return keystore
 * @throws NoSuchAlgorithmException
 * @throws KeyStoreException
 * @throws ResourceException 
 * @throws IOException 
 * @throws CertificateException 
 */
private static TrustManager[] getServerTrustManager() throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, ResourceException {

    TrustManagerFactory factory = TrustManagerFactory.getInstance("X.509");

    KeyStore trustStore = KeyStore.getInstance("JKS");

    trustStore.load(new ClassPathResource(ConfigUtils.getInstance().getServerKeyStoreFileName()).getInputStream(), ConfigUtils.getInstance().getServerKeystorePassword().toCharArray());

    factory.init(trustStore);       
    return factory.getTrustManagers();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文