2017-10-27 10 views
2

サーバーと通信するSOAPクライアントを作成しようとしました。 C#ではすべてがスムーズに実行されますが、Javaではいくつか例外があります。SOAPクライアント - ProtocolException:サーバーが何度もリダイレクトされました

当社は代理権を有していません。 SOAPサービスは基本認証の背後にあります。物語の背後にある

小: は、私は、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); 
    } 
    ... 
} 

と実装の認証といくつかの種類のクッキーと

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; 
     } 
    }); 

とクライアント

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

そこにはのProtocolExceptionがあり、wsdlファイルに接続中にリダイレクトが多すぎます。

短い

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

長いバージョン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 

私は認証の詳細が正しいと私は手動でWSDLファイルに接続できるようWebアドレスは、正しいことを知っています。

+0

完全なスタックトレース? –

+1

あなたのプロキシと思われます。 NTLMを使用していますか? proxy-voleで試してみるか、またはjavax.net.debugを使用してネットワークの問題をデバッグしてください。 – beat

+0

私たちはNTLMを持っていますが、何か変わるのですか? :/ – Polostor

答えて

2

問題は、@ビートがプロキシ設定で示唆したとおりです。私はプロキシユーザが異なるドメインにあるので、NTLMを適切に設定していません。

設定するコードはSystem.setProperty("http.auth.ntlm.domain", domain);で、これを設定した後、すべてが意図したとおりに動作するようになりました。

J2SE Proxy Authenticationでさらに見ることができます。

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()); 
      } 
     }); 
    } 
} 
1

私はポロスターによって要求されたとおり、答えを書こうとします。 NTLMv2プロキシはユーザーを認証していますが、成功していない場合はリダイレクトします。

異なるサイトで異なるプロキシを使用したときに問題が発生したため、proxy-voleを使用することをおすすめします。これにより、プラットフォームの設定に基づいてプロキシの自動セットアップが行われます。

関連する問題