简体   繁体   English

SOAP客户端 - ProtocolException:服务器重定向次数过多

[英]SOAP client - ProtocolException: Server redirected too many times

I tried to create SOAP client to communicate with server. 我试图创建SOAP客户端与服务器进行通信。 Everything runs smoothly with C# but on Java I still get some exceptions. 使用C#,一切运行顺利,但在Java上我仍然有一些例外。

Our company is behind proxy. 我们公司落后于代理。 SOAP service is behind basic authentication. SOAP服务是基本身份验证的基础。

Small behind story: I generated code with Java generate schema with JAX_WS from wsdl 小故事:我使用来自wsdl的JAX_WS生成Java生成模式的代码

/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.9-b130926.1035
 * Generated source version: 2.2
 */
@WebServiceClient(name = "ServiceWs", targetNamespace = "http://www.web.org/Schema/Klient/Service", wsdlLocation = "https://app.web.org/KlientWS/ServiceWs.wsdl")
public class ServiceWs
        extends Service {
    public ServiceWs(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }
    ...
}

And with implementation authentication and cookies of some kind: 并通过实现身份验证和某种cookie:

CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
Authenticator.setDefault(new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
            System.setProperty("java.net.useSystemProxies", "true");

            System.setProperty("proxySet", "true");
            System.setProperty("proxyHost", localProxyHost);
            System.setProperty("proxyPort", localProxyPort);
            System.setProperty("proxyUser", localProxyUser);
            System.setProperty("proxyPassword", localProxyPassword);
            String prot = getRequestingProtocol().toLowerCase();

            // Requesting protocol
            System.setProperty(prot + ".proxyHost", localProxyHost);
            System.setProperty(prot + ".proxyPort", localProxyPort);
            System.setProperty(prot + ".proxyUser", localProxyUser);
            System.setProperty(prot + ".proxyPassword", localProxyPassword);

//          if (getRequestorType() == RequestorType.PROXY) {
//              if (getRequestingHost().toLowerCase().equals(localProxyHost.toLowerCase())) {
//                  if (Integer.parseInt(localProxyPort) == getRequestingPort()) {
//                      // Seems to be OK.
//                      return new PasswordAuthentication(localProxyUser, localProxyPassword.toCharArray());
//                  }
//              }
//          } else
            if (getRequestorType() == RequestorType.SERVER) {
                return new PasswordAuthentication(username, password.toCharArray());
            }
            return null;
        }
    });

And implementation of client 并实施客户端

ServiceWs client;
try {
    URL url = new URL(endpointAddress);
    client = new ServiceWs(url);
} catch (IOException e) {
    client = new ServiceWs();
}

And it just fails there with ProtocolException with too many redirections while connecting to wsdl file. 在连接到wsdl文件时,它只是在ProtocolException失败时有太多的重定向。

shorter version 更短的版本

org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
Caused by: java.net.ProtocolException: Server redirected too many  times (20)

longer verison 更长的verison

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.

    at org.apache.cxf.jaxws.ServiceImpl.initialize(ServiceImpl.java:163)
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:129)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:82)
    at javax.xml.ws.Service.<init>(Service.java:77)
    at xx.company.project.service.ws.ServiceWs.<init>(ServiceWs.java:45)
    at xx.company.project.service.UploadWebService.fillService(UploadWebService.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:87)
    at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:218)
    at org.apache.cxf.jaxws.ServiceImpl.initialize(ServiceImpl.java:161)
    ... 35 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'https://app.web.org/KlientWS/ServiceWs.wsdl'.: java.net.ProtocolException: Server redirected too many  times (20)
    at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2198)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2390)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2422)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:265)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:164)
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:85)
    ... 37 more
Caused by: java.net.ProtocolException: Server redirected too many  times (20)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1884)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2188)
    ... 42 more

I know authentication details are correct and web address is correct, as I can connect to the wsdl file manually. 我知道身份验证详细信息正确且网址正确,因为我可以手动连接到wsdl文件。

The problem was, as @beat suggested in the proxy settings. 问题是,正如@beat在代理设置中建议的那样。 I have not set the NTLM properly, as our proxy user is in different domain. 我没有正确设置NTLM,因为我们的代理用户位于不同的域中。

The code to be set was System.setProperty("http.auth.ntlm.domain", domain); 要设置的代码是System.setProperty("http.auth.ntlm.domain", domain); and after setting this everything started to work as intended. 设置完成后,一切都按预期开始工作。

More to be seen in J2SE Proxy Authentication . J2SE代理身份验证中可以看到更多内容。

private void createAuthentication(String localProxyHost, String localProxyPort, 
    String localProxyUser, String localProxyPassword, String domain, 
    String username, String password) {

    if (!prepared) {
        System.setProperty("java.net.useSystemProxies", "true");

        System.setProperty("http.auth.ntlm.domain", domain);
        System.setProperty("proxyHost", localProxyHost);
        System.setProperty("proxyPort", localProxyPort);
        System.setProperty("proxyUser", localProxyUser);
        System.setProperty("proxyPassword", localProxyPassword);

        prepared = true;
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
        Authenticator.setDefault(new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
    }
}

As requested by Polostor, I try to write an answer. 按照Polostor的要求,我试着写一个答案。 NTLMv2 Proxies are authenticating the user, and if not sucessful redirect you. NTLMv2代理正在对用户进行身份验证,如果没有成功则重定向您。

As I had a lot of issues with different proxies at different sites, I do recommend using proxy-vole . 由于我在不同站点的不同代理有很多问题,我建议使用proxy-vole This will do an automatic setup of your proxies based on the platform settings. 这将根据平台设置自动设置代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.net.ProtocolException: 服务器重定向次数过多 (20) - java.net.ProtocolException: Server redirected too many times (20) java.net.ProtocolException: 服务器重定向次数过多 - java.net.ProtocolException: Server redirected too many times java.net.Authenticator:java.net.ProtocolException:服务器重定向太多次(20) - java.net.Authenticator : java.net.ProtocolException: Server redirected too many times (20) 获取“java.net.ProtocolException:服务器重定向次数太多”错误 - Getting “java.net.ProtocolException: Server redirected too many times” Error 服务器重定向太多次 - Server redirected too many times @PreAuthorize(“ isAuthenticated()”)重定向服务器太多次 - @PreAuthorize(“isAuthenticated()”) redirected server too many times Java HttpURLConnection问题:服务器重定向次数过多 - Java HttpURLConnection issue: Server redirected too many times 尝试检索 Sharepoint WSDL 失败,并显示“服务器重定向太多次” - Attempt to retrieve Sharepoint WSDL fails with “Server redirected too many times” 尝试使用 HTTPS 进行连接:服务器重定向次数过多 - Tring to connect using HTTPS: Server redirected too many times java.net.ProtocolException:重定向过多:21 Android 应用 - java.net.ProtocolException: Too many redirects: 21 Android App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM