Search in sources :

Example 61 with MessageContext

use of org.apache.axis2.context.MessageContext in project coprhd-controller by CoprHD.

the class SSLUtil method setCookie.

/**
 * set the given HTTP cookie
 *
 * @param cookieName
 * @param cookieValue
 */
public void setCookie(String cookieName, String cookieValue) throws InvalidSession {
    MessageContext currentMessageContext = MessageContext.getCurrentMessageContext();
    if (currentMessageContext == null) {
        throw FaultUtil.InvalidSession("No current message context");
    }
    HttpServletResponse resp = (HttpServletResponse) currentMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE);
    if (resp == null) {
        throw FaultUtil.InvalidSession("No HTTP Servlet Response");
    }
    Cookie cookie = new Cookie(cookieName, cookieValue);
    resp.addCookie(cookie);
}
Also used : Cookie(javax.servlet.http.Cookie) HttpServletResponse(javax.servlet.http.HttpServletResponse) MessageContext(org.apache.axis2.context.MessageContext)

Example 62 with MessageContext

use of org.apache.axis2.context.MessageContext in project coprhd-controller by CoprHD.

the class SSLUtil method checkHttpRequest.

/**
 * checkHttpRequest
 *
 * The term "Session" is overloaded. A Session can refer to either a SSL
 * session or it can refer to a VASA session.
 *
 * If there is an error in either of the Session configurations, then this
 * routine will throw the InvalidSession expection.
 *
 * @param validClientCertificateNeeded
 * @param validSessionIdNeeed
 */
public String checkHttpRequest(boolean validSSLSessionNeeded, boolean validVASASessionNeeded) throws InvalidSession {
    final String methodName = "checkHttpRequest(): ";
    try {
        /*
             * Check for a valid context.
             */
        log.trace(methodName + "Entry with inputs validSSLSessionNeeded[" + validSSLSessionNeeded + "] validVASASessionNeeded[" + validVASASessionNeeded + "]");
        MessageContext currentMessageContext = MessageContext.getCurrentMessageContext();
        if (currentMessageContext == null) {
            throw FaultUtil.InvalidSession("No current message context");
        }
        String clientAddress = (String) currentMessageContext.getProperty("REMOTE_ADDR");
        // log.debug("Request from client at ip addr: " + clientAddress);
        HttpServletRequest req = (HttpServletRequest) currentMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
        if (req == null) {
            throw FaultUtil.InvalidSession("No HTTP Servlet Request");
        }
        /**
         * Get SSL data
         */
        String sslSessionId = (String) req.getAttribute("javax.servlet.request.ssl_session");
        if (sslSessionId == null) {
            /**
             * This is not an SSL connection. If the service is not allowing
             * none-SSL connections, throw an exception. Otherwise check for
             * a valid VASA session if necessary.
             */
            if (!mustUseSSL) {
                if (validVASASessionNeeded) {
                    checkHttpForValidVASASession();
                }
                log.trace(methodName + "Exit returning clientAddress[" + clientAddress + "]");
                return clientAddress;
            } else {
                throw FaultUtil.InvalidSession("Must use SSL connection");
            }
        }
        /*
             * At this point, it is known that there is a well formed HTTPS
             * session.
             */
        if (validSSLSessionNeeded) {
            checkHttpForValidSSLSession(req);
        }
        if (validVASASessionNeeded) {
            checkHttpForValidVASASession();
        }
        log.trace(methodName + "Exit returning clientAddress[" + clientAddress + "]");
        return clientAddress;
    } catch (InvalidCertificate ic) {
        // InvalidCertificate can be thrown by certificateIsTrusted
        log.error(methodName + "invalid certificate exception ", ic);
        throw FaultUtil.InvalidSession("Non trusted certificate.");
    } catch (InvalidSession is) {
        log.error(methodName + "invalid session exception ", is);
        throw is;
    } catch (Exception e) {
        log.error(methodName + "Exception occured ", e);
        throw FaultUtil.InvalidSession("checkHttpSession unexpected exception. Convert to InvalidSession.", e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InvalidCertificate(com.vmware.vim.vasa._1_0.InvalidCertificate) MessageContext(org.apache.axis2.context.MessageContext) InvalidSession(com.vmware.vim.vasa._1_0.InvalidSession) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 63 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class XFormURLEncodedBuilder method processDocument.

public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext) throws AxisFault {
    // first process the input stream
    SOAPEnvelope soapEnv = (SOAPEnvelope) processDocumentWrapper(inputStream, s, messageContext);
    // when this is a POST request, if the body of the soap envelope is empty and the parameter
    // map is there, build a dummy soap body which contains all the parameters coming in.
    SOAPBody body = soapEnv.getBody();
    String httpMethod = (String) messageContext.getProperty(HTTPConstants.HTTP_METHOD);
    if (body.getFirstElement() == null && HTTPConstants.HTTP_METHOD_POST.equals(httpMethod) && messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP) != null) {
        MultipleEntryHashMap map = (MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP);
        SOAPFactory soapFactory = getSOAPFactory(messageContext);
        OMElement bodyFirstChild = soapFactory.createOMElement(XFORM_FIRST_ELEMENT, body);
        createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, map);
    } else if (body.getFirstElement() != null && "mediate".equals(body.getFirstElement().getLocalName())) {
        body.getFirstElement().setLocalName(XFORM_FIRST_ELEMENT.getLocalPart());
    }
    return soapEnv;
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 64 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class XFormURLEncodedBuilder method processDocumentWrapper.

/**
 * @return Returns the document element.
 */
private OMElement processDocumentWrapper(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
    MultipleEntryHashMap parameterMap = new MultipleEntryHashMap();
    SOAPFactory soapFactory;
    AxisBindingOperation axisBindingOperation = (AxisBindingOperation) messageContext.getProperty(Constants.AXIS_BINDING_OPERATION);
    String queryParameterSeparator = null;
    String templatedPath = null;
    if (axisBindingOperation != null) {
        queryParameterSeparator = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
        templatedPath = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION);
    }
    if (queryParameterSeparator == null) {
        queryParameterSeparator = WSDL20DefaultValueHolder.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR_DEFAULT;
    }
    AxisEndpoint axisEndpoint = (AxisEndpoint) messageContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
    if (axisEndpoint != null) {
        AxisBinding axisBinding = axisEndpoint.getBinding();
        String soapVersion = (String) axisBinding.getProperty(WSDL2Constants.ATTR_WSOAP_VERSION);
        soapFactory = getSOAPFactory(soapVersion);
    } else {
        soapFactory = getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    }
    EndpointReference endpointReference = messageContext.getTo();
    if (endpointReference == null) {
        throw new AxisFault("Cannot create DocumentElement without destination EPR");
    }
    String requestURL = endpointReference.getAddress();
    try {
        requestURL = extractParametersUsingHttpLocation(templatedPath, parameterMap, requestURL, queryParameterSeparator);
    } catch (UnsupportedEncodingException e) {
        throw AxisFault.makeFault(e);
    }
    String query = requestURL;
    int index;
    if ((index = requestURL.indexOf("?")) > -1) {
        query = requestURL.substring(index + 1);
    }
    extractParametersFromRequest(parameterMap, query, queryParameterSeparator, (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING), inputStream);
    messageContext.setProperty(Constants.REQUEST_PARAMETER_MAP, parameterMap);
    return BuilderUtil.buildsoapMessage(messageContext, parameterMap, soapFactory);
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisBinding(org.apache.axis2.description.AxisBinding) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 65 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class XFormURLEncodedBuilder method getSOAPFactory.

private SOAPFactory getSOAPFactory(MessageContext messageContext) throws AxisFault {
    SOAPFactory soapFactory;
    AxisEndpoint axisEndpoint = (AxisEndpoint) messageContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
    if (axisEndpoint != null) {
        AxisBinding axisBinding = axisEndpoint.getBinding();
        String soapVersion = (String) axisBinding.getProperty(WSDL2Constants.ATTR_WSOAP_VERSION);
        soapFactory = getSOAPFactory(soapVersion);
    } else {
        soapFactory = getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    }
    return soapFactory;
}
Also used : AxisBinding(org.apache.axis2.description.AxisBinding) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)218 AxisFault (org.apache.axis2.AxisFault)126 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)84 EndpointReference (org.apache.axis2.addressing.EndpointReference)79 OMElement (org.apache.axiom.om.OMElement)75 MessageContext (org.apache.synapse.MessageContext)71 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)62 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)56 IOException (java.io.IOException)55 Map (java.util.Map)52 Test (org.junit.Test)45 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)44 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)36 MessageFormatter (org.apache.axis2.transport.MessageFormatter)35 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)34 Options (org.apache.axis2.client.Options)30 HashMap (java.util.HashMap)29 AxisService (org.apache.axis2.description.AxisService)29 QName (javax.xml.namespace.QName)28 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)28