use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class JsonStreamBuilder method processDocument.
public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext) throws AxisFault {
if (inputStream != null) {
OMElement element = JsonUtil.getNewJsonPayload(messageContext, inputStream, false, false);
if (element != null) {
if (logger.isDebugEnabled()) {
logger.debug("#processDocument. Built JSON payload from JSON stream. MessageID: " + messageContext.getMessageID());
}
return element;
}
} else {
EndpointReference endpointReference = messageContext.getTo();
if (endpointReference == null) {
logger.error("#processDocument. Cannot build payload without a valid EPR. MessageID: " + messageContext.getMessageID());
throw new AxisFault("Cannot build payload without a valid EPR.");
}
String requestURL;
try {
requestURL = URIEncoderDecoder.decode(endpointReference.getAddress());
} catch (UnsupportedEncodingException e) {
logger.error("#processDocument. Could not decode request URL. MessageID: " + messageContext.getMessageID());
throw new AxisFault("Could not decode request URL.", e);
}
String jsonString;
int index;
// half as the incoming JSON message
if ((index = requestURL.indexOf('=')) > 0) {
jsonString = requestURL.substring(index + 1);
messageContext.setProperty(Constants.JSON_STRING, jsonString);
ByteArrayInputStream is = new ByteArrayInputStream(jsonString.getBytes());
return processDocument(is, s, messageContext);
} else {
messageContext.setProperty(Constants.JSON_STRING, null);
}
}
if (logger.isDebugEnabled()) {
logger.debug("#processDocument. No JSON payload found in request. MessageID: " + messageContext.getMessageID());
}
SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
return factory.getDefaultEnvelope();
}
use of org.apache.axiom.soap.SOAPFactory 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.axiom.soap.SOAPFactory 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;
}
use of org.apache.axiom.soap.SOAPFactory 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.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class MessageHelper method cloneSOAPEnvelope.
/**
* This method will clone the provided SOAPEnvelope and returns the cloned envelope
* as an exact copy of the provided envelope
*
* @param envelope - this will be cloned to get the new envelope
* @return cloned SOAPEnvelope from the provided one
*/
public static SOAPEnvelope cloneSOAPEnvelope(SOAPEnvelope envelope) {
SOAPFactory fac;
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelope.getBody().getNamespace().getNamespaceURI())) {
fac = OMAbstractFactory.getSOAP11Factory();
} else {
fac = OMAbstractFactory.getSOAP12Factory();
}
SOAPEnvelope newEnvelope = fac.getDefaultEnvelope();
Iterator childIterator;
if (envelope.getHeader() != null) {
SOAPHeader body = envelope.getHeader();
childIterator = body.getChildren();
while (childIterator.hasNext()) {
Object bodyNs = childIterator.next();
if (bodyNs instanceof SOAPHeaderBlock) {
try {
newEnvelope.getHeader().addChild(ElementHelper.toSOAPHeaderBlock(((OMElement) bodyNs).cloneOMElement(), fac));
} catch (Exception e) {
handleException(e);
}
} else if (bodyNs instanceof OMElement) {
newEnvelope.getHeader().addChild(((OMElement) bodyNs).cloneOMElement());
}
}
}
if (envelope.getBody() != null) {
// fault would lead to class cast exceptions if accessed through the getFault method
if (envelope.getBody().getFirstElement() instanceof SOAPFault && envelope.getBody().hasFault()) {
SOAPFault fault = envelope.getBody().getFault();
newEnvelope.getBody().addFault(cloneSOAPFault(fault));
} else {
OMElement body = envelope.getBody().cloneOMElement();
Iterator ns = body.getAllDeclaredNamespaces();
OMNamespace bodyNs = body.getNamespace();
String nsUri = bodyNs.getNamespaceURI();
String nsPrefix = bodyNs.getPrefix();
while (ns.hasNext()) {
OMNamespace namespace = ((OMNamespace) ns.next());
if (nsUri != null && !nsUri.equals(namespace.getNamespaceURI()) && nsPrefix != null && !nsPrefix.equals(namespace.getPrefix())) {
newEnvelope.getBody().declareNamespace(namespace);
}
ns.remove();
}
Iterator attributes = body.getAllAttributes();
while (attributes.hasNext()) {
OMAttribute attrb = (OMAttribute) attributes.next();
newEnvelope.getBody().addAttribute(attrb);
attributes.remove();
}
Iterator itr = body.getChildren();
while (itr.hasNext()) {
OMNode node = (OMNode) itr.next();
itr.remove();
newEnvelope.getBody().addChild(node);
}
}
}
return newEnvelope;
}
Aggregations