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);
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations