You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Audino, Jeremy" <je...@philips.com> on 2008/11/20 22:58:04 UTC

2nd call from CXF Client to ServerSocket deadlocks

I'm trying to impliment a simple parse and forward message router using the Java ServerSocket object.
The intention is to listen on a port for clients, forward to streams to a service listening on another port,
and pass along the response once completed.

I have a ServerSocket listing on a port that reads the input stream until it see's the SOAP XML terminator.
Once detected, the expected response is written to the output stream.

This works exactly once. When the second call to the server occurs just the HTTP header is received, no
SOAP XML.... This works fine going from CXF Client to CXF Server and gSoap Client to CXF Server. Is it possible
to respond to a CXF client request with the Java Socket classes? Most likey one of the streams is locked, but
I can't seem to figure out a remedy.

First POST:

POST /services/Logger HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: "log"
Accept: *
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0_10-rc2
Host: localhost:8080
Connection: keep-alive
Content-Length: 311

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:LogParams xmlns:ns2="http://com/philips/cirs/logger"><messageLogLevel>INFO</messageLogLevel><p
rocessName>jeremy</processName><message>Obtained reference to Logger Service.</message></ns2:LogParams></soap:Body></soap:Envelope>

Return String:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 209
Server: Jetty(6.1.9)

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:ResultCode xmlns:ns2="http://com/philips/cirs/logger"><result>SUCCESS</result></ns2:ResultCode
></soap:Body></soap:Envelope>

Second Post:

POST /services/Logger HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: "log"
Accept: *
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0_10-rc2
Host: localhost:8080
Connection: keep-alive
Content-Length: 308

<and it stops here>

My Server is implimented as follows:

                  //Listen on 8080---------------------------------
                  ServerSocket ss = new ServerSocket(8080);
                  //-----------------------------------------------

                  PrintWriter outClient = null;
                  BufferedReader inClient = null;
                  Socket conn;
                  String fullLine;

                  int msgCount = 0;
                  while(true)
                  {
                        //Wait for a client to connect. Get its streams-------------------
                        conn = ss.accept();

                        inClient = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                        outClient = new PrintWriter(new BufferedWriter(new OutputStreamWriter(conn.getOutputStream())), true);

                        int in;
                        StringBuffer _m_MessageBuffer = new StringBuffer(1024);

                        String str;

                        // read the remaining stream... (may not contain EOL)
                        do {
                              // also prudent to put some sort of timeout here as well
                              if ( _m_MessageBuffer.toString().endsWith("</soap:Envelope>") // Java (CXF)
                                          || _m_MessageBuffer.toString().endsWith("</SOAP-ENV:Envelope>")) // C++ (gsoap)
                                    break;

                              in = inClient.read();
                              System.out.print((char)in);
                              if (in != -1)
                              {
                                    _m_MessageBuffer.append((char)in);
                              }
                        } while (in != -1);

                        System.out.println("");


                        String xml = new String("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns2:ResultCode xmlns:ns2=\"http://com/philips/cirs/logger\"><result>SUCCESS</result></ns2:ResultCode></soap:Body></soap:Envelope>");

                        StringBuffer ret_string = new StringBuffer();
                        ret_string.append("HTTP/1.1 200 OK\n");
                        ret_string.append("Content-Type: text/xml; charset=utf-8\n");
                        ret_string.append("Content-Length: " + xml.length() + "\n");
                        ret_string.append("Server: Jetty(6.1.9)\n\n");
                        ret_string.append(xml);
                        System.out.println("\nReturn String:\n");
                        System.out.println(ret_string.toString());
                        System.out.flush();

                        outClient.write(ret_string.toString());
                        outClient.flush();

                        inClient.close();
                        outClient.close();
                        conn.close();

The Client is simply uses the classes generated from WSDL.....

LogParams logParams = new LogParams();
logParams.setMessageLogLevel("String");
logParams.setMessage("String");
logParams.setProcessName("String");

String loggerEndpointAddress = http://lcoalhost:8080/services/logger
Logger _m_Logger = new Logger();
LoggerPortType _m_LoggerPort = _m_Logger.getLogger();
BindingProvider bp = (BindingProvider)_m_LoggerPort;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, loggerEndpointAddress);

_m_LoggerPort.log(logParams)

Jeremy F. Audino
Senior Software Development Engineer
Philips Healthcare -- Nuclear Medicine
Tel: 440-483-7444
E-mail: jeremy.audino@philips.com


________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.