Search in sources :

Example 1 with OAuthHandler

use of org.apache.synapse.endpoints.oauth.OAuthHandler in project wso2-synapse by wso2.

the class HTTPEndpointFactory method createEndpoint.

@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    OMAttribute nameAttr = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    String name = null;
    if (nameAttr != null) {
        name = nameAttr.getAttributeValue();
    }
    OMElement httpElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "http"));
    HTTPEndpoint httpEndpoint;
    OAuthHandler oAuthhandler = createOAuthHandler(httpElement, name);
    if (oAuthhandler != null) {
        httpEndpoint = new OAuthConfiguredHTTPEndpoint(oAuthhandler);
    } else {
        httpEndpoint = new HTTPEndpoint();
    }
    if (name != null) {
        httpEndpoint.setName(name);
    }
    if (httpElement != null) {
        EndpointDefinition definition = createEndpointDefinition(httpElement);
        OMAttribute uriTemplateAttr = httpElement.getAttribute(new QName("uri-template"));
        if (uriTemplateAttr != null) {
            String uriValue = uriTemplateAttr.getAttributeValue();
            uriValue = ResolverFactory.getInstance().getResolver(uriValue).resolve();
            // get object and and resolve
            if (uriValue.startsWith(HTTPEndpoint.legacyPrefix)) {
                httpEndpoint.setUriTemplate(UriTemplate.fromTemplate(uriValue.substring(HTTPEndpoint.legacyPrefix.length())));
                // Set the address to the initial template value.
                definition.setAddress(uriValue.substring(HTTPEndpoint.legacyPrefix.length()));
                httpEndpoint.setLegacySupport(true);
            } else {
                httpEndpoint.setUriTemplate(UriTemplate.fromTemplate(uriValue));
                // Set the address to the initial template value.
                definition.setAddress(uriValue);
                httpEndpoint.setLegacySupport(false);
            }
        }
        httpEndpoint.setDefinition(definition);
        processAuditStatus(definition, httpEndpoint.getName(), httpElement);
        OMAttribute methodAttr = httpElement.getAttribute(new QName("method"));
        if (methodAttr != null) {
            setHttpMethod(httpEndpoint, methodAttr.getAttributeValue());
        } else {
            // Method is not a mandatory parameter for HttpEndpoint. So methodAttr Can be null
            if (log.isDebugEnabled()) {
                log.debug("Method is not specified for HttpEndpoint. " + "Hence using the http method from incoming message");
            }
        }
    }
    processProperties(httpEndpoint, epConfig);
    CommentListUtil.populateComments(epConfig, httpEndpoint.getCommentsList());
    return httpEndpoint;
}
Also used : OAuthConfiguredHTTPEndpoint(org.apache.synapse.endpoints.OAuthConfiguredHTTPEndpoint) HTTPEndpoint(org.apache.synapse.endpoints.HTTPEndpoint) QName(javax.xml.namespace.QName) OAuthHandler(org.apache.synapse.endpoints.oauth.OAuthHandler) OAuthConfiguredHTTPEndpoint(org.apache.synapse.endpoints.OAuthConfiguredHTTPEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)1 HTTPEndpoint (org.apache.synapse.endpoints.HTTPEndpoint)1 OAuthConfiguredHTTPEndpoint (org.apache.synapse.endpoints.OAuthConfiguredHTTPEndpoint)1 OAuthHandler (org.apache.synapse.endpoints.oauth.OAuthHandler)1