MessageDocument response = parser.parseStream(responseStream);  tx.getContext().setResponse(response);  if (requestFailed) {
MessageDocument response; if (!requestFailed) { response = parser.parseStream(responseStream);  tx.getContext().setResponse(response); } else {  try { response = parser.parseStream(responseStream); } catch (Exception e) {    String text=responseStream.toString(); throw new SoapException( "The remote endpoint returned an error,\n" + "but the response could not be parsed\n" + "and turned into a SOAPFault.\n"+text, e,null); }   tx.getContext().setResponse(response);
    public void transmit() {        String destination = wsa.getDestination();        log.debug("Posting to " + destination);        PostMethod method = new ProgressingPostMethod(destination);        method.addRequestHeader("SOAPAction","");        method.addRequestHeader("User-Agent",HttpConstants.ALPINE_VERSION);        //fill in the details        //1. get the message into a byte array        //2. add it        //3. TODO: add files?        File outputFile = null;        OutputStream outToFile = null;        RequestEntity re = null;        try {            try {                try {                    outputFile = File.createTempFile("alpine", ".post");                    outToFile = new BufferedOutputStream(new FileOutputStream(outputFile));                    Serializer serializer = new Serializer(outToFile);                    serializer.write(request);                    serializer.flush();                    outToFile.flush();                    String contentType = HttpConstants.CONTENT_TYPE_TEXT_XML;                    String ctxContentType = (String) tx.getContext().get(ContextConstants.ATTR_SOAP_CONTENT_TYPE);                    if(ctxContentType!=null) {                        contentType=ctxContentType;                    }                    re = new ProgressiveFileUploadRequestEntity(tx, request, outputFile,                            contentType,                            tx.getUploadFeedback(), BLOCKSIZE);                    method.setRequestEntity(re);                } finally {                    if (outToFile != null) {                        outToFile.close();                    }                }            } catch (IOException ioe) {                //error before we even connect to the server                throw new HttpTransportFault(ERROR_DURING_PREPARATION, ioe);            }            InputStream responseStream = null;            try {                int statusCode = httpclient.executeMethod(method);                final boolean requestFailed = statusCode != HttpStatus.SC_OK;                boolean responseIsXml;                //get the content type and drop anything following a semicolon                //this can be null on an empty response                String contentType = getResponseContentType(method);                if(contentType!=null) {                    contentType = HttpBinder.extractBaseContentType(contentType);                    responseIsXml = HttpBinder.isValidSoapContentType(contentType);                } else {                    responseIsXml=false;                }                if (requestFailed &&                        (!responseIsXml || statusCode != HttpStatus.SC_INTERNAL_SERVER_ERROR)) {                    //TODO: treat 500+text/xml response specially, as it is probably a SOAPFault                    log.error("Method failed: " + method.getStatusLine());                    throw new HttpTransportFault(destination, method);                }                //response is 200, but is it HTML?                if (!responseIsXml) {                    HttpTransportFault fault = new HttpTransportFault(destination, method,                            "Wrong content type: expected "                                    + HttpConstants.CONTENT_TYPE_TEXT_XML                                    + " or "                                    + HttpConstants.CONTENT_TYPE_SOAP_XML                                    + " but got ["                                    + contentType                                    + ']');                    throw fault;                }                //extract the response                responseStream = method.getResponseBodyAsStream();                //parse it                SoapMessageParser parser = tx.getContext().createParser();                MessageDocument response = parser.parseStream(responseStream);                //set our response                tx.getContext().setResponse(response);                // if is a fault, turn it into an exception.                if (requestFailed) {                    throw new SoapException(response);                }            } catch (IOException ioe) {                throw new HttpTransportFault(destination, ioe);            } catch (SAXException e) {                throw new HttpTransportFault(destination, e);            } catch (ParsingException e) {                throw new HttpTransportFault(destination, e);            } finally {                if (responseStream != null) {                    try {                        responseStream.close();                    } catch (IOException e) {                        //ignore this.                    }                }                method.releaseConnection();            }        } finally {            if (outputFile != null) {                outputFile.delete();            }        }    }