Example usage for javax.xml.ws.http HTTPException getMessage

List of usage examples for javax.xml.ws.http HTTPException getMessage

Introduction

In this page you can find the example usage for javax.xml.ws.http HTTPException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:microsoft.exchange.webservices.data.core.request.ServiceRequestBase.java

/**
 * Reads the response.//from w  w  w  .  java 2 s  .c  o m
 *
 * @param response HTTP web request
 * @return response response object
 * @throws Exception on error
 */
protected T readResponse(HttpWebRequest response) throws Exception {
    T serviceResponse;

    if (!response.getResponseContentType().startsWith("text/xml")) {
        throw new ServiceRequestException("The response received from the service didn't contain valid XML.");
    }

    /**
     * If tracing is enabled, we read the entire response into a
     * MemoryStream so that we can pass it along to the ITraceListener. Then
     * we parse the response from the MemoryStream.
     */

    try {
        this.getService().processHttpResponseHeaders(TraceFlags.EwsResponseHttpHeaders, response);

        if (this.getService().isTraceEnabledFor(TraceFlags.EwsResponse)) {
            ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
            InputStream serviceResponseStream = ServiceRequestBase.getResponseStream(response);

            int data = serviceResponseStream.read();
            while (data != -1) {
                memoryStream.write(data);
                data = serviceResponseStream.read();
            }

            this.traceResponse(response, memoryStream);
            ByteArrayInputStream memoryStreamIn = new ByteArrayInputStream(memoryStream.toByteArray());
            EwsServiceXmlReader ewsXmlReader = new EwsServiceXmlReader(memoryStreamIn, this.getService());
            serviceResponse = this.readResponse(ewsXmlReader);
            serviceResponseStream.close();
            memoryStream.flush();
        } else {
            InputStream responseStream = ServiceRequestBase.getResponseStream(response);
            EwsServiceXmlReader ewsXmlReader = new EwsServiceXmlReader(responseStream, this.getService());
            serviceResponse = this.readResponse(ewsXmlReader);
        }

        return serviceResponse;
    } catch (HTTPException e) {
        if (e.getMessage() != null) {
            this.getService().processHttpResponseHeaders(TraceFlags.EwsResponseHttpHeaders, response);
        }
        throw new ServiceRequestException(String.format("The request failed. %s", e.getMessage()), e);
    } catch (IOException e) {
        throw new ServiceRequestException(String.format("The request failed. %s", e.getMessage()), e);
    } finally { // close the underlying response
        response.close();
    }
}