Search in sources :

Example 1 with AxisBindingOperation

use of org.apache.axis2.description.AxisBindingOperation 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 2 with AxisBindingOperation

use of org.apache.axis2.description.AxisBindingOperation in project wso2-synapse by wso2.

the class RESTUtil method dispatchAndVerify.

public static void dispatchAndVerify(MessageContext msgContext) throws AxisFault {
    String extendedURIBasedDispatcher = System.getProperty("ei.extendedURIBasedDispatcher");
    if (extendedURIBasedDispatcher == null) {
        requestDispatcher.invoke(msgContext);
    } else {
        try {
            invokeMethod.invoke(dispatcherInstance, msgContext);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new AxisFault(e.getMessage());
        }
    }
    AxisService axisService = msgContext.getAxisService();
    if (axisService != null) {
        httpLocationBasedDispatcher.invoke(msgContext);
        if (msgContext.getAxisOperation() == null) {
            requestURIOperationDispatcher.invoke(msgContext);
        }
        AxisOperation axisOperation;
        if ((axisOperation = msgContext.getAxisOperation()) != null) {
            AxisEndpoint axisEndpoint = (AxisEndpoint) msgContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
            if (axisEndpoint != null) {
                AxisBindingOperation axisBindingOperation = (AxisBindingOperation) axisEndpoint.getBinding().getChild(axisOperation.getName());
                msgContext.setProperty(Constants.AXIS_BINDING_OPERATION, axisBindingOperation);
            }
            msgContext.setAxisOperation(axisOperation);
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with AxisBindingOperation

use of org.apache.axis2.description.AxisBindingOperation in project wso2-synapse by wso2.

the class XFormURLEncodedBuilderTest method testExtractMultipleParametersUsingHttpLocation2.

/**
 * Test extracting parameter from 'whttp:location'
 * @throws AxisFault
 */
public void testExtractMultipleParametersUsingHttpLocation2() throws AxisFault {
    AxisBindingOperation axisBindingOperation = new AxisBindingOperation();
    axisBindingOperation.setProperty("whttp:location", "books/{name}/");
    MessageContext messageContext = Util.newMessageContext();
    messageContext.setProperty("AxisBindingOperation", axisBindingOperation);
    messageContext.setTo(new EndpointReference("http://localhost:9000/store"));
    XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
    urlEncodedBuilder.processDocument(null, "", messageContext);
    assertNotNull("Parameter 'name' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("name"));
}
Also used : AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 4 with AxisBindingOperation

use of org.apache.axis2.description.AxisBindingOperation in project wso2-synapse by wso2.

the class XFormURLEncodedBuilderTest method testExtractMultipleParametersUsingHttpLocation.

/**
 * Test extracting multiple parameters from 'whttp:location'
 * @throws AxisFault
 */
public void testExtractMultipleParametersUsingHttpLocation() throws AxisFault {
    AxisBindingOperation axisBindingOperation = new AxisBindingOperation();
    axisBindingOperation.setProperty("whttp:location", "books/{category}/{name}");
    MessageContext messageContext = Util.newMessageContext();
    messageContext.setProperty("AxisBindingOperation", axisBindingOperation);
    messageContext.setTo(new EndpointReference("http://localhost:9000/store"));
    XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
    urlEncodedBuilder.processDocument(null, "", messageContext);
    assertNotNull("Parameter 'category' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("category"));
    assertNotNull("Parameter 'name' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("name"));
}
Also used : AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 5 with AxisBindingOperation

use of org.apache.axis2.description.AxisBindingOperation in project wso2-synapse by wso2.

the class SynapseXPathVariableContext method getVariableValue.

/**
 * Gets the variable values resolved from the context. This includes the
 * <dl>
 *   <dt><tt>body</tt></dt>
 *   <dd>The SOAP 1.1 or 1.2 body element.</dd>
 *   <dt><tt>header</tt></dt>
 *   <dd>The SOAP 1.1 or 1.2 header element.</dd>
 * </dl>
 * and the following variable prefixes
 * <dl>
 *   <dt><tt>ctx</tt></dt>
 *   <dd>Prefix for Synapse MessageContext properties</dd>
 *   <dt><tt>axis2</tt></dt>
 *   <dd>Prefix for Axis2 MessageContext properties</dd>
 *   <dt><tt>trp</tt></dt>
 *   <dd>Prefix for the transport headers</dd>
 * </dl>
 * If the variable is unknown, this method attempts to resolve it using
 * the parent variable context.
 *
 * @param namespaceURI namespaces for the variable resolution
 * @param prefix string prefix for the variable resolution
 * @param localName string local name for the variable resolution
 * @return Resolved variable value
 * @throws UnresolvableException if the variable specified does not found
 */
public Object getVariableValue(String namespaceURI, String prefix, String localName) throws UnresolvableException {
    if (namespaceURI == null) {
        if (env != null) {
            if (SynapseXPathConstants.SOAP_BODY_VARIABLE.equals(localName)) {
                return env.getBody();
            } else if (SynapseXPathConstants.SOAP_HEADER_VARIABLE.equals(localName)) {
                return env.getHeader();
            } else if (SynapseXPathConstants.SOAP_ENVELOPE_VARIABLE.equals(localName)) {
                return env;
            }
        }
        if (prefix != null && !"".equals(prefix) && synCtx != null) {
            if (SynapseXPathConstants.MESSAGE_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
                return synCtx.getProperty(localName);
            } else if (SynapseXPathConstants.AXIS2_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
                return ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(localName);
            } else if (SynapseXPathConstants.FUNC_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
                Stack<TemplateContext> functionStack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
                TemplateContext topCtxt = functionStack.peek();
                if (topCtxt != null) {
                    Object result = topCtxt.getParameterValue(localName);
                    if (result != null && result instanceof SynapseXPath && env != null) {
                        SynapseXPath expression = (SynapseXPath) topCtxt.getParameterValue(localName);
                        try {
                            return expression.evaluate(env);
                        } catch (JaxenException e) {
                            return null;
                        }
                    } else {
                        return result;
                    }
                }
            } else if (SynapseXPathConstants.TRANSPORT_VARIABLE_PREFIX.equals(prefix)) {
                org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
                if (headers != null && headers instanceof Map) {
                    Map headersMap = (Map) headers;
                    return headersMap.get(localName);
                } else {
                    return null;
                }
            } else if (SynapseXPathConstants.URL_VARIABLE_PREFIX.equals(prefix)) {
                EndpointReference toEPR = synCtx.getTo();
                if (toEPR != null) {
                    String completeURL = toEPR.getAddress();
                    AxisBindingOperation axisBindingOperation = (AxisBindingOperation) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(Constants.AXIS_BINDING_OPERATION);
                    String queryParameterSeparator = null;
                    if (axisBindingOperation != null) {
                        queryParameterSeparator = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
                    }
                    if (queryParameterSeparator == null) {
                        queryParameterSeparator = WSDL20DefaultValueHolder.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR_DEFAULT;
                    }
                    int i = completeURL.indexOf("?");
                    if (i > -1) {
                        String queryString = completeURL.substring(i + 1);
                        if (queryString != null && !queryString.equals("")) {
                            String[] params = queryString.split(queryParameterSeparator);
                            if (params == null || params.length == 0) {
                                return "";
                            }
                            for (String param : params) {
                                String[] temp = param.split("=");
                                if (temp != null && temp.length >= 1) {
                                    if (temp[0].equalsIgnoreCase(localName)) {
                                        try {
                                            return temp.length > 1 ? URIEncoderDecoder.decode(temp[1]) : "";
                                        } catch (UnsupportedEncodingException e) {
                                            String msg = "Couldn't decode the URL parameter " + "value " + temp[1] + " with name " + localName;
                                            log.error(msg, e);
                                            throw new UnresolvableException(msg + e.getMessage());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return "";
            } else if (SynapseXPathConstants.OPERATION_SCOPE_VARIABLE_PREFIX.equals(prefix)) {
                Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
                return axis2smc.getAxis2MessageContext().getOperationContext().getProperty(localName);
            } else if (SynapseXPathConstants.SYSTEM_SCOPE_VARIABLE_PREFIX.equals(prefix)) {
                String propVal = System.getProperty(localName);
                if (propVal != null) {
                    return propVal;
                } else {
                    return "";
                }
            } else {
                Object o = synCtx.getProperty(prefix);
                if (o instanceof Map) {
                    Object valueObject = ((Map) o).get(localName);
                    if (valueObject != null) {
                        return valueObject.toString();
                    }
                }
            }
        }
    }
    // try resolving using available custom extensions
    Object obj = XpathExtensionUtil.resolveVariableContext(synCtx, namespaceURI, prefix, localName);
    if (obj != null) {
        return obj;
    }
    return parent.getVariableValue(namespaceURI, prefix, localName);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) TemplateContext(org.apache.synapse.mediators.template.TemplateContext) Stack(java.util.Stack) EndpointReference(org.apache.axis2.addressing.EndpointReference) JaxenException(org.jaxen.JaxenException) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) UnresolvableException(org.jaxen.UnresolvableException) Map(java.util.Map) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

AxisBindingOperation (org.apache.axis2.description.AxisBindingOperation)6 EndpointReference (org.apache.axis2.addressing.EndpointReference)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AxisFault (org.apache.axis2.AxisFault)2 MessageContext (org.apache.axis2.context.MessageContext)2 AxisEndpoint (org.apache.axis2.description.AxisEndpoint)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 Stack (java.util.Stack)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 AxisBinding (org.apache.axis2.description.AxisBinding)1 AxisBindingMessage (org.apache.axis2.description.AxisBindingMessage)1 AxisOperation (org.apache.axis2.description.AxisOperation)1 AxisService (org.apache.axis2.description.AxisService)1 MultipleEntryHashMap (org.apache.axis2.util.MultipleEntryHashMap)1 MessageContext (org.apache.synapse.MessageContext)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 TemplateContext (org.apache.synapse.mediators.template.TemplateContext)1