Java Code Examples for com.sun.xml.internal.ws.util.StreamUtils#hasSomeData()

The following examples show how to use com.sun.xml.internal.ws.util.StreamUtils#hasSomeData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLMessage.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 2
Source File: XMLMessage.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 3
Source File: XMLMessage.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 4
Source File: XMLMessage.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 5
Source File: XMLMessage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 6
Source File: XMLMessage.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 7
Source File: XMLMessage.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 8
Source File: XMLMessage.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Message create(final String ct, InputStream in, WSFeatureList f) {
    Message data;
    try {
        in = StreamUtils.hasSomeData(in);
        if (in == null) {
            return Messages.createEmpty(SOAPVersion.SOAP_11);
        }

        if (ct != null) {
            final ContentType contentType = new ContentType(ct);
            final int contentTypeId = identifyContentType(contentType);
            if ((contentTypeId & MIME_MULTIPART_FLAG) != 0) {
                data = new XMLMultiPart(ct, in, f);
            } else if ((contentTypeId & PLAIN_XML_FLAG) != 0) {
                data = new XmlContent(ct, in, f);
            } else {
                data = new UnknownContent(ct, in);
            }
        } else {
            // According to HTTP spec 7.2.1, if the media type remain
            // unknown, treat as application/octet-stream
            data = new UnknownContent("application/octet-stream", in);
        }
    } catch(Exception ex) {
        throw new WebServiceException(ex);
    }
    return data;
}
 
Example 9
Source File: HttpTransportPipe.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    con.readResponseCodeAndMessage();   // throws IOE
    recordCookies(request, con);

    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf,"HTTP response - "+request.endpointAddress+" - "+con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }

    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {                     // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if(responseStream != null) {
            responseStream.close();         // No data, so close the stream
            responseStream = null;
        }

    }

    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    checkStatusCode(responseStream, con); // throws ClientTransportException

    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}
 
Example 10
Source File: HttpTransportPipe.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    con.readResponseCodeAndMessage();   // throws IOE
    recordCookies(request, con);

    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf,"HTTP response - "+request.endpointAddress+" - "+con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }

    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {                     // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if(responseStream != null) {
            responseStream.close();         // No data, so close the stream
            responseStream = null;
        }

    }

    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    checkStatusCode(responseStream, con); // throws ClientTransportException

    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}
 
Example 11
Source File: HttpTransportPipe.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    con.readResponseCodeAndMessage();   // throws IOE
    recordCookies(request, con);

    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf,"HTTP response - "+request.endpointAddress+" - "+con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }

    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {                     // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if(responseStream != null) {
            responseStream.close();         // No data, so close the stream
            responseStream = null;
        }

    }

    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    checkStatusCode(responseStream, con); // throws ClientTransportException

    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}
 
Example 12
Source File: HttpTransportPipe.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    con.readResponseCodeAndMessage();   // throws IOE
    recordCookies(request, con);

    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf,"HTTP response - "+request.endpointAddress+" - "+con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }

    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {                     // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if(responseStream != null) {
            responseStream.close();         // No data, so close the stream
            responseStream = null;
        }

    }

    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    checkStatusCode(responseStream, con); // throws ClientTransportException

    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}
 
Example 13
Source File: HttpTransportPipe.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    con.readResponseCodeAndMessage();   // throws IOE
    recordCookies(request, con);

    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf,"HTTP response - "+request.endpointAddress+" - "+con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }

    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {                     // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if(responseStream != null) {
            responseStream.close();         // No data, so close the stream
            responseStream = null;
        }

    }

    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    checkStatusCode(responseStream, con); // throws ClientTransportException

    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}
 
Example 14
Source File: HttpTransportPipe.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    con.readResponseCodeAndMessage();   // throws IOE
    recordCookies(request, con);

    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf,"HTTP response - "+request.endpointAddress+" - "+con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }

    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {                     // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if(responseStream != null) {
            responseStream.close();         // No data, so close the stream
            responseStream = null;
        }

    }

    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    checkStatusCode(responseStream, con); // throws ClientTransportException

    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}
 
Example 15
Source File: HttpTransportPipe.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    con.readResponseCodeAndMessage();   // throws IOE
    recordCookies(request, con);

    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf,"HTTP response - "+request.endpointAddress+" - "+con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }

    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {                     // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if(responseStream != null) {
            responseStream.close();         // No data, so close the stream
            responseStream = null;
        }

    }

    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    checkStatusCode(responseStream, con); // throws ClientTransportException

    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}