Search in sources :

Example 1 with StatisticsConfigurable

use of org.apache.synapse.aspects.statistics.StatisticsConfigurable in project wso2-synapse by wso2.

the class AbstractMediatorSerializer method saveTracingState.

/**
 * Perform common functions and finalize the mediator serialization.
 * i.e. process any common attributes
 *
 * @param mediatorOmElement the OMElement being created
 * @param mediator the Mediator instance being serialized
 */
protected static void saveTracingState(OMElement mediatorOmElement, Mediator mediator) {
    int traceState = mediator.getTraceState();
    String traceValue = null;
    if (traceState == org.apache.synapse.SynapseConstants.TRACING_ON) {
        traceValue = XMLConfigConstants.TRACE_ENABLE;
    } else if (traceState == org.apache.synapse.SynapseConstants.TRACING_OFF) {
        traceValue = XMLConfigConstants.TRACE_DISABLE;
    }
    if (traceValue != null) {
        mediatorOmElement.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, nullNS, traceValue));
    }
    if (mediator instanceof AspectConfigurable) {
        StatisticsConfigurable statisticsConfigurable = ((AspectConfigurable) mediator).getAspectConfiguration();
        if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) {
            mediatorOmElement.addAttribute(fac.createOMAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, nullNS, XMLConfigConstants.STATISTICS_ENABLE));
        }
        if (statisticsConfigurable != null && statisticsConfigurable.isTracingEnabled()) {
            mediatorOmElement.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, nullNS, XMLConfigConstants.TRACE_ENABLE));
        }
    }
}
Also used : AspectConfigurable(org.apache.synapse.aspects.AspectConfigurable) StatisticsConfigurable(org.apache.synapse.aspects.statistics.StatisticsConfigurable)

Example 2 with StatisticsConfigurable

use of org.apache.synapse.aspects.statistics.StatisticsConfigurable in project wso2-synapse by wso2.

the class ProxyServiceSerializer method serializeProxy.

public static OMElement serializeProxy(OMElement parent, ProxyService service) {
    OMElement proxy = fac.createOMElement("proxy", synNS);
    if (service.getName() != null) {
        proxy.addAttribute(fac.createOMAttribute("name", nullNS, service.getName()));
    } else {
        handleException("Invalid proxy service. Service name is required");
    }
    String descriptionStr = service.getDescription();
    if (descriptionStr != null) {
        OMElement description = fac.createOMElement("description", synNS);
        description.addChild(fac.createOMText(descriptionStr));
        proxy.addChild(description);
    }
    ArrayList transports = service.getTransports();
    if (transports != null && !transports.isEmpty()) {
        String transportStr = "" + transports.get(0);
        for (int i = 1; i < transports.size(); i++) {
            transportStr = transportStr.concat(" " + transports.get(i));
        }
        proxy.addAttribute(fac.createOMAttribute("transports", nullNS, transportStr));
    }
    if (service.getServiceGroup() != null) {
        proxy.addAttribute(fac.createOMAttribute("serviceGroup", nullNS, service.getServiceGroup()));
    }
    List pinnedServers = service.getPinnedServers();
    if (pinnedServers != null && !pinnedServers.isEmpty()) {
        String pinnedServersStr = "" + pinnedServers.get(0);
        for (int i = 1; i < pinnedServers.size(); i++) {
            pinnedServersStr = pinnedServersStr.concat(" " + pinnedServers.get(i));
        }
        proxy.addAttribute(fac.createOMAttribute("pinnedServers", nullNS, pinnedServersStr));
    }
    if (service.isStartOnLoad()) {
        proxy.addAttribute(fac.createOMAttribute("startOnLoad", nullNS, "true"));
    } else {
        proxy.addAttribute(fac.createOMAttribute("startOnLoad", nullNS, "false"));
    }
    String endpoint = service.getTargetEndpoint();
    OMElement target = fac.createOMElement("target", synNS);
    Endpoint inLineEndpoint = service.getTargetInLineEndpoint();
    if (endpoint != null) {
        target.addAttribute(fac.createOMAttribute("endpoint", nullNS, endpoint));
        proxy.addChild(target);
    } else if (inLineEndpoint != null) {
        OMElement epElement = EndpointSerializer.getElementFromEndpoint(inLineEndpoint);
        target.addChild(epElement);
        proxy.addChild(target);
    }
    String inSeq = service.getTargetInSequence();
    String outSeq = service.getTargetOutSequence();
    String faultSeq = service.getTargetFaultSequence();
    SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
    if (inSeq != null) {
        target.addAttribute(fac.createOMAttribute("inSequence", nullNS, inSeq));
        proxy.addChild(target);
    } else {
        SequenceMediator inLineInSeq = service.getTargetInLineInSequence();
        if (inLineInSeq != null) {
            OMElement inSeqElement = serializer.serializeAnonymousSequence(null, inLineInSeq);
            inSeqElement.setLocalName("inSequence");
            target.addChild(inSeqElement);
            proxy.addChild(target);
        }
    }
    if (outSeq != null) {
        target.addAttribute(fac.createOMAttribute("outSequence", nullNS, outSeq));
        proxy.addChild(target);
    } else {
        SequenceMediator inLineOutSeq = service.getTargetInLineOutSequence();
        if (inLineOutSeq != null) {
            OMElement outSeqElement = serializer.serializeAnonymousSequence(null, inLineOutSeq);
            outSeqElement.setLocalName("outSequence");
            target.addChild(outSeqElement);
            proxy.addChild(target);
        }
    }
    if (faultSeq != null) {
        target.addAttribute(fac.createOMAttribute("faultSequence", nullNS, faultSeq));
        proxy.addChild(target);
    } else {
        SequenceMediator inLineFaultSeq = service.getTargetInLineFaultSequence();
        if (inLineFaultSeq != null) {
            OMElement faultSeqElement = serializer.serializeAnonymousSequence(null, inLineFaultSeq);
            faultSeqElement.setLocalName("faultSequence");
            target.addChild(faultSeqElement);
            proxy.addChild(target);
        }
    }
    String wsdlKey = service.getWSDLKey();
    String wsdlEndpoint = service.getPublishWSDLEndpoint();
    String preservePolicy = service.getPreservePolicy();
    URI wsdlUri = service.getWsdlURI();
    Object inLineWSDL = service.getInLineWSDL();
    if (wsdlKey != null || wsdlUri != null || inLineWSDL != null || wsdlEndpoint != null) {
        OMElement wsdl = fac.createOMElement("publishWSDL", synNS);
        if (wsdlEndpoint != null) {
            wsdl.addAttribute(fac.createOMAttribute("endpoint", nullNS, wsdlEndpoint));
        } else if (wsdlKey != null) {
            wsdl.addAttribute(fac.createOMAttribute("key", nullNS, wsdlKey));
        } else if (inLineWSDL != null) {
            wsdl.addChild((OMNode) inLineWSDL);
        } else if (wsdlUri != null) {
            wsdl.addAttribute(fac.createOMAttribute("uri", nullNS, wsdlUri.toString()));
        }
        if (preservePolicy != null) {
            wsdl.addAttribute(fac.createOMAttribute("preservePolicy", nullNS, preservePolicy));
        }
        ResourceMapSerializer.serializeResourceMap(wsdl, service.getResourceMap());
        proxy.addChild(wsdl);
    }
    for (PolicyInfo pi : service.getPolicies()) {
        OMElement policy = fac.createOMElement("policy", synNS);
        if (pi.getPolicyKey() != null) {
            policy.addAttribute(fac.createOMAttribute("key", nullNS, pi.getPolicyKey()));
        } else {
            handleException("Policy without a key has been found");
        }
        if (pi.getOperation() != null) {
            policy.addAttribute(fac.createOMAttribute("operationName", nullNS, pi.getOperation().getLocalPart()));
            if (pi.getOperation().getNamespaceURI() != null) {
                policy.addAttribute(fac.createOMAttribute("operationNamespace", nullNS, pi.getOperation().getNamespaceURI()));
            }
        }
        if (pi.getType() != 0) {
            policy.addAttribute(fac.createOMAttribute("type", nullNS, pi.getMessageLable().toLowerCase()));
        }
        proxy.addChild(policy);
    }
    for (String propertyName : service.getParameterMap().keySet()) {
        OMElement property = fac.createOMElement("parameter", synNS);
        property.addAttribute(fac.createOMAttribute("name", nullNS, propertyName));
        Object value = service.getParameterMap().get(propertyName);
        if (value != null) {
            if (value instanceof String) {
                property.setText(((String) value).trim());
                proxy.addChild(property);
            } else if (value instanceof OMNode) {
                property.addChild((OMNode) value);
                proxy.addChild(property);
            }
        }
    }
    if (service.isWsAddrEnabled()) {
        proxy.addChild(fac.createOMElement("enableAddressing", synNS));
    }
    if (service.isWsSecEnabled()) {
        proxy.addChild(fac.createOMElement("enableSec", synNS));
    }
    StatisticsConfigurable statisticsConfigurable = service.getAspectConfiguration();
    if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) {
        proxy.addAttribute(fac.createOMAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, nullNS, XMLConfigConstants.STATISTICS_ENABLE));
    }
    if (statisticsConfigurable != null && statisticsConfigurable.isTracingEnabled()) {
        proxy.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, nullNS, XMLConfigConstants.TRACE_ENABLE));
    }
    if (parent != null) {
        parent.addChild(proxy);
    }
    return proxy;
}
Also used : ArrayList(java.util.ArrayList) PolicyInfo(org.apache.synapse.util.PolicyInfo) URI(java.net.URI) Endpoint(org.apache.synapse.endpoints.Endpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) ArrayList(java.util.ArrayList) List(java.util.List) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) StatisticsConfigurable(org.apache.synapse.aspects.statistics.StatisticsConfigurable)

Example 3 with StatisticsConfigurable

use of org.apache.synapse.aspects.statistics.StatisticsConfigurable in project wso2-synapse by wso2.

the class InboundEndpointSerializer method serializeInboundEndpoint.

public static OMElement serializeInboundEndpoint(InboundEndpoint inboundEndpoint) {
    OMElement inboundEndpointElt = fac.createOMElement(InboundEndpointConstants.INBOUND_ENDPOINT, SynapseConstants.SYNAPSE_OMNAMESPACE);
    inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_NAME, inboundEndpoint.getName(), null);
    if (inboundEndpoint.getInjectingSeq() != null) {
        inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_SEQUENCE, inboundEndpoint.getInjectingSeq(), null);
    }
    if (inboundEndpoint.getOnErrorSeq() != null) {
        inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_ERROR_SEQUENCE, inboundEndpoint.getOnErrorSeq(), null);
    }
    if (inboundEndpoint.getProtocol() != null) {
        inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_PROTOCOL, inboundEndpoint.getProtocol(), null);
    } else {
        inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_CLASS, inboundEndpoint.getClassImpl(), null);
    }
    StatisticsConfigurable statisticsConfigurable = inboundEndpoint.getAspectConfiguration();
    if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) {
        inboundEndpointElt.addAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, XMLConfigConstants.STATISTICS_ENABLE, null);
    }
    if (statisticsConfigurable != null && statisticsConfigurable.isTracingEnabled()) {
        inboundEndpointElt.addAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, XMLConfigConstants.TRACE_ENABLE, null);
    }
    inboundEndpointElt.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_SUSPEND, Boolean.toString(inboundEndpoint.isSuspend()), null);
    OMElement parametersElt = fac.createOMElement(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETERS, SynapseConstants.SYNAPSE_OMNAMESPACE);
    for (Map.Entry<String, String> paramEntry : inboundEndpoint.getParametersMap().entrySet()) {
        String strKey = paramEntry.getKey();
        OMElement parameter = fac.createOMElement(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER, SynapseConstants.SYNAPSE_OMNAMESPACE);
        parameter.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_NAME, strKey, null);
        if (inboundEndpoint.getParameterKey(strKey) != null) {
            parameter.addAttribute(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_KEY, inboundEndpoint.getParameterKey(strKey), null);
        } else if (isWellFormedXML(paramEntry.getValue())) {
            try {
                OMElement omElement = AXIOMUtil.stringToOM(paramEntry.getValue());
                parameter.addChild(omElement);
            } catch (XMLStreamException e) {
                String msg = "Error Parsing OMElement for value of " + paramEntry.getKey();
                throw new SynapseException(msg, e);
            }
        } else {
            parameter.setText(paramEntry.getValue());
        }
        parametersElt.addChild(parameter);
    }
    inboundEndpointElt.addChild(parametersElt);
    return inboundEndpointElt;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) OMElement(org.apache.axiom.om.OMElement) StatisticsConfigurable(org.apache.synapse.aspects.statistics.StatisticsConfigurable) Map(java.util.Map)

Example 4 with StatisticsConfigurable

use of org.apache.synapse.aspects.statistics.StatisticsConfigurable in project wso2-synapse by wso2.

the class EndpointDefinitionSerializer method serializeEndpointDefinition.

public void serializeEndpointDefinition(EndpointDefinition endpointDefinition, OMElement element) {
    StatisticsConfigurable statisticsConfigurable = endpointDefinition.getAspectConfiguration();
    if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) {
        element.addAttribute(fac.createOMAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, null, XMLConfigConstants.STATISTICS_ENABLE));
    }
    if (statisticsConfigurable != null && statisticsConfigurable.isTracingEnabled()) {
        element.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, null, XMLConfigConstants.TRACE_ENABLE));
    }
    if (endpointDefinition.isUseSwa()) {
        element.addAttribute(fac.createOMAttribute("optimize", null, "swa"));
    } else if (endpointDefinition.isUseMTOM()) {
        element.addAttribute(fac.createOMAttribute("optimize", null, "mtom"));
    }
    if (endpointDefinition.getCharSetEncoding() != null) {
        element.addAttribute(fac.createOMAttribute("encoding", null, endpointDefinition.getCharSetEncoding()));
    }
    if (endpointDefinition.isAddressingOn()) {
        OMElement addressing = fac.createOMElement("enableAddressing", SynapseConstants.SYNAPSE_OMNAMESPACE);
        if (endpointDefinition.getAddressingVersion() != null) {
            addressing.addAttribute(fac.createOMAttribute("version", null, endpointDefinition.getAddressingVersion()));
        }
        if (endpointDefinition.isUseSeparateListener()) {
            addressing.addAttribute(fac.createOMAttribute("separateListener", null, "true"));
        }
        element.addChild(addressing);
    }
    if (endpointDefinition.isSecurityOn()) {
        OMElement sec = fac.createOMElement("enableSec", SynapseConstants.SYNAPSE_OMNAMESPACE);
        if (endpointDefinition.getWsSecPolicyKey() != null) {
            if (!endpointDefinition.isDynamicPolicy()) {
                sec.addAttribute(fac.createOMAttribute("policy", null, endpointDefinition.getWsSecPolicyKey()));
            } else {
                sec.addAttribute(fac.createOMAttribute("policy", null, '{' + endpointDefinition.getDynamicPolicy().getExpression() + '}'));
            }
        } else {
            if (endpointDefinition.getInboundWsSecPolicyKey() != null) {
                sec.addAttribute(fac.createOMAttribute("inboundPolicy", null, endpointDefinition.getInboundWsSecPolicyKey()));
            }
            if (endpointDefinition.getOutboundWsSecPolicyKey() != null) {
                sec.addAttribute(fac.createOMAttribute("outboundPolicy", null, endpointDefinition.getOutboundWsSecPolicyKey()));
            }
        }
        element.addChild(sec);
    }
    if (endpointDefinition.getTimeoutAction() != SynapseConstants.NONE || endpointDefinition.getTimeoutDuration() > 0 || endpointDefinition.isDynamicTimeoutEndpoint()) {
        OMElement timeout = fac.createOMElement("timeout", SynapseConstants.SYNAPSE_OMNAMESPACE);
        element.addChild(timeout);
        if (endpointDefinition.getTimeoutDuration() > 0 || endpointDefinition.isDynamicTimeoutEndpoint()) {
            OMElement duration = fac.createOMElement("duration", SynapseConstants.SYNAPSE_OMNAMESPACE);
            if (!endpointDefinition.isDynamicTimeoutEndpoint()) {
                duration.setText(Long.toString(endpointDefinition.getTimeoutDuration()));
            } else {
                duration.setText('{' + endpointDefinition.getDynamicTimeoutExpression().getExpression() + '}');
            }
            timeout.addChild(duration);
        }
        if (endpointDefinition.getTimeoutAction() != SynapseConstants.NONE) {
            OMElement action = fac.createOMElement("responseAction", SynapseConstants.SYNAPSE_OMNAMESPACE);
            if (endpointDefinition.getTimeoutAction() == SynapseConstants.DISCARD) {
                action.setText("discard");
            } else if (endpointDefinition.getTimeoutAction() == SynapseConstants.DISCARD_AND_FAULT) {
                action.setText("fault");
            }
            timeout.addChild(action);
        }
    }
    if (endpointDefinition.getInitialSuspendDuration() != -1 || !endpointDefinition.getSuspendErrorCodes().isEmpty()) {
        OMElement suspendOnFailure = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_ON_FAILURE, SynapseConstants.SYNAPSE_OMNAMESPACE);
        if (!endpointDefinition.getSuspendErrorCodes().isEmpty()) {
            OMElement errorCodes = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES, SynapseConstants.SYNAPSE_OMNAMESPACE);
            errorCodes.setText(endpointDefinition.getSuspendErrorCodes().toString().replaceAll("[\\[\\] ]", ""));
            suspendOnFailure.addChild(errorCodes);
        }
        if (endpointDefinition.getInitialSuspendDuration() != -1) {
            OMElement initialDuration = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_INITIAL_DURATION, SynapseConstants.SYNAPSE_OMNAMESPACE);
            initialDuration.setText(Long.toString(endpointDefinition.getInitialSuspendDuration()));
            suspendOnFailure.addChild(initialDuration);
        }
        if (endpointDefinition.getSuspendProgressionFactor() != -1) {
            OMElement progressionFactor = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR, SynapseConstants.SYNAPSE_OMNAMESPACE);
            progressionFactor.setText(Float.toString(endpointDefinition.getSuspendProgressionFactor()));
            suspendOnFailure.addChild(progressionFactor);
        }
        if (endpointDefinition.getSuspendMaximumDuration() != -1 && endpointDefinition.getSuspendMaximumDuration() != Long.MAX_VALUE) {
            OMElement suspendMaximum = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_MAXIMUM_DURATION, SynapseConstants.SYNAPSE_OMNAMESPACE);
            suspendMaximum.setText(Long.toString(endpointDefinition.getSuspendMaximumDuration()));
            suspendOnFailure.addChild(suspendMaximum);
        }
        element.addChild(suspendOnFailure);
    }
    if (endpointDefinition.getRetryDurationOnTimeout() > 0 || !endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
        OMElement markAsTimedout = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.MARK_FOR_SUSPENSION, SynapseConstants.SYNAPSE_OMNAMESPACE);
        if (!endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
            OMElement errorCodes = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES, SynapseConstants.SYNAPSE_OMNAMESPACE);
            errorCodes.setText(endpointDefinition.getTimeoutErrorCodes().toString().replaceAll("[\\[\\] ]", ""));
            markAsTimedout.addChild(errorCodes);
        }
        if (endpointDefinition.getRetriesOnTimeoutBeforeSuspend() > 0) {
            OMElement retries = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.RETRIES_BEFORE_SUSPENSION, SynapseConstants.SYNAPSE_OMNAMESPACE);
            retries.setText(Long.toString(endpointDefinition.getRetriesOnTimeoutBeforeSuspend()));
            markAsTimedout.addChild(retries);
        }
        if (endpointDefinition.getRetryDurationOnTimeout() > 0) {
            OMElement retryDelay = fac.createOMElement(org.apache.synapse.config.xml.XMLConfigConstants.RETRY_DELAY, SynapseConstants.SYNAPSE_OMNAMESPACE);
            retryDelay.setText(Long.toString(endpointDefinition.getRetryDurationOnTimeout()));
            markAsTimedout.addChild(retryDelay);
        }
        element.addChild(markAsTimedout);
    }
    if (!endpointDefinition.getRetryDisabledErrorCodes().isEmpty()) {
        OMElement retryConfig = fac.createOMElement(XMLConfigConstants.RETRY_CONFIG, SynapseConstants.SYNAPSE_OMNAMESPACE);
        OMElement errorCodes = fac.createOMElement("disabledErrorCodes", SynapseConstants.SYNAPSE_OMNAMESPACE);
        errorCodes.setText(endpointDefinition.getRetryDisabledErrorCodes().toString().replaceAll("[\\[\\] ]", ""));
        retryConfig.addChild(errorCodes);
        element.addChild(retryConfig);
    } else if (!endpointDefinition.getRetryEnableErrorCodes().isEmpty()) {
        OMElement retryConfig = fac.createOMElement(XMLConfigConstants.RETRY_CONFIG, SynapseConstants.SYNAPSE_OMNAMESPACE);
        OMElement errorCodes = fac.createOMElement("enabledErrorCodes", SynapseConstants.SYNAPSE_OMNAMESPACE);
        errorCodes.setText(endpointDefinition.getRetryEnableErrorCodes().toString().replaceAll("[\\[\\] ]", ""));
        retryConfig.addChild(errorCodes);
        element.addChild(retryConfig);
    }
}
Also used : OMElement(org.apache.axiom.om.OMElement) StatisticsConfigurable(org.apache.synapse.aspects.statistics.StatisticsConfigurable)

Example 5 with StatisticsConfigurable

use of org.apache.synapse.aspects.statistics.StatisticsConfigurable in project wso2-synapse by wso2.

the class APISerializer method serializeAPI.

public static OMElement serializeAPI(API api) {
    OMElement apiElt = fac.createOMElement("api", SynapseConstants.SYNAPSE_OMNAMESPACE);
    apiElt.addAttribute("name", api.getAPIName(), null);
    apiElt.addAttribute("context", api.getContext(), null);
    VersionStrategySerializer.serializeVersioningStrategy(api.getVersionStrategy(), apiElt);
    if (api.getHost() != null) {
        apiElt.addAttribute("hostname", api.getHost(), null);
    }
    if (api.getPort() != -1) {
        apiElt.addAttribute("port", String.valueOf(api.getPort()), null);
    }
    StatisticsConfigurable statisticsConfigurable = api.getAspectConfiguration();
    if (statisticsConfigurable != null && statisticsConfigurable.isStatisticsEnable()) {
        apiElt.addAttribute(XMLConfigConstants.STATISTICS_ATTRIB_NAME, XMLConfigConstants.STATISTICS_ENABLE, null);
    }
    if (statisticsConfigurable != null && statisticsConfigurable.isTracingEnabled()) {
        apiElt.addAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME, XMLConfigConstants.TRACE_ENABLE, null);
    }
    Resource[] resources = api.getResources();
    for (Resource r : resources) {
        OMElement resourceElt = ResourceSerializer.serializeResource(r);
        apiElt.addChild(resourceElt);
    }
    Handler[] handlers = api.getHandlers();
    if (handlers.length > 0) {
        OMElement handlersElt = fac.createOMElement("handlers", SynapseConstants.SYNAPSE_OMNAMESPACE);
        for (Handler handler : handlers) {
            OMElement handlerElt = fac.createOMElement("handler", SynapseConstants.SYNAPSE_OMNAMESPACE);
            handlerElt.addAttribute("class", handler.getClass().getName(), null);
            handlersElt.addChild(handlerElt);
            if (handler.getProperties() != null) {
                Map propertyMap = handler.getProperties();
                if (propertyMap != null) {
                    Iterator itr = propertyMap.keySet().iterator();
                    while (itr.hasNext()) {
                        String propName = (String) itr.next();
                        Object o = handler.getProperties().get(propName);
                        OMElement prop = fac.createOMElement(APIFactory.PROP_Q, handlerElt);
                        prop.addAttribute(fac.createOMAttribute(APIFactory.ATT_NAME.getLocalPart(), nullNS, propName));
                        if (o instanceof String) {
                            prop.addAttribute(fac.createOMAttribute(APIFactory.ATT_VALUE.getLocalPart(), nullNS, (String) o));
                        } else {
                            prop.addChild((OMNode) o);
                        }
                        handlerElt.addChild(prop);
                    }
                }
            }
        }
        apiElt.addChild(handlersElt);
    }
    if (api.getProtocol() == RESTConstants.PROTOCOL_HTTP_ONLY) {
        apiElt.addAttribute("transports", Constants.TRANSPORT_HTTP, null);
    } else if (api.getProtocol() == RESTConstants.PROTOCOL_HTTPS_ONLY) {
        apiElt.addAttribute("transports", Constants.TRANSPORT_HTTPS, null);
    }
    return apiElt;
}
Also used : Resource(org.apache.synapse.rest.Resource) Iterator(java.util.Iterator) Handler(org.apache.synapse.rest.Handler) StatisticsConfigurable(org.apache.synapse.aspects.statistics.StatisticsConfigurable) Map(java.util.Map)

Aggregations

StatisticsConfigurable (org.apache.synapse.aspects.statistics.StatisticsConfigurable)5 Map (java.util.Map)2 OMElement (org.apache.axiom.om.OMElement)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 SynapseException (org.apache.synapse.SynapseException)1 AspectConfigurable (org.apache.synapse.aspects.AspectConfigurable)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)1 Handler (org.apache.synapse.rest.Handler)1 Resource (org.apache.synapse.rest.Resource)1 PolicyInfo (org.apache.synapse.util.PolicyInfo)1