Search in sources :

Example 1 with UnsupportedMediaException

use of com.sun.xml.ws.server.UnsupportedMediaException in project metro-jax-ws by eclipse-ee4j.

the class SOAPBindingCodec method decode.

@Override
public void decode(InputStream in, String contentType, Packet packet) throws IOException {
    if (contentType == null) {
        contentType = xmlMimeType;
    }
    packet.setContentType(new ContentTypeImpl(contentType));
    preDecode(packet);
    try {
        if (isMultipartRelated(contentType))
            // parse the multipart portion and then decide whether it's MTOM or SwA
            super.decode(in, contentType, packet);
        else if (isFastInfoset(contentType)) {
            if (!ignoreContentNegotiationProperty && packet.contentNegotiation == ContentNegotiation.none)
                throw noFastInfosetForDecoding();
            useFastInfosetForEncoding = true;
            fiSoapCodec.decode(in, contentType, packet);
        } else
            xmlSoapCodec.decode(in, contentType, packet);
    } catch (RuntimeException we) {
        if (we instanceof ExceptionHasMessage || we instanceof UnsupportedMediaException) {
            throw we;
        } else {
            throw new MessageCreationException(version, we);
        }
    }
    postDecode(packet);
}
Also used : MessageCreationException(com.sun.xml.ws.protocol.soap.MessageCreationException) UnsupportedMediaException(com.sun.xml.ws.server.UnsupportedMediaException) ExceptionHasMessage(com.sun.xml.ws.api.message.ExceptionHasMessage)

Example 2 with UnsupportedMediaException

use of com.sun.xml.ws.server.UnsupportedMediaException in project metro-jax-ws by eclipse-ee4j.

the class HttpAdapter method invokeAsync.

public void invokeAsync(final WSHTTPConnection con, final CompletionCallback callback) throws IOException {
    if (handleGet(con)) {
        callback.onCompletion();
        return;
    }
    final Pool<HttpToolkit> currentPool = getPool();
    final HttpToolkit tk = currentPool.take();
    final Packet request;
    try {
        request = decodePacket(con, tk.codec);
    } catch (ExceptionHasMessage e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
        Packet response = new Packet();
        response.setMessage(e.getFaultMessage());
        encodePacket(response, con, tk.codec);
        currentPool.recycle(tk);
        con.close();
        callback.onCompletion();
        return;
    } catch (UnsupportedMediaException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
        Packet response = new Packet();
        con.setStatus(WSHTTPConnection.UNSUPPORTED_MEDIA);
        encodePacket(response, con, tk.codec);
        currentPool.recycle(tk);
        con.close();
        callback.onCompletion();
        return;
    }
    endpoint.process(request, new WSEndpoint.CompletionCallback() {

        @Override
        public void onCompletion(@NotNull Packet response) {
            try {
                try {
                    encodePacket(response, con, tk.codec);
                } catch (IOException ioe) {
                    LOGGER.log(Level.SEVERE, ioe.getMessage(), ioe);
                }
                currentPool.recycle(tk);
            } finally {
                con.close();
                callback.onCompletion();
            }
        }
    }, null);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) UnsupportedMediaException(com.sun.xml.ws.server.UnsupportedMediaException) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) IOException(java.io.IOException) ExceptionHasMessage(com.sun.xml.ws.api.message.ExceptionHasMessage)

Example 3 with UnsupportedMediaException

use of com.sun.xml.ws.server.UnsupportedMediaException in project metro-jax-ws by eclipse-ee4j.

the class MtomCodec method decode.

@Override
protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException {
    // TODO shouldn't we check for SOAP1.1/SOAP1.2 and throw
    // TODO UnsupportedMediaException like StreamSOAPCodec
    String charset = null;
    String ct = mpp.getRootPart().getContentType();
    if (ct != null) {
        charset = new ContentTypeImpl(ct).getCharSet();
    }
    if (charset != null && !Charset.isSupported(charset)) {
        throw new UnsupportedMediaException(charset);
    }
    if (charset != null) {
        packet.invocationProperties.put(DECODED_MESSAGE_CHARSET, charset);
    } else {
        packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
    }
    // we'd like to reuse those reader objects but unfortunately decoder may be reused
    // before the decoded message is completely used.
    XMLStreamReader mtomReader = new MtomXMLStreamReaderEx(mpp, XMLStreamReaderFactory.create(null, mpp.getRootPart().asInputStream(), charset, true));
    packet.setMessage(codec.decode(mtomReader, new MimeAttachmentSet(mpp)));
    packet.setMtomFeature(mtomFeature);
    packet.setContentType(mpp.getContentType());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) UnsupportedMediaException(com.sun.xml.ws.server.UnsupportedMediaException) MimeAttachmentSet(com.sun.xml.ws.message.MimeAttachmentSet)

Example 4 with UnsupportedMediaException

use of com.sun.xml.ws.server.UnsupportedMediaException in project metro-jax-ws by eclipse-ee4j.

the class SOAPBindingCodec method decode.

@Override
public void decode(ReadableByteChannel in, String contentType, Packet packet) {
    if (contentType == null) {
        throw new UnsupportedMediaException();
    }
    preDecode(packet);
    try {
        if (isMultipartRelated(contentType))
            super.decode(in, contentType, packet);
        else if (isFastInfoset(contentType)) {
            if (packet.contentNegotiation == ContentNegotiation.none)
                throw noFastInfosetForDecoding();
            useFastInfosetForEncoding = true;
            fiSoapCodec.decode(in, contentType, packet);
        } else
            xmlSoapCodec.decode(in, contentType, packet);
    } catch (RuntimeException we) {
        if (we instanceof ExceptionHasMessage || we instanceof UnsupportedMediaException) {
            throw we;
        } else {
            throw new MessageCreationException(version, we);
        }
    }
    postDecode(packet);
}
Also used : MessageCreationException(com.sun.xml.ws.protocol.soap.MessageCreationException) UnsupportedMediaException(com.sun.xml.ws.server.UnsupportedMediaException) ExceptionHasMessage(com.sun.xml.ws.api.message.ExceptionHasMessage)

Aggregations

UnsupportedMediaException (com.sun.xml.ws.server.UnsupportedMediaException)4 ExceptionHasMessage (com.sun.xml.ws.api.message.ExceptionHasMessage)3 MessageCreationException (com.sun.xml.ws.protocol.soap.MessageCreationException)2 Packet (com.sun.xml.ws.api.message.Packet)1 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)1 MimeAttachmentSet (com.sun.xml.ws.message.MimeAttachmentSet)1 IOException (java.io.IOException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1