Search in sources :

Example 1 with MimeHeader

use of javax.xml.soap.MimeHeader in project OpenAM by OpenRock.

the class SAML2Utils method putHeaders.

/**
     * Sets mime headers in HTTP servlet response.
     *
     * @param headers  mime headers to be set.
     * @param response HTTP servlet response.
     */
public static void putHeaders(MimeHeaders headers, HttpServletResponse response) {
    if (debug.messageEnabled()) {
        debug.message("SAML2Util.putHeaders: Header=" + headers.toString());
    }
    Iterator it = headers.getAllHeaders();
    while (it.hasNext()) {
        MimeHeader header = (MimeHeader) it.next();
        String[] values = headers.getHeader(header.getName());
        if (debug.messageEnabled()) {
            debug.message("SAML2Util.putHeaders: Header name=" + header.getName() + ", value=" + Arrays.toString(values));
        }
        if (values.length == 1) {
            response.setHeader(header.getName(), header.getValue());
        } else {
            StringBuilder concatenatedHeaderValues = new StringBuilder();
            for (int i = 0; i < values.length; i++) {
                if (i != 0) {
                    concatenatedHeaderValues.append(',');
                }
                concatenatedHeaderValues.append(values[i]);
            }
            response.setHeader(header.getName(), concatenatedHeaderValues.toString());
        }
    }
}
Also used : MimeHeader(javax.xml.soap.MimeHeader) Iterator(java.util.Iterator)

Example 2 with MimeHeader

use of javax.xml.soap.MimeHeader in project OpenAM by OpenRock.

the class SAMLUtils method setMimeHeaders.

/**
     * Sets the given <code>HttpServletResponse</code> object with the
     * headers in the given <code>MimeHeaders</code> object.
     * @param headers the <code>MimeHeaders</code> object
     * @param response the <code>HttpServletResponse</code> object to which the
     *        headers are to be written.
     */
public static void setMimeHeaders(MimeHeaders headers, HttpServletResponse response) {
    if (headers == null || response == null) {
        debug.message("SAMLUtils.setMimeHeaders : null input");
        return;
    }
    for (Iterator iter = headers.getAllHeaders(); iter.hasNext(); ) {
        MimeHeader header = (MimeHeader) iter.next();
        String[] values = headers.getHeader(header.getName());
        if (values.length == 1) {
            response.setHeader(header.getName(), header.getValue());
        } else {
            StringBuffer concat = new StringBuffer();
            int i = 0;
            while (i < values.length) {
                if (i != 0) {
                    concat.append(',');
                }
                concat.append(values[i++]);
            }
            response.setHeader(header.getName(), concat.toString());
        }
    }
    return;
}
Also used : MimeHeader(javax.xml.soap.MimeHeader) CharacterIterator(java.text.CharacterIterator) Iterator(java.util.Iterator) StringCharacterIterator(java.text.StringCharacterIterator)

Example 3 with MimeHeader

use of javax.xml.soap.MimeHeader in project OpenAM by OpenRock.

the class IDPArtifactResolution method putHeaders.

// puts MIME headers into a HTTPResponse
private static void putHeaders(MimeHeaders headers, HttpServletResponse res) {
    Iterator it = headers.getAllHeaders();
    while (it.hasNext()) {
        MimeHeader header = (MimeHeader) it.next();
        String[] values = headers.getHeader(header.getName());
        if (values.length == 1) {
            res.setHeader(header.getName(), header.getValue());
        } else {
            StringBuilder concat = new StringBuilder();
            int i = 0;
            while (i < values.length) {
                if (i != 0) {
                    concat.append(',');
                }
                concat.append(values[i++]);
            }
            res.setHeader(header.getName(), concat.toString());
        }
    }
}
Also used : MimeHeader(javax.xml.soap.MimeHeader) Iterator(java.util.Iterator)

Example 4 with MimeHeader

use of javax.xml.soap.MimeHeader in project tomee by apache.

the class AxisWsContainer method doService.

protected void doService(final HttpRequest req, final HttpResponse res) throws Exception {
    final org.apache.axis.MessageContext messageContext = new org.apache.axis.MessageContext(null);
    req.setAttribute(WsConstants.MESSAGE_CONTEXT, messageContext);
    messageContext.setClassLoader(classLoader);
    Message responseMessage;
    String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
    final String contentLocation = req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
    final InputStream inputStream = req.getInputStream();
    final Message requestMessage = new Message(inputStream, false, contentType, contentLocation);
    messageContext.setRequestMessage(requestMessage);
    messageContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, req.getURI().getPath());
    messageContext.setProperty(org.apache.axis.MessageContext.TRANS_URL, req.getURI().toString());
    messageContext.setService(service);
    messageContext.setProperty(REQUEST, req);
    messageContext.setProperty(RESPONSE, res);
    messageContext.setProperty(AxisEngine.PROP_DISABLE_PRETTY_XML, Boolean.TRUE);
    final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        try {
            final String characterEncoding = (String) requestMessage.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
            if (characterEncoding != null) {
                messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, characterEncoding);
            } else {
                messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
            }
            final String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
            if (soapAction != null) {
                messageContext.setUseSOAPAction(true);
                messageContext.setSOAPActionURI(soapAction);
            }
            final SOAPEnvelope env = requestMessage.getSOAPEnvelope();
            if (env != null && env.getSOAPConstants() != null) {
                messageContext.setSOAPConstants(env.getSOAPConstants());
            }
            final SOAPService service = messageContext.getService();
            Thread.currentThread().setContextClassLoader(classLoader);
            service.invoke(messageContext);
            responseMessage = messageContext.getResponseMessage();
        } catch (final AxisFault fault) {
            if (req.getMethod().equals(HttpRequest.Method.GET.name()) && req.getParameters().isEmpty()) {
                String serviceName = req.getURI().getRawPath();
                serviceName = serviceName.substring(serviceName.lastIndexOf("/") + 1);
                printServiceInfo(res, serviceName);
                return;
            } else {
                responseMessage = handleFault(fault, res, messageContext);
            }
        } catch (final Exception e) {
            responseMessage = handleException(messageContext, res, e);
        }
        //TODO investigate and fix operation == null!
        if (messageContext.getOperation() != null) {
            if (messageContext.getOperation().getMep() == OperationType.ONE_WAY) {
                // No content, so just indicate accepted
                res.setStatus(HttpServletResponse.SC_ACCEPTED);
                return;
            } else if (responseMessage == null) {
                responseMessage = handleException(messageContext, null, new ServerRuntimeException("No response for non-one-way operation"));
            }
        } else if (responseMessage == null) {
            res.setStatus(HttpServletResponse.SC_ACCEPTED);
            return;
        }
        try {
            final SOAPConstants soapConstants = messageContext.getSOAPConstants();
            final String contentType1 = responseMessage.getContentType(soapConstants);
            res.setContentType(contentType1);
            // Transfer MIME headers to HTTP headers for response message.
            final MimeHeaders responseMimeHeaders = responseMessage.getMimeHeaders();
            for (final Iterator i = responseMimeHeaders.getAllHeaders(); i.hasNext(); ) {
                final MimeHeader responseMimeHeader = (MimeHeader) i.next();
                res.setHeader(responseMimeHeader.getName(), responseMimeHeader.getValue());
            }
            //TODO discuss this with dims.
            //                // synchronize the character encoding of request and response
            //                String responseEncoding = (String) messageContext.getProperty(
            //                        SOAPMessage.CHARACTER_SET_ENCODING);
            //                if (responseEncoding != null) {
            //                    try {
            //                        responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
            //                                               responseEncoding);
            //                    } catch (SOAPException e) {
            //                        log.info(Messages.getMessage("exception00"), e);
            //                    }
            //                }
            //determine content type from message response
            contentType = responseMessage.getContentType(messageContext.getSOAPConstants());
            responseMessage.writeTo(res.getOutputStream());
        } catch (final Exception e) {
            logger.warning(Messages.getMessage("exception00"), e);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) AxisFault(org.apache.axis.AxisFault) Message(org.apache.axis.Message) SOAPMessage(javax.xml.soap.SOAPMessage) InputStream(java.io.InputStream) SOAPEnvelope(org.apache.axis.message.SOAPEnvelope) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) IOException(java.io.IOException) MimeHeaders(javax.xml.soap.MimeHeaders) MimeHeader(javax.xml.soap.MimeHeader) Iterator(java.util.Iterator) MessageContext(org.apache.axis.MessageContext) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) SOAPConstants(org.apache.axis.soap.SOAPConstants) MessageContext(org.apache.axis.MessageContext)

Aggregations

Iterator (java.util.Iterator)4 MimeHeader (javax.xml.soap.MimeHeader)4 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CharacterIterator (java.text.CharacterIterator)1 StringCharacterIterator (java.text.StringCharacterIterator)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 AxisFault (org.apache.axis.AxisFault)1 Message (org.apache.axis.Message)1 MessageContext (org.apache.axis.MessageContext)1 SOAPService (org.apache.axis.handlers.soap.SOAPService)1 SOAPEnvelope (org.apache.axis.message.SOAPEnvelope)1 SOAPConstants (org.apache.axis.soap.SOAPConstants)1 ServerRuntimeException (org.apache.openejb.server.ServerRuntimeException)1