Search in sources :

Example 1 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class StreamMessageTest method getInputStream.

/*
    private DOMSource toDOMSource(Source source) throws Exception {
        if (source instanceof DOMSource) {
            return (DOMSource)source;
        }
        Transformer trans = TransformerFactory.newInstance().newTransformer();
        DOMResult result = new DOMResult();
        trans.transform(source, result);
        return new DOMSource(result.getNode());
    }
    */
private InputStream getInputStream(Source source) throws Exception {
    Transformer trans = TransformerFactory.newInstance().newTransformer();
    ByteArrayBuffer bab = new ByteArrayBuffer();
    StreamResult result = new StreamResult(bab);
    trans.transform(source, result);
    return bab.newInputStream();
}
Also used : Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 2 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class XMLHTTPBindingCodec method transformDataSource.

public static DataSource transformDataSource(DataSource in, boolean isFastInfoset, boolean useFastInfoset, WSFeatureList f) {
    try {
        if (isFastInfoset && !useFastInfoset) {
            // Convert from Fast Infoset to XML
            Codec codec = new XMLHTTPBindingCodec(f);
            Packet p = new Packet();
            codec.decode(in.getInputStream(), in.getContentType(), p);
            p.getMessage().getAttachments();
            codec.getStaticContentType(p);
            ByteArrayBuffer bos = new ByteArrayBuffer();
            ContentType ct = codec.encode(p, bos);
            return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
        } else if (!isFastInfoset && useFastInfoset) {
            // Convert from XML to Fast Infoset
            Codec codec = new XMLHTTPBindingCodec(f);
            Packet p = new Packet();
            codec.decode(in.getInputStream(), in.getContentType(), p);
            p.contentNegotiation = ContentNegotiation.optimistic;
            p.getMessage().getAttachments();
            codec.getStaticContentType(p);
            ByteArrayBuffer bos = new ByteArrayBuffer();
            com.sun.xml.ws.api.pipe.ContentType ct = codec.encode(p, bos);
            return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
        }
    } catch (Exception ex) {
        throw new WebServiceException(ex);
    }
    return in;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Codec(com.sun.xml.ws.api.pipe.Codec) XMLCodec(com.sun.xml.ws.encoding.xml.XMLCodec) ContentType(com.sun.xml.ws.api.pipe.ContentType) WebServiceException(jakarta.xml.ws.WebServiceException) IOException(java.io.IOException) WebServiceException(jakarta.xml.ws.WebServiceException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 3 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class HttpAdapter method decodePacket.

/*
     *
     * @param con
     * @param codec
     * @return
     * @throws IOException
     *         ExceptionHasMessage exception that contains particular fault message
     *         UnsupportedMediaException to indicate to send 415 error code
     */
private Packet decodePacket(@NotNull WSHTTPConnection con, @NotNull Codec codec) throws IOException {
    String ct = con.getRequestHeader("Content-Type");
    InputStream in = con.getInput();
    Packet packet = new Packet();
    packet.soapAction = fixQuotesAroundSoapAction(con.getRequestHeader("SOAPAction"));
    packet.wasTransportSecure = con.isSecure();
    packet.acceptableMimeTypes = con.getRequestHeader("Accept");
    packet.addSatellite(con);
    addSatellites(packet);
    packet.isAdapterDeliversNonAnonymousResponse = true;
    packet.component = this;
    packet.transportBackChannel = new Oneway(con);
    packet.webServiceContextDelegate = con.getWebServiceContextDelegate();
    packet.setState(Packet.State.ServerRequest);
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        buf.write(in);
        in.close();
        dump(buf, "HTTP request", con.getRequestHeaders());
        in = buf.newInputStream();
    }
    codec.decode(in, ct, packet);
    return packet;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) InputStream(java.io.InputStream) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 4 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class HttpAdapter method encodePacket.

private void encodePacket(@NotNull Packet packet, @NotNull WSHTTPConnection con, @NotNull Codec codec) throws IOException {
    if (isNonAnonymousUri(packet.endpointAddress) && packet.getMessage() != null) {
        try {
            // Message is targeted to non-anonymous response endpoint.
            // After call to non-anonymous processor, typically, packet.getMessage() will be null
            // however, processors could use this pattern to modify the response sent on the back-channel,
            // e.g. send custom HTTP headers with the HTTP 202
            packet = getNonAnonymousResponseProcessor().process(packet);
        } catch (RuntimeException re) {
            // if processing by NonAnonymousResponseProcessor fails, new SOAPFaultMessage is created to be sent
            // to back-channel client
            SOAPVersion soapVersion = packet.getBinding().getSOAPVersion();
            Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, re);
            packet = packet.createServerResponse(faultMsg, packet.endpoint.getPort(), null, packet.endpoint.getBinding());
        }
    }
    if (con.isClosed()) {
        // Connection is already closed
        return;
    }
    Message responseMessage = packet.getMessage();
    addStickyCookie(con);
    addReplicaCookie(con, packet);
    if (responseMessage == null) {
        if (!con.isClosed()) {
            // for example, 415 may have been set earlier for Unsupported Content-Type
            if (con.getStatus() == 0) {
                con.setStatus(WSHTTPConnection.ONEWAY);
            }
            OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
            if (dump || LOGGER.isLoggable(Level.FINER)) {
                ByteArrayBuffer buf = new ByteArrayBuffer();
                codec.encode(packet, buf);
                dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
                buf.writeTo(os);
            } else {
                codec.encode(packet, os);
            }
            // close the response channel now
            try {
                // no payload
                os.close();
            } catch (IOException e) {
                throw new WebServiceException(e);
            }
        }
    } else {
        if (con.getStatus() == 0) {
            // if the appliation didn't set the status code,
            // set the default one.
            con.setStatus(responseMessage.isFault() ? HttpURLConnection.HTTP_INTERNAL_ERROR : HttpURLConnection.HTTP_OK);
        }
        if (isClientErrorStatus(con.getStatus())) {
            OutputStream os = con.getOutput();
            if (dump || LOGGER.isLoggable(Level.FINER)) {
                ByteArrayBuffer buf = new ByteArrayBuffer();
                writeClientError(con.getStatus(), buf, packet);
                dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
                buf.writeTo(os);
            } else {
                writeClientError(con.getStatus(), os, packet);
            }
            os.close();
            return;
        }
        ContentType contentType = codec.getStaticContentType(packet);
        if (contentType != null) {
            con.setContentTypeResponseHeader(contentType.getContentType());
            OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
            if (dump || LOGGER.isLoggable(Level.FINER)) {
                ByteArrayBuffer buf = new ByteArrayBuffer();
                codec.encode(packet, buf);
                dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
                buf.writeTo(os);
            } else {
                codec.encode(packet, os);
            }
            os.close();
        } else {
            ByteArrayBuffer buf = new ByteArrayBuffer();
            contentType = codec.encode(packet, buf);
            con.setContentTypeResponseHeader(contentType.getContentType());
            if (dump || LOGGER.isLoggable(Level.FINER)) {
                dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
            }
            OutputStream os = con.getOutput();
            buf.writeTo(os);
            os.close();
        }
    }
}
Also used : Message(com.sun.xml.ws.api.message.Message) ExceptionHasMessage(com.sun.xml.ws.api.message.ExceptionHasMessage) WebServiceException(jakarta.xml.ws.WebServiceException) ContentType(com.sun.xml.ws.api.pipe.ContentType) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 5 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class AbstractSchemaValidationTube method createDOM.

private Document createDOM(SDDocument doc) {
    // Get infoset
    ByteArrayBuffer bab = new ByteArrayBuffer();
    try {
        doc.writeTo(null, resolver, bab);
    } catch (IOException ioe) {
        throw new WebServiceException(ioe);
    }
    // Convert infoset to DOM
    Transformer trans = XmlUtil.newTransformer();
    // doc.getURL().toExternalForm());
    Source source = new StreamSource(bab.newInputStream(), null);
    DOMResult result = new DOMResult();
    try {
        trans.transform(source, result);
    } catch (TransformerException te) {
        throw new WebServiceException(te);
    }
    return (Document) result.getNode();
}
Also used : Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) WebServiceException(jakarta.xml.ws.WebServiceException) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) Document(org.w3c.dom.Document) SDDocument(com.sun.xml.ws.api.server.SDDocument) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) TransformerException(javax.xml.transform.TransformerException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Aggregations

ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)29 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)13 Message (com.sun.xml.ws.api.message.Message)9 WebServiceException (jakarta.xml.ws.WebServiceException)9 Packet (com.sun.xml.ws.api.message.Packet)7 ClientTransportException (com.sun.xml.ws.client.ClientTransportException)7 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)6 SOAPMessage (jakarta.xml.soap.SOAPMessage)6 IOException (java.io.IOException)6 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)5 ObjectInputStream (java.io.ObjectInputStream)5 ObjectOutputStream (java.io.ObjectOutputStream)5 Transformer (javax.xml.transform.Transformer)5 StreamSource (javax.xml.transform.stream.StreamSource)5 XMLInputFactory (javax.xml.stream.XMLInputFactory)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 URL (java.net.URL)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 TransformerException (javax.xml.transform.TransformerException)3 DOMResult (javax.xml.transform.dom.DOMResult)3