Search in sources :

Example 11 with MimeHeaders

use of javax.xml.soap.MimeHeaders in project cxf by apache.

the class SOAPHandlerInterceptorTest method prepareSOAPMessage.

private SOAPMessage prepareSOAPMessage(String resouceName) throws Exception {
    InputStream is = this.getClass().getResourceAsStream(resouceName);
    SOAPMessage soapMessage = null;
    MessageFactory factory = MessageFactory.newInstance();
    MimeHeaders mhs = null;
    soapMessage = factory.createMessage(mhs, is);
    return soapMessage;
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 12 with MimeHeaders

use of javax.xml.soap.MimeHeaders in project Payara by payara.

the class BaseAuthConfig method getOpName.

private static String getOpName(SOAPMessage message) {
    String rvalue = null;
    // first look for a SOAPAction header.
    // this is what .net uses to identify the operation
    MimeHeaders headers = message.getMimeHeaders();
    if (headers != null) {
        String[] actions = headers.getHeader("SOAPAction");
        if (actions != null && actions.length > 0) {
            rvalue = actions[0];
            if (rvalue != null && rvalue.equals("\"\"")) {
                rvalue = null;
            }
        }
    }
    if (rvalue == null) {
        Name name = getName(message);
        if (name != null) {
            rvalue = name.getLocalName();
        }
    }
    return rvalue;
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) Name(javax.xml.soap.Name) QName(javax.xml.namespace.QName)

Example 13 with MimeHeaders

use of javax.xml.soap.MimeHeaders 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)

Example 14 with MimeHeaders

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

the class FSSOAPReceiver method doPost.

/**
     * Handles post request.
     * @param request http request object
     * @param response http response object
     * @exception ServletException, IOException if error occurrs.
     */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
    FSUtils.debug.message("FSSOAPReceiver.doPost: Called");
    FSUtils.checkHTTPRequestLength(request);
    try {
        MimeHeaders mimeHeaders = SAMLUtils.getMimeHeaders(request);
        ServletInputStream sInputStream = request.getInputStream();
        SOAPMessage soapMessage = msgFactory.createMessage(mimeHeaders, sInputStream);
        this.onMessage(request, response, soapMessage);
        return;
    } catch (SOAPException se) {
        throw new ServletException(se);
    }
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 15 with MimeHeaders

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

the class SOAPCommunicator method getSOAPMessage.

/**
     * Returns SOAP Message from <code>HttpServletRequest</code>.
     *
     * @param request <code>HttpServletRequest</code> includes SOAP Message.
     * @return SOAPMessage if request include any soap message in the header.
     * @throws IOException   if error in creating input stream.
     * @throws SOAPException if error in creating soap message.
     */
public SOAPMessage getSOAPMessage(final HttpServletRequest request) throws IOException, SOAPException {
    // Get all the headers from the HTTP request
    MimeHeaders headers = getHeaders(request);
    // Get the body of the HTTP request
    InputStream is = request.getInputStream();
    // Create a SOAPMessage
    return messageFactory.createMessage(headers, is);
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

MimeHeaders (javax.xml.soap.MimeHeaders)24 SOAPMessage (javax.xml.soap.SOAPMessage)16 SOAPException (javax.xml.soap.SOAPException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 ServletException (javax.servlet.ServletException)5 MessageFactory (javax.xml.soap.MessageFactory)4 FSException (com.sun.identity.federation.common.FSException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Enumeration (java.util.Enumeration)3 StringTokenizer (java.util.StringTokenizer)3 ServletInputStream (javax.servlet.ServletInputStream)3 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)2 SessionException (com.sun.identity.plugin.session.SessionException)2 SAMLException (com.sun.identity.saml.common.SAMLException)2 SAMLRequestVersionTooHighException (com.sun.identity.saml.common.SAMLRequestVersionTooHighException)2 SAMLRequestVersionTooLowException (com.sun.identity.saml.common.SAMLRequestVersionTooLowException)2 SAMLRequesterException (com.sun.identity.saml.common.SAMLRequesterException)2 SOAPPartImpl (com.sun.xml.messaging.saaj.soap.SOAPPartImpl)2