public static Resource createResource(OMElement resourceElt) { Resource resource = new Resource(); configureURLMappings(resource, resourceElt); configureSequences(resource, resourceElt); configureFilters(resource, resourceElt); return resource; }
public static API createAPI(OMElement apiElt) { return createAPI(apiElt, new Properties()); }
public static Resource createResource(OMElement resourceElt) { return createResource(resourceElt, new Properties()); }
public void testAPISerialization1() throws Exception { String xml = "<api name=\"test\" context=\"/dictionary\" transports=\"https\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<resource url-mapping=\"/admin/view\" inSequence=\"in\" outSequence=\"out\"/></api>"; OMElement om = AXIOMUtil.stringToOM(xml); API api = APIFactory.createAPI(om); OMElement out = APISerializer.serializeAPI(api); assertXMLEqual(xml, out.toString()); }
public static API createAPI(OMElement apiElt) { OMAttribute nameAtt = apiElt.getAttribute(new QName("name")); if (nameAtt == null || "".equals(nameAtt.getAttributeValue())) { handleException("Attribute 'name' is required for an API definition"); return null; handleException("Attribute 'context' is required for an API definition"); return null; VersionStrategy vStrategy = VersionStrategyFactory.createVersioningStrategy(api, apiElt); while (resources.hasNext()) { OMElement resourceElt = (OMElement) resources.next(); api.addResource(ResourceFactory.createResource(resourceElt)); noResources = false; handleException("An API must contain at least one resource definition"); while (handlers.hasNext()) { OMElement handlerElt = (OMElement) handlers.next(); defineHandler(api, handlerElt); api.setProtocol(RESTConstants.PROTOCOL_HTTPS_ONLY); } else { handleException("Invalid protocol name: " + transports);
private static void serializeAPIs(OMElement definitions, Collection<API> apiSet) { for (API api : apiSet) { OMElement apiElt = APISerializer.serializeAPI(api); definitions.addChild(apiElt); } }
public static VersionStrategy createVersioningStrategy(API api, OMElement apiElt) { OMAttribute versionAtt = apiElt.getAttribute(new QName("version")); if (versionAtt == null || "".equals(versionAtt.getAttributeValue())) { // handleException("Attribute 'version' is required for an API definition"); } OMAttribute versionTypeAtt = apiElt.getAttribute(new QName("version-type")); if (versionAtt != null && (versionTypeAtt == null || "".equals(versionTypeAtt.getAttributeValue()))) { handleException("Attribute 'version-type' is required for an API definition"); } OMAttribute versionParamAtt = apiElt.getAttribute(new QName("version-param")); String version = ""; if (versionAtt != null) { version = versionAtt.getAttributeValue(); } String versionType = ""; if (versionTypeAtt != null) { versionType = versionTypeAtt.getAttributeValue(); } String versionParam = ""; if (versionParamAtt != null) { versionParam = versionParamAtt.getAttributeValue(); } return selectVersionStrategy(api, version, versionType, versionParam); }
apiElt.addAttribute("context", api.getContext(), null); VersionStrategySerializer.serializeVersioningStrategy(api.getVersionStrategy(), apiElt) ; if (api.getHost() != null) { apiElt.addAttribute("hostname", api.getHost(), null); OMElement resourceElt = ResourceSerializer.serializeResource(r); apiElt.addChild(resourceElt);
private static void defineHandler(API api, OMElement handlerElt) { String handlerClass = handlerElt.getAttributeValue(new QName("class")); if (handlerClass == null || "".equals(handlerClass)) { handleException("A handler element must have a class attribute"); } try { Class clazz = APIFactory.class.getClassLoader().loadClass(handlerClass); Handler handler = (Handler) clazz.newInstance(); api.addHandler(handler); } catch (Exception e) { handleException("Error initializing API handler: " + handlerClass, e); } }
public void testAPISerialization4() throws Exception { String xml = "<api name=\"test\" context=\"/dictionary\" transports=\"https\" hostname=\"apache.org\" port=\"8243\"" + " xmlns=\"http://ws.apache.org/ns/synapse\"><resource url-mapping=\"/admin/view\" " + "outSequence=\"out\"><inSequence><log/><send/></inSequence></resource></api>"; OMElement om = AXIOMUtil.stringToOM(xml); API api = APIFactory.createAPI(om); OMElement out = APISerializer.serializeAPI(api); assertXMLEqual(xml, out.toString()); }
public static Resource createResource(OMElement resourceElt, Properties properties) { Resource resource = new Resource(); configureURLMappings(resource, resourceElt); configureSequences(resource, resourceElt, properties); configureFilters(resource, resourceElt); return resource; }
public static OMElement serializeAPI(OMElement parent, API api) { OMElement apiElt = serializeAPI(api); if (parent != null) { parent.addChild(apiElt); } return apiElt; }
public static API defineAPI(SynapseConfiguration config, OMElement elem, Properties properties) { API api = null; try { api = APIFactory.createAPI(elem, properties); config.addAPI(api.getName(), api); } catch (Exception e) { String msg = "API configuration cannot be built"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e); } return api; }
public void testAPISerialization3() throws Exception { String xml = "<api name=\"test\" context=\"/dictionary\" transports=\"https\" hostname=\"apache.org\" port=\"8243\"" + " xmlns=\"http://ws.apache.org/ns/synapse\"><resource url-mapping=\"/admin/view\" " + "inSequence=\"in\"><outSequence><log/><send/></outSequence></resource></api>"; OMElement om = AXIOMUtil.stringToOM(xml); API api = APIFactory.createAPI(om); OMElement out = APISerializer.serializeAPI(api); assertXMLEqual(xml, out.toString()); }
private static void serializeAPIs(OMElement definitions, Collection<API> apiSet) { for (API api : apiSet) { OMElement apiElt = APISerializer.serializeAPI(api); definitions.addChild(apiElt); } }
public static API defineAPI(SynapseConfiguration config, OMElement elem) { API api = null; try { api = APIFactory.createAPI(elem); config.addAPI(api.getName(), api); } catch (Exception e) { String msg = "API configuration cannot be built"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_APIS, msg, e); } return api; }
public void testAPISerialization2() throws Exception { String xml = "<api name=\"test\" context=\"/dictionary\" transports=\"https\" hostname=\"apache.org\" port=\"8243\"" + " xmlns=\"http://ws.apache.org/ns/synapse\"><resource url-mapping=\"/admin/view\" " + "inSequence=\"in\" outSequence=\"out\"/></api>"; OMElement om = AXIOMUtil.stringToOM(xml); API api = APIFactory.createAPI(om); OMElement out = APISerializer.serializeAPI(api); assertXMLEqual(xml, out.toString()); }
public OMElement serializeAPI(API api, SynapseConfiguration synapseConfig, OMElement parent) throws Exception { File apiDir = createDirectory(currentDirectory, MultiXMLConfigurationBuilder.REST_API_DIR); OMElement apiElement = APISerializer.serializeAPI(api); String fileName = api.getFileName(); if (fileName != null) { if (currentDirectory == rootDirectory) { handleDeployment(apiDir, fileName, api.getName(), synapseConfig.getArtifactDeploymentStore()); } File apiFile = new File(apiDir, fileName); writeToFile(apiElement, apiFile); } else if (parent != null) { parent.addChild(apiElement); } return apiElement; }
/** * Add api with the option of re-ordering the api collection based on the context * * @param config SynapseConfiguration * @param elem OMElement element * @param properties Properties * @param reOrder reorder the deployment order based on the context * @return API api object */ public static API defineAPI(SynapseConfiguration config, OMElement elem, Properties properties, boolean reOrder) { API api = null; try { api = APIFactory.createAPI(elem, properties); config.addAPI(api.getName(), api, reOrder); } catch (Exception e) { String msg = "API configuration cannot be built"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e); } return api; }
public void testAPISerialization5() throws Exception { String xml = "<api name=\"test\" context=\"/dictionary\" transports=\"https\" hostname=\"apache.org\" port=\"8243\"" + " xmlns=\"http://ws.apache.org/ns/synapse\"><resource url-mapping=\"/admin/view/*\" " + "><inSequence><log/><send/></inSequence><outSequence><log/><send/></outSequence></resource>" + "<resource url-mapping=\"/admin/*\"><inSequence><log/><send/></inSequence><outSequence>" + "<log/><send/></outSequence></resource><resource uri-template=\"/{char}/{word}\">" + "<inSequence><send/></inSequence><faultSequence><log level=\"full\"/></faultSequence>" + "</resource></api>"; OMElement om = AXIOMUtil.stringToOM(xml); API api = APIFactory.createAPI(om); OMElement out = APISerializer.serializeAPI(api); assertXMLEqual(xml, out.toString()); } }