feat(demo): Custom path parser demo plugin
ADD
custom-path-parser-demo/pom.xml
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>io.apiman.plugins</groupId>
+ <artifactId>apiman-plugins</artifactId>
+ <version>1.4.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>custom-path-parser-plugin-demo</artifactId>
+ <packaging>war</packaging>
+ <name>custom-path-parser-plugin-demo</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.apiman</groupId>
+ <artifactId>apiman-test-policies</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- apiman dependencies (must be excluded from the WAR) -->
+ <dependency>
+ <groupId>io.apiman</groupId>
+ <artifactId>apiman-gateway-engine-beans</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.apiman</groupId>
+ <artifactId>apiman-gateway-engine-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.apiman</groupId>
+ <artifactId>apiman-gateway-engine-policies</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <webResources>
+ <resource>
+ <directory>src/main/apiman</directory>
+ <targetPath>META-INF/apiman</targetPath>
+ <filtering>true</filtering>
+ </resource>
+ </webResources>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>

ADD
custom-path-parser-demo/src/main/apiman/plugin.json
+{
+ "frameworkVersion" : 1.0,
+ "name" : "Custom Path Parser Plugin Demo",
+ "description" : "This plugin provide a demonstration of a custom path parser for the Apiman Gateway.",
+ "version" : "${project.version}"
+}

ADD
custom-path-parser-demo/src/main/java/io/apiman/plugins/demo/custompathparser/CustomPathParserImpl.java
+/*
+ * Copyright 2018 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.apiman.plugins.demo.custompathparser;
+
+import io.apiman.common.util.ApimanPathUtils.ApiRequestPathInfo;
+import io.apiman.gateway.engine.IApiRequestPathParser;
+import io.apiman.gateway.engine.beans.util.HeaderMap;
+import io.apiman.gateway.engine.impl.DefaultRequestPathParser;
+
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+/**
+ * Example {@link IApiRequestPathParser} implementation.
+ *
+ * See {@link DefaultRequestPathParser} for the standard implementation.
+ *
+ * @author Marc Savy {@literal <marc@rhymewithgravy.com>}
+ */
+@SuppressWarnings("nls")
+public class CustomPathParserImpl implements IApiRequestPathParser {
+ private final String defaultOrgName;
+
+ public CustomPathParserImpl(Map<String, String> config) {
+ // Pass in the defaultOrgName from static config or just use "DefaultOrg".
+ this.defaultOrgName = config.getOrDefault("defaultOrgName", "DefaultOrg");
+ }
+
+ @Override
+ public ApiRequestPathInfo parseEndpoint(String path, HeaderMap headers) {
+ String[] split = StringUtils.split(path, "/", 3);
+
+ if (split == null || split.length < 2) {
+ throw new IllegalArgumentException("Invalid path format, expected /apiId/apiVersion/<resource path>");
+ }
+
+ ApiRequestPathInfo parsed = new ApiRequestPathInfo();
+ // Let's set the org name manually as our configured `defaultOrgName`
+ parsed.orgId = defaultOrgName;
+ parsed.apiId = split[0];
+ parsed.apiVersion = split[1];
+ if (split.length > 2) {
+ parsed.resource = "/" + split[2];
+ } else {
+ parsed.resource = "/";
+ }
+ return parsed;
+ }
+}

MODIFY
pom.xml
pom.xml
<module>url-whitelist-policy</module>
<module>repository</module>
<module>auth-3scale</module>
+ <module>custom-path-parser-demo</module>
</modules>
<profiles>

feat(demo): Custom path parser demo plugin