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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations