use of org.apache.synapse.api.API in project wso2-synapse by wso2.
the class APIDeployer method restoreSynapseArtifact.
@Override
public void restoreSynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Restoring the API with name : " + artifactName + " : Started");
}
try {
API api = getSynapseConfiguration().getAPI(artifactName);
if (api != null) {
api.setLogSetterValue();
}
OMElement apiElement = APISerializer.serializeAPI(api);
if (api.getFileName() != null) {
String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.REST_API_DIR + File.separator + api.getFileName();
writeToFile(apiElement, fileName);
if (log.isDebugEnabled()) {
log.debug("Restoring the API with name : " + artifactName + " : Completed");
}
log.info("API named '" + artifactName + "' has been restored");
} else {
handleSynapseArtifactDeploymentError("Couldn't restore the API named '" + artifactName + "', filename cannot be found");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Restoring of the API named '" + artifactName + "' has failed", e);
}
}
use of org.apache.synapse.api.API in project wso2-synapse by wso2.
the class APIDispatcherTest method testAPIContextVersionBasedDispatchWithNoVersion.
public void testAPIContextVersionBasedDispatchWithNoVersion() throws Exception {
API api = new API(TEST_API, "/test");
api.setVersionStrategy(new ContextVersionStrategy(api, TEST_API_VERSION, null));
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
RESTRequestHandler handler = new RESTRequestHandler();
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test/", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar?a=5", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test?a=5", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
// Message with '/test' context & URL as a Query Parameter should be dispatched
synCtx = getMessageContext(synapseConfig, false, "/test?a=http://localhost.com", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
}
use of org.apache.synapse.api.API in project wso2-synapse by wso2.
the class APIDispatcherTest method testGeneralAPIDispatch.
public void testGeneralAPIDispatch() throws Exception {
API api = new API(TEST_API, "/");
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(TEST_API, api);
RESTRequestHandler handler = new RESTRequestHandler();
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
handler.process(synCtx);
assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
synCtx = getMessageContext(synapseConfig, false, "/", "GET");
handler.process(synCtx);
assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
synCtx = getMessageContext(synapseConfig, false, "/foo/bar?a=5", "GET");
handler.process(synCtx);
assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
}
use of org.apache.synapse.api.API in project wso2-synapse by wso2.
the class SynapseConfigurationTest method testAPITableOrderWithAddAPIwithoutReOrder.
public void testAPITableOrderWithAddAPIwithoutReOrder() {
SynapseConfiguration config = new SynapseConfiguration();
API api1 = new API("API1", "/context/test");
API api2 = new API("API2", "/context");
API api3 = new API("API3", "/context/test/ctx");
config.addAPI("API1", api1, false);
config.addAPI("API2", api2, false);
config.addAPI("API3", api3, false);
// this should get the api table as it is.
Collection<API> apis = config.getAPIs();
API[] apisArray = apis.toArray(new API[apis.size()]);
// api1 with context /context/test/ctx should be first in the list
assertEquals("Order is not correct before sorting", api1, apisArray[0]);
// calling explicitly to order the apitable
config.reconstructAPITable();
apis = config.getAPIs();
API[] apisArray2 = apis.toArray(new API[apis.size()]);
// api3 with context /context/test/ctx should be first in the list
assertEquals("Order is not correct", api3, apisArray2[0]);
}
use of org.apache.synapse.api.API in project wso2-synapse by wso2.
the class StatisticSynapseConfigurationObserverTest method testApiUpdated.
/**
* Test apiUpdated method by hash generation.
*/
@Test
public void testApiUpdated() {
final String apiName = "testName";
final String apiContext = "/testContext";
API api = new API(apiName, apiContext);
observer.apiUpdated(api);
Assert.assertNotNull("New hash must be set by the method", api.getAspectConfiguration().getHashCode());
}
Aggregations