We have developed a J2ME application that uses web services to talk to a server. When an exception occurs on the server a SOAP fault is generated and returned to the J2ME application. The HTTP status code is set to 500 for the returned message as per the specification for web services.

Most J2ME implementations handle this appropriately and generate the correct type of exception back to the calling code. However some S40 implementations (namely the Nokia 6235 and 6255 CDMA phones) throw an IO Exception when it tries to close the output stream that was used to submit the request.

The following code shows the invoke function that submits the web service request to the server. The IO exception occurs during ostream.close() on the 6235 and 6255 whereas other phones successfully close the stream and then process the returned message as required.
Code:
        HttpConnection http = null;

        OutputStream ostream = null;

        InputStream istream = null;

        try {

            // open stream to service endpoint

            http = (HttpConnection)Connector.open(getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY));

            ostream = setupReqStream(http);

            encoder.encode(params, inputType, ostream, null);

            if (ostream != null) {

                        ostream.close();

            }

            istream = setupResStream(http);

            Object result = null;

            if (returnType != null) {

                result = decoder.decode(returnType, istream, http.getEncoding(), http.getLength());

            }
Has anybody else encountered this problem and is there a solution that we may be able to apply?

Thanks a lot,
Nick