2016-11-28 21 views
1

初めてこのサイトに質問を投稿する。私は署名された(ヘッダーx509)SOAPリクエストを生成し、Webサービスが存在するhttps URLに提出する必要があるプロジェクトに取り組んできました。これまで私はSigned SOAPリクエストを生成することができましたが、リクエストを送信するときにソケットが閉じられた状態になっています。誰も私がこのエラーを引き起こす可能性があります私のコードが不足している把握するのに役立つことができます。前もって感謝します!以下はJavaソケットが閉じている - SOAPリクエストを投稿するとき

私がリクエストを投稿し、エラーてる方法については、私のコードです:

  SSLContext sslcontext = SSLContexts.custom() 
        .loadTrustMaterial(new File("my keystore"), "mypassword".toCharArray(), 
          new TrustSelfSignedStrategy()) 
        .build(); 

      SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
        sslcontext, 
        new String[] { "TLSv1" }, 
        null, 
        SSLConnectionSocketFactory.getDefaultHostnameVerifier()); 
      RequestConfig requestConfig = RequestConfig.custom() 
        .setSocketTimeout(300 * 1000) 
        .setConnectTimeout(300 * 1000) 
        .setConnectionRequestTimeout(300 * 1000) 
        .build(); 
      HttpClient httpclient = HttpClients.custom() //CloseableHttpClient 
        .setDefaultRequestConfig(requestConfig) 
        .setSSLSocketFactory(sslsf) 
        .build(); 

      HttpPost httpPost; 
      httpPost = new HttpPost("https://my webservice"); 

      httpPost.setHeader("Content-type", "test/xml"); 

      File input = new File(esbXmlFile); 

      InputStream inputStream = new FileInputStream(input); 
      InputStreamEntity inputStreamEntity = new InputStreamEntity(inputStream); 
      httpPost.setEntity(inputStreamEntity); 


      String content = null; 
      int statusCode = 1; //statusCode is response code form WS. 
      try 
      { 
       HttpResponse response = httpclient.execute(httpPost); 
       statusCode = response.getStatusLine().getStatusCode(); 
       System.out.println("statusCode : " + statusCode); 
       HttpEntity entity = response.getEntity(); 
       content = EntityUtils.toString(entity); 

      } 
      catch (SocketException e) { 
       e.getStackTrace(); 
      } 
      catch (IOException e) { 
       e.getStackTrace(); 
      } 

I get this error: 
      DEBUG (main) [org.apache.http.conn.ssl.SSLConnectionSocketFactory] - Starting handshake 
     2016-11-28 16:24:04,019 DEBUG (main) [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] - http-outgoing-1: Shutdown connection 
     2016-11-28 16:24:04,019 DEBUG (main) [org.apache.http.impl.execchain.MainClientExec] - Socket is closed 
     java.net.SocketException: Socket is closed 
       at java.net.Socket.setSoLinger(Socket.java:986) 
       at org.apache.http.impl.BHttpConnectionBase.shutdown(BHttpConnectionBase.java:305) 
       at org.apache.http.impl.conn.DefaultManagedHttpClientConnection.shutdown(DefaultManagedHttpClientConnection.java:97) 
       at org.apache.http.impl.conn.LoggingManagedHttpClientConnection.shutdown(LoggingManagedHttpClientConnection.java:89) 
       at org.apache.http.impl.conn.CPoolEntry.shutdownConnection(CPoolEntry.java:74) 
       at org.apache.http.impl.conn.CPoolProxy.shutdown(CPoolProxy.java:96) 
       at org.apache.http.impl.execchain.ConnectionHolder.abortConnection(ConnectionHolder.java:127) 
       at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:352) 
       at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) 
       at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) 
       at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) 
       at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) 
       at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) 
       at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) 
       at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) 

答えて

0

たぶんあなたが設定する必要があります。 httpPost.setHeader(「コンテンツタイプ」、「テスト/ XMLを」 ); 〜 httpPost.setHeader( "Content-type"、 "text/xml"); 違いはtest/xml into text/xml

です
関連する問題