use of org.apache.synapse.endpoints.HTTPEndpoint in project wso2-synapse by wso2.
the class HTTPEndpointSerializerTest method test.
public void test() throws Exception {
String inputXml = "<endpoint xmlns=\"http://ws.apache.org/ns/synapse\">" + "<http uri-template=\"URI Template\" method=\"GET\" />" + "</endpoint>";
OMElement inputElement = AXIOMUtil.stringToOM(inputXml);
HTTPEndpoint endpoint = (HTTPEndpoint) HTTPEndpointFactory.getEndpointFromElement(inputElement, true, null);
OMElement serializedResponse = HTTPEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue("Endpoint not serialized!", compare(serializedResponse, inputElement));
}
use of org.apache.synapse.endpoints.HTTPEndpoint in project carbon-apimgt by wso2.
the class WebSocketUtils method getEndpointUrl.
/**
* Gets the uri-template of the endpoint, which has been specified in the given resource.
* @param resource API Resource
* @param synCtx MessageContext
* @return URI template
*/
public static String getEndpointUrl(Resource resource, MessageContext synCtx) {
Optional<Mediator> filterMediator = resource.getInSequence().getList().stream().filter(m -> m instanceof FilterMediator).findFirst();
if (filterMediator.isPresent()) {
Optional<Mediator> sendMediator = ((FilterMediator) filterMediator.get()).getList().stream().filter(m -> m instanceof SendMediator).findFirst();
if (sendMediator.isPresent()) {
Endpoint endpoint = ((SendMediator) sendMediator.get()).getEndpoint();
if (endpoint instanceof IndirectEndpoint) {
String endpointKey = ((IndirectEndpoint) endpoint).getKey();
Endpoint directEndpoint = synCtx.getConfiguration().getEndpoint(endpointKey);
if (directEndpoint instanceof HTTPEndpoint) {
return ((HTTPEndpoint) synCtx.getConfiguration().getEndpoint(endpointKey)).getUriTemplate().getTemplate();
}
}
}
}
// Ideally we won't reach here
return null;
}
use of org.apache.synapse.endpoints.HTTPEndpoint in project wso2-synapse by wso2.
the class HTTPEndpointFactory method createEndpoint.
@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
HTTPEndpoint httpEndpoint = new HTTPEndpoint();
OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
httpEndpoint.setName(name.getAttributeValue());
}
OMElement httpElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "http"));
if (httpElement != null) {
EndpointDefinition definition = createEndpointDefinition(httpElement);
OMAttribute uriTemplateAttr = httpElement.getAttribute(new QName("uri-template"));
if (uriTemplateAttr != null) {
if (uriTemplateAttr.getAttributeValue().startsWith(HTTPEndpoint.legacyPrefix)) {
httpEndpoint.setUriTemplate(UriTemplate.fromTemplate(uriTemplateAttr.getAttributeValue().substring(HTTPEndpoint.legacyPrefix.length())));
// Set the address to the initial template value.
definition.setAddress(uriTemplateAttr.getAttributeValue().substring(HTTPEndpoint.legacyPrefix.length()));
httpEndpoint.setLegacySupport(true);
} else {
httpEndpoint.setUriTemplate(UriTemplate.fromTemplate(uriTemplateAttr.getAttributeValue()));
// Set the address to the initial template value.
definition.setAddress(uriTemplateAttr.getAttributeValue());
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);
return httpEndpoint;
}
use of org.apache.synapse.endpoints.HTTPEndpoint in project wso2-synapse by wso2.
the class HTTPEndpointSerializer method serializeEndpoint.
@Override
protected OMElement serializeEndpoint(Endpoint endpoint) {
if (!(endpoint instanceof HTTPEndpoint)) {
handleException("Invalid endpoint type.");
}
fac = OMAbstractFactory.getOMFactory();
OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
HTTPEndpoint httpEndpoint = (HTTPEndpoint) endpoint;
EndpointDefinition epDefinitionHttp = httpEndpoint.getDefinition();
OMElement httpEPElement = serializeEndpointDefinition(epDefinitionHttp);
if (httpEndpoint.getHttpMethod() != null) {
httpEPElement.addAttribute(fac.createOMAttribute("method", null, httpEndpoint.getHttpMethod()));
}
if (httpEndpoint.getUriTemplate() != null) {
if (httpEndpoint.isLegacySupport()) {
httpEPElement.addAttribute(fac.createOMAttribute("uri-template", null, HTTPEndpoint.legacyPrefix + httpEndpoint.getUriTemplate().getTemplate()));
} else {
httpEPElement.addAttribute(fac.createOMAttribute("uri-template", null, httpEndpoint.getUriTemplate().getTemplate()));
}
}
endpointElement.addChild(httpEPElement);
// serialize the properties
serializeProperties(httpEndpoint, endpointElement);
serializeCommonAttributes(endpoint, endpointElement);
return endpointElement;
}
Aggregations