Search in sources :

Example 6 with EndpointDefinition

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

the class AddressEndpointFactory method createEndpoint.

@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    AddressEndpoint addressEndpoint = new AddressEndpoint();
    OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name != null) {
        addressEndpoint.setName(name.getAttributeValue());
    }
    OMElement addressElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "address"));
    if (addressElement != null) {
        EndpointDefinition definition = createEndpointDefinition(addressElement);
        addressEndpoint.setDefinition(definition);
        processAuditStatus(definition, addressEndpoint.getName(), addressElement);
    }
    processProperties(addressEndpoint, epConfig);
    return addressEndpoint;
}
Also used : AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) QName(javax.xml.namespace.QName) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 7 with EndpointDefinition

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

the class DefaultEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof DefaultEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    DefaultEndpoint defaultEndpoint = (DefaultEndpoint) endpoint;
    serializeCommonAttributes(defaultEndpoint, endpointElement);
    EndpointDefinition epAddress = defaultEndpoint.getDefinition();
    OMElement defaultElement = serializeEndpointDefinition(epAddress);
    endpointElement.addChild(defaultElement);
    // serialize the properties
    serializeProperties(defaultEndpoint, endpointElement);
    return endpointElement;
}
Also used : DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement)

Example 8 with EndpointDefinition

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

the class WSDLEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof WSDLEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    WSDLEndpoint wsdlEndpoint = (WSDLEndpoint) endpoint;
    OMElement wsdlElement = fac.createOMElement("wsdl", SynapseConstants.SYNAPSE_OMNAMESPACE);
    String serviceName = wsdlEndpoint.getServiceName();
    if (serviceName != null) {
        wsdlElement.addAttribute("service", serviceName, null);
    }
    String portName = wsdlEndpoint.getPortName();
    if (portName != null) {
        wsdlElement.addAttribute("port", portName, null);
    }
    String uri = wsdlEndpoint.getWsdlURI();
    if (uri != null) {
        wsdlElement.addAttribute("uri", uri, null);
    }
    OMElement wsdlDoc = wsdlEndpoint.getWsdlDoc();
    if (wsdlDoc != null) {
        wsdlElement.addChild(wsdlDoc);
    }
    // currently, we have to get QOS information from the endpoint definition and set them as
    // special elements under the wsdl element. in future, these information should be
    // extracted from the wsdl.
    EndpointDefinition epDefinition = wsdlEndpoint.getDefinition();
    EndpointDefinitionSerializer serializer = new EndpointDefinitionSerializer();
    serializer.serializeEndpointDefinition(epDefinition, wsdlElement);
    serializeSpecificEndpointProperties(epDefinition, wsdlElement);
    endpointElement.addChild(wsdlElement);
    // serialize the parameters
    serializeProperties(wsdlEndpoint, endpointElement);
    serializeCommonAttributes(endpoint, endpointElement);
    return endpointElement;
}
Also used : WSDLEndpoint(org.apache.synapse.endpoints.WSDLEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement)

Example 9 with EndpointDefinition

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

the class WSDL11EndpointBuilder method populateEndpointDefinitionFromWSDL.

/**
 * Creates an EndpointDefinition for WSDL endpoint from an inline WSDL supplied in the WSDL
 * endpoint configuration.
 *
 * @param endpointDefinition the endpoint definition to populate
 * @param baseUri base uri of the wsdl
 * @param wsdl    OMElement representing the inline WSDL
 * @param service Service of the endpoint
 * @param port    Port of the endpoint
 * @return EndpointDefinition containing the information retrieved from the WSDL
 */
public EndpointDefinition populateEndpointDefinitionFromWSDL(EndpointDefinition endpointDefinition, String baseUri, OMElement wsdl, String service, String port) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        wsdl.serialize(baos);
        InputStream in = new ByteArrayInputStream(baos.toByteArray());
        InputSource inputSource = new InputSource(in);
        WSDLLocator wsdlLocator = new CustomWSDLLocator(inputSource, baseUri);
        Document doc = null;
        try {
            doc = XMLUtils.newDocument(inputSource);
        } catch (ParserConfigurationException e) {
            handleException("Parser Configuration Error", e);
        } catch (SAXException e) {
            handleException("Parser SAX Error", e);
        } catch (IOException e) {
            handleException(WSDLException.INVALID_WSDL + "IO Error", e);
        }
        if (doc != null) {
            WSDLFactory fac = WSDLFactory.newInstance();
            WSDLReader reader = fac.newWSDLReader();
            Definition definition = reader.readWSDL(wsdlLocator, doc.getDocumentElement());
            return createEndpointDefinitionFromWSDL(endpointDefinition, definition, service, port);
        }
    } catch (XMLStreamException e) {
        handleException("Error retrieving the WSDL definition from the inline WSDL.", e);
    } catch (WSDLException e) {
        handleException("Error retrieving the WSDL definition from the inline WSDL.", e);
    }
    return null;
}
Also used : WSDLLocator(javax.wsdl.xml.WSDLLocator) CustomWSDLLocator(org.apache.synapse.util.resolver.CustomWSDLLocator) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) WSDLFactory(javax.wsdl.factory.WSDLFactory) CustomWSDLLocator(org.apache.synapse.util.resolver.CustomWSDLLocator) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 10 with EndpointDefinition

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

the class ForwardingService method dispatch.

/**
 * Sends the message to a given endpoint.
 *
 * @param messageContext synapse {@link MessageContext} to be sent
 */
public void dispatch(MessageContext messageContext) {
    if (log.isDebugEnabled()) {
        log.debug("Sending the message to client with message processor [" + messageProcessor.getName() + "]");
    }
    // The below code is just for keeping the backward compatibility with the old code.
    if (targetEndpoint == null) {
        targetEndpoint = (String) messageContext.getProperty(ForwardingProcessorConstants.TARGET_ENDPOINT);
    }
    if (targetEndpoint != null) {
        Endpoint endpoint = messageContext.getEndpoint(targetEndpoint);
        if (endpoint == null) {
            log.error("Endpoint does not exists. Deactivating the message processor");
            deactivateMessageProcessor(messageContext);
            return;
        }
        AbstractEndpoint abstractEndpoint = (AbstractEndpoint) endpoint;
        EndpointDefinition endpointDefinition = abstractEndpoint.getDefinition();
        String endpointReferenceValue;
        if (endpointDefinition.getAddress() != null) {
            endpointReferenceValue = endpointDefinition.getAddress();
            // we only validate response for certain protocols (i.e HTTP/HTTPS)
            isResponseValidationNotRequired = !isResponseValidationRequiredEndpoint(endpointReferenceValue);
        }
        try {
            // Send message to the client
            while (!isSuccessful && !isTerminated) {
                tryToDispatchToEndpoint(messageContext, endpoint);
                isTerminated = messageProcessor.isDeactivated();
                if (!isSuccessful) {
                    prepareToRetry(messageContext);
                }
            }
        } catch (Exception e) {
            log.error("Message processor [" + messageProcessor.getName() + "] failed to send the message to" + " client", e);
        }
    } else {
        /*
			 * No Target Endpoint defined for the Message So we do not have a
			 * place to deliver.
			 * Here we log a warning and remove the message todo: we can improve
			 * this by implementing a target inferring
			 * mechanism.
			 */
        log.error("Neither targetEndpoint defined in the MessageProcessor configuration nor " + "Property " + ForwardingProcessorConstants.TARGET_ENDPOINT + " is found in the message context, hence deactivating the MessageProcessor");
        deactivateMessageProcessor(messageContext);
    }
}
Also used : AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) StoreForwardException(org.apache.synapse.message.StoreForwardException) SynapseException(org.apache.synapse.SynapseException) OMException(org.apache.axiom.om.OMException)

Aggregations

EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)24 OMElement (org.apache.axiom.om.OMElement)10 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)10 QName (javax.xml.namespace.QName)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 SynapseException (org.apache.synapse.SynapseException)6 MessageContext (org.apache.synapse.MessageContext)4 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)4 DefaultEndpoint (org.apache.synapse.endpoints.DefaultEndpoint)4 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)3 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)3 IOException (java.io.IOException)2 URI (java.net.URI)2 AxisFault (org.apache.axis2.AxisFault)2 TestMessageContext (org.apache.synapse.TestMessageContext)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 HTTPEndpoint (org.apache.synapse.endpoints.HTTPEndpoint)2 WSDLEndpoint (org.apache.synapse.endpoints.WSDLEndpoint)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1