2012-06-12 3 views
0

PCRF의/응답에 대한 SOAP 요청을 관리 할 WS 기반 에이전트를 구현 중입니다. 연결은 https 포트를 통해 이루어지며 a key-store file from a trusted certificate을 생성하기 위해 Java 키 저장소 (키 저장 도구)를 사용합니다. 연결이 잘된 것 같습니다 (인증 성공 여부는 확실하지 않지만) 반환 된 정보 (응답)는 읽을 수없는 짧은 문자열입니다.Java 웹 서비스 요청 - 응답 문제

SoapUI 앱을 통한 동일한 절차가 정상적으로 작동합니다.

두 절차의 유일한 차이점은 첫 번째로 키 저장소를 사용하고 두 번째로는 신뢰할 수있는 인증서를 사용한다는 것입니다.

어떻게 해결할 수 있습니까? 나는 어디가 잘못되었는지 이해하지 못한다.

SOAP 메시지 보낸 사람에게 사용 된 Java 소스와 PSRF에서받은 응답을 SoapUI 및 구현 된 WS로 공유하는 데 도움이된다면 도움이 될 것입니다.

package SOAPSender; 

import java.io.BufferedReader; 
import java.io.BufferedWriter; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.io.OutputStreamWriter; 
import java.net.Socket; 

public class DebugMain { 

    public static void main(String[] args) { 
     //PCRFProvisioningAgent temp = new PCRFProvisioningAgent(); 

      loadKeyAndTrustStore(); 

      StringBuffer outputStream = new StringBuffer(); 
      BufferedWriter wr = null; 
      BufferedReader rd = null; 
      Socket sock = null; 
      String outputBuffer = null; 

      try { 

       // Create socket 
       sock = new Socket("10.96.227.219", 8080); 

       // Create header 
       wr = new BufferedWriter(new OutputStreamWriter(
         sock.getOutputStream(), "UTF-8")); 

       String xmlData = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:rm=\"rm:soap\">"+ 
          "<soapenv:Header/>"+ 
          "<soapenv:Body>"+ 
           "<rm:getSubscriber>"+ 
           "<inPara>"+ 
            "<subscriber>"+ 
             "<attribute>"+ 
              "<key>USRIDENTIFIER</key>"+ 
              "<value>284090000000004</value>"+ 
             "</attribute>"+ 
            "</subscriber>"+ 
           "</inPara>"+ 
           "</rm:getSubscriber>"+ 
          "</soapenv:Body>"+ 
         "</soapenv:Envelope>";    

       wr.write("POST https://10.96.227.219:8080/axis/services/ScfPccSoapServiceEndpointPort HTTP/1.1\r\n"); 
       wr.write("User-Agent: https://10.96.227.219:8080/axis/services/ScfPccSoapServiceEndpointPort\r\n"); 
       wr.write("Content-Length: " + xmlData.length() + "\r\n"); 
       wr.write("Content-Type: text/xml;charset=UTF-8\r\n"); 
//    wr.write("SOAPAction: \"rm:soap/ScfPccSoapServiceEndpoint/getSubscriberRequest\"\r\n"); 
       wr.write("SOAPAction: \"\"\r\n"); 
       wr.write("\r\n"); 

       // Send data 
       wr.write(xmlData); 
       wr.flush(); 

       // Read response 
       // exception handler - when connection is reset instead of close 
       // after sending a packet from source 
       char cbuf[] = new char[4096]; 
       int i = 0; 
       // buffer is sized to max 4096 packet size 

       try { 
        rd = new BufferedReader(new InputStreamReader(
          sock.getInputStream(), "UTF-8")); 
        while ((i = rd.read(cbuf)) != -1) { 
         outputStream.append(cbuf, 0, i); 
         int contStartIndex = outputStream.toString().indexOf(
           "Content-Length: ") 
           + "Content-Length: ".length(); 
         int contEndIndex = outputStream.toString().indexOf("\n", 
           contStartIndex) - 1; 
         if (outputStream.toString().indexOf("Content-Length: ") != -1) { 
          int contLength = Integer.valueOf(
            outputStream.toString().substring(
              contStartIndex, contEndIndex)) 
            .intValue(); 
          int headerLength = outputStream 
            .toString() 
            .substring(
              0, 
              outputStream.toString().indexOf(
                "\n\r\n")).length() + 3; 
          // if the message body is complete but there is not an 
          // ending character 
          // while will break 
          // warning - with national characters! content length is 
          // count of bytes not chars 
          if (i - headerLength >= contLength) 
           break; 
         } 
        } 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
       System.out.println("--------\n" + String.valueOf(cbuf) 
         + "\n--------------"); 
       outputBuffer = outputStream.toString(); 

      } catch (Exception e) { 
       e.printStackTrace(); 
      } finally { 
       try { 
        if (wr != null) 
         wr.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       try { 
        if (rd != null) 
         rd.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       try { 
        if (sock != null) 
         sock.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 
    } 

    private static void loadKeyAndTrustStore() { 
     try { 
      // System.out.println(Constants.ROOT_PATH + Constants.STORE_FILE); 
      // AdminLogger.error("Certificate file: " + Constants.ROOT_PATH 
      // + Constants.STORE_FILE); 

      // System load ssl the file of certificate 
      // Load Key store 

      System.out.println(System.getProperty("javax.net.ssl.keyStoreType")); 
      System.setProperty("javax.net.ssl.keyStoreType", "****"); 
      System.out.println(System.getProperty("javax.net.ssl.keyStoreType")); 

      System.out.println(System.getProperty("javax.net.ssl.keyStore")); 
      System.setProperty("javax.net.ssl.keyStore", 
        "****"); 
      System.out.println(System.getProperty("javax.net.ssl.keyStore")); 

      System.out.println(System.getProperty("javax.net.ssl.keyStorePassword")); 
      System.setProperty("javax.net.ssl.keyStorePassword", "****"); 
      System.out.println(System.getProperty("javax.net.ssl.keyStorePassword")); 


      // TrustStore 

      System.out.println(System.getProperty("javax.net.ssl.trustStore")); 
      System.setProperty("javax.net.ssl.trustStore", 
        "****"); 
      System.out.println(System.getProperty("javax.net.ssl.trustStore")); 

      System.out.println(System.getProperty("javax.net.ssl.trustStorePassword")); 
      System.setProperty("javax.net.ssl.trustStorePassword", "****"); 
      System.out.println(System.getProperty("javax.net.ssl.trustStorePassword")); 

     } catch (Exception ex) { 
      // AdminLogger.error(ex, "StartupServlet.loadKeyAndTrustStore"); 
     } 
    } 

} 

는 반응이다 :

... 여기 SoapUI 응용 프로그램의 응답입니다 :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <getSubscriberResponse xmlns="rm:soap"> 
     <result xmlns=""> 
      <resultCode>12302</resultCode> 
      <paras> 
       <key>errorDescription</key> 
       <value>The subscriber does not exist.</value> 
      </paras> 
     </result> 
     </getSubscriberResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

답변

1

소켓이 웹 서비스를 호출 할 수있는 이상적인 방법은 아니다 Java에서. JAX-WS와 같은 Java API를 사용하십시오. PSRF 웹 서비스에서 WSDL을 가져오고 ws-import 명령을 사용하여 클라이언트 스텁을 생성합니다.

WS-Security로 보안 된 웹 서비스를 호출하려면 JAX-WS 보안 API를 사용해야합니다. jax-ws-consuming-web-service-with-ws-security-and-ws-addressing

감사합니다, Sreehari -

이 스레드를 참조하십시오.

+0

필자는 시스템이 이러한 SOAP 메시지를 PCRF로 보내는 것으로 언급하지 않았지만 Java 버전 1.4.2로 구성되었습니다! – nenito

0

@sreehari가 지적한대로 Sockets은 웹 서비스를 호출하는 데 이상적이지 않습니다. 기본적으로 응용 프로그램 프로토콜 (예 : HTTP/S)의 모든 관련 세부 정보를 직접 구현해야합니다. 그것은 엄청난 사업입니다.

"저수준"을 유지하고 요청을 직접 작성하려면 HttpsUrlConnection을 사용하여 "업그레이드"할 것을 제안합니다.