FileDocCategorySizeDatePackage
HttpPoster.javaAPI DocExample7079Tue May 29 16:56:32 BST 2007com.sun.xml.ws.mex.client

HttpPoster

public class HttpPoster extends Object
Class that handles making the HTTP POST request to a service.

Fields Summary
private static final Logger
logger
Constructors Summary
Methods Summary
private java.net.HttpURLConnectioncreateConnection(java.net.URL url)

        
        return (HttpURLConnection) url.openConnection();
    
public java.io.InputStreammakeGetCall(java.lang.String address)
This method is called by ServiceDescriptorImpl when a metadata response contains a mex location element. The location element contains an address of a metadata document that can be retrieved with an HTTP GET call.

param
address The address of the document.
return
The java.io.InputStream returned by the http url connection.

        final URL url = new URL(address);
        final HttpURLConnection conn = createConnection(url);
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-Type",
            "application/x-www-form-urlencoded"); // taken from wsimport
        try {
            return conn.getInputStream();
        } catch (IOException ioe) {
            outputErrorStream(conn);
            
            // this exception is caught within the mex code and is logged there
            throw ioe;
        }
    
private voidoutputErrorStream(java.net.HttpURLConnection conn)

        final InputStream error = conn.getErrorStream();
        if (error != null) {
            final BufferedReader reader = new BufferedReader(
                new InputStreamReader(error));
            try {
                if (logger.isLoggable(ERROR_LOG_LEVEL)) {
                    logger.log(ERROR_LOG_LEVEL,
                        MessagesMessages.MEX_0010_ERROR_FROM_SERVER());
                    String line = reader.readLine();
                    while (line != null) {
                        logger.log(ERROR_LOG_LEVEL, line);
                        line = reader.readLine();
                    }
                    logger.log(ERROR_LOG_LEVEL,
                        MessagesMessages.MEX_0011_ERROR_FROM_SERVER_END());
                }
            } catch (IOException ioe) {
                // This exception has no more impact.
                logger.log(ERROR_LOG_LEVEL,
                    MessagesMessages.MEX_0012_READING_ERROR_STREAM_FAILURE(),
                    ioe);
            } finally {
                try {
                    reader.close();
                } catch (IOException ex) {
                    // This exception has no more impact.
                    logger.log(ERROR_LOG_LEVEL,
                        MessagesMessages.MEX_0013_CLOSING_ERROR_STREAM_FAILURE(),
                        ex);
                }
            }
        }
    
java.io.InputStreampost(java.lang.String request, java.lang.String address, java.lang.String contentType)
Makes the request to the service. It is expected that this method may throw IOException several times before metadata is returned successfully.

param
request A String containing the xml that will be the payload of the message.
param
address Address of the service.
return
The java.io.InputStream returned by the http url connection.


                                                                      
          
             
        
        final URL url = new URL(address);
        final HttpURLConnection conn = createConnection(url);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", contentType);
        conn.setRequestProperty("SOAPAction", GET_REQUEST);

        final Writer writer = new OutputStreamWriter(conn.getOutputStream());
        writer.write(request);
        writer.flush();

        try {
            return conn.getInputStream();
        } catch (IOException ioe) {
            outputErrorStream(conn);
            
            // this exception is caught within the mex code and is logged there
            throw ioe;
        } finally {
            writer.close();
        }