syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject syncope git commit: [SYNCOPE-703] Online generation features extensions, offline profile similar to 1_2_X is now available
Date Wed, 07 Oct 2015 09:53:38 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 4a57705c3 -> 4cd1c1ea6


[SYNCOPE-703] Online generation features extensions, offline profile similar to 1_2_X is now
available


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4cd1c1ea
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4cd1c1ea
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4cd1c1ea

Branch: refs/heads/master
Commit: 4cd1c1ea653d3a3cc23f042825452dc7f735738e
Parents: 4a57705
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Wed Oct 7 11:53:32 2015 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Wed Oct 7 11:53:32 2015 +0200

----------------------------------------------------------------------
 common/rest-api/pom.xml                         |  17 +-
 core/rest-cxf/pom.xml                           | 306 +++++++++++--------
 .../syncope/core/rest/cxf/WADLServlet.java      |  96 ++++++
 .../main/resources/META-INF/web-fragment.xml    |  10 +
 .../src/main/resources/restCXFContext.xml       |  15 +-
 5 files changed, 317 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/4cd1c1ea/common/rest-api/pom.xml
----------------------------------------------------------------------
diff --git a/common/rest-api/pom.xml b/common/rest-api/pom.xml
index bbad479..280de26 100644
--- a/common/rest-api/pom.xml
+++ b/common/rest-api/pom.xml
@@ -56,7 +56,22 @@ under the License.
   </dependencies>
   
   <build>
-    <plugins>
+    <plugins>      
+      <!-- Generating javadoc JAR artifact for usage with CXF's WADL generator (for core)
-->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <inherited>true</inherited>
+        <executions>
+          <execution>
+            <id>attach-javadocs</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+
       <plugin>
         <groupId>org.apache.cxf</groupId>
         <artifactId>cxf-java2wadl-plugin</artifactId>

http://git-wip-us.apache.org/repos/asf/syncope/blob/4cd1c1ea/core/rest-cxf/pom.xml
----------------------------------------------------------------------
diff --git a/core/rest-cxf/pom.xml b/core/rest-cxf/pom.xml
index f88077b..2a1fcad 100644
--- a/core/rest-cxf/pom.xml
+++ b/core/rest-cxf/pom.xml
@@ -99,6 +99,12 @@ under the License.
       <groupId>org.apache.cxf</groupId>
       <artifactId>cxf-rt-rs-client</artifactId>
     </dependency>  
+    <dependency>
+      <groupId>org.apache.syncope.common</groupId>
+      <artifactId>syncope-common-rest-api</artifactId>
+      <version>${project.version}</version>
+      <classifier>javadoc</classifier>
+    </dependency>
     
     <dependency>
       <groupId>org.apache.syncope.core</groupId>
@@ -130,130 +136,7 @@ under the License.
   </dependencies>
 
   <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-        <inherited>false</inherited>
-        <configuration>
-          <outputDirectory>${project.build.directory}</outputDirectory>
-          <artifactItems>
-            <artifactItem>
-              <groupId>org.apache.syncope.common</groupId>
-              <artifactId>syncope-common-rest-api</artifactId>
-              <version>${project.version}</version>
-              <type>wadl</type>
-            </artifactItem>
-          </artifactItems>
-        </configuration>
-        <executions>
-          <execution>
-            <phase>process-resources</phase>
-            <goals>
-              <goal>copy</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-              
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>xml-maven-plugin</artifactId>
-        <inherited>true</inherited>
-        <executions>
-          <execution>
-            <phase>prepare-package</phase>
-            <goals>
-              <goal>transform</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <transformationSets>
-            <transformationSet>
-              <dir>${project.build.directory}</dir>
-              <includes>
-                <include>syncope-common-rest-api-${project.version}.wadl</include>
-              </includes>
-              <outputDir>${project.build.directory}/classes/META-INF/resources/doc</outputDir>
-              <stylesheet>${project.build.directory}/classes/wadl2html/identity.xsl</stylesheet>
-              <outputProperties>
-                <outputProperty>
-                  <name>indent</name>
-                  <value>yes</value>
-                </outputProperty>
-              </outputProperties>
-              <fileMappers>
-                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
-                  <pattern>^.*$</pattern>
-                  <replacement>syncope.wadl</replacement>
-                </fileMapper>
-              </fileMappers>
-            </transformationSet>
-            <transformationSet>
-              <dir>${project.build.directory}</dir>
-              <includes>
-                <include>syncope-common-rest-api-${project.version}.wadl</include>
-              </includes>
-              <outputDir>${project.build.directory}/classes/META-INF/resources/doc</outputDir>
-              <stylesheet>${project.build.directory}/classes/wadl2html/index.xsl</stylesheet>
-              <parameters>
-                <parameter>
-                  <name>contextPath</name>
-                  <value>..</value>
-                </parameter>
-              </parameters>
-              <outputProperties>
-                <outputProperty>
-                  <name>indent</name>
-                  <value>yes</value>
-                </outputProperty>
-              </outputProperties>
-              <fileMappers>
-                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
-                  <pattern>^.*$</pattern>
-                  <replacement>index.html</replacement>
-                </fileMapper>
-              </fileMappers>
-            </transformationSet>
-            <transformationSet>
-              <dir>${project.build.directory}</dir>
-              <includes>
-                <include>syncope-common-rest-api-${project.version}.wadl</include>
-              </includes>
-              <outputDir>${project.build.directory}/classes/META-INF/resources/doc</outputDir>
-              <stylesheet>${project.build.directory}/classes/wadl2html/schema.xsl</stylesheet>
-              <parameters>
-                <parameter>
-                  <name>contextPath</name>
-                  <value>..</value>
-                </parameter>
-                <parameter>
-                  <name>schema-position</name>
-                  <value>1</value>
-                </parameter>
-                <parameter>
-                  <name>schema-prefix</name>
-                  <value>syncope1</value>
-                </parameter>
-              </parameters>
-              <outputProperties>
-                <outputProperty>
-                  <name>indent</name>
-                  <value>yes</value>
-                </outputProperty>
-              </outputProperties>
-              <fileMappers>
-                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
-                  <pattern>^.*$</pattern>
-                  <replacement>schema_1_syncope1.html</replacement>
-                </fileMapper>
-              </fileMappers>
-            </transformationSet>
-          </transformationSets>
-        </configuration>
-      </plugin>
-            
+    <plugins>            
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-checkstyle-plugin</artifactId>
@@ -267,4 +150,179 @@ under the License.
       </resource>
     </resources>
   </build>
+  
+  <profiles>
+    <profile>
+      <id>offline-wadl</id>
+      
+      <build>
+        <defaultGoal>clean verify</defaultGoal>
+        
+        <plugins>
+          <!-- 1. Fetch offline WADL -->
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-dependency-plugin</artifactId>
+            <inherited>false</inherited>
+            <configuration>
+              <outputDirectory>${project.build.directory}</outputDirectory>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.syncope.common</groupId>
+                  <artifactId>syncope-common-rest-api</artifactId>
+                  <version>${project.version}</version>
+                  <type>wadl</type>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+            <executions>
+              <execution>
+                <id>fetch-offline-wadl</id>
+                <phase>process-resources</phase>
+                <goals>
+                  <goal>copy</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+              
+          <!-- 2. Transform WADL into 2 HTML pages -->
+          <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>xml-maven-plugin</artifactId>
+            <inherited>true</inherited>
+            <executions>
+              <execution>
+                <id>wadl2html</id>
+                <phase>process-resources</phase>
+                <goals>
+                  <goal>transform</goal>
+                </goals>
+              </execution>
+            </executions>
+            <configuration>
+              <transformationSets>
+                <transformationSet>
+                  <dir>${project.build.directory}</dir>
+                  <includes>
+                    <include>syncope-common-rest-api-${project.version}.wadl</include>
+                  </includes>
+                  <outputDir>${project.build.directory}/generated/wadl</outputDir>
+                  <stylesheet>${project.build.directory}/classes/wadl2html/identity.xsl</stylesheet>
+                  <outputProperties>
+                    <outputProperty>
+                      <name>indent</name>
+                      <value>yes</value>
+                    </outputProperty>
+                  </outputProperties>
+                  <fileMappers>
+                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
+                      <pattern>^.*$</pattern>
+                      <replacement>syncope.wadl</replacement>
+                    </fileMapper>
+                  </fileMappers>
+                </transformationSet>
+                <transformationSet>
+                  <dir>${project.build.directory}</dir>
+                  <includes>
+                    <include>syncope-common-rest-api-${project.version}.wadl</include>
+                  </includes>
+                  <outputDir>${project.build.directory}/generated/wadl</outputDir>
+                  <stylesheet>${project.build.directory}/classes/wadl2html/index.xsl</stylesheet>
+                  <parameters>
+                    <parameter>
+                      <name>contextPath</name>
+                      <value>..</value>
+                    </parameter>
+                  </parameters>
+                  <outputProperties>
+                    <outputProperty>
+                      <name>indent</name>
+                      <value>yes</value>
+                    </outputProperty>
+                  </outputProperties>
+                  <fileMappers>
+                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
+                      <pattern>^.*$</pattern>
+                      <replacement>index.html</replacement>
+                    </fileMapper>
+                  </fileMappers>
+                </transformationSet>
+                <transformationSet>
+                  <dir>${project.build.directory}</dir>
+                  <includes>
+                    <include>syncope-common-rest-api-${project.version}.wadl</include>
+                  </includes>
+                  <outputDir>${project.build.directory}/generated/wadl</outputDir>
+                  <stylesheet>${project.build.directory}/classes/wadl2html/schema.xsl</stylesheet>
+                  <parameters>
+                    <parameter>
+                      <name>contextPath</name>
+                      <value>..</value>
+                    </parameter>
+                    <parameter>
+                      <name>schema-position</name>
+                      <value>1</value>
+                    </parameter>
+                    <parameter>
+                      <name>schema-prefix</name>
+                      <value>syncope1</value>
+                    </parameter>
+                  </parameters>
+                  <outputProperties>
+                    <outputProperty>
+                      <name>indent</name>
+                      <value>yes</value>
+                    </outputProperty>
+                  </outputProperties>
+                  <fileMappers>
+                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
+                      <pattern>^.*$</pattern>
+                      <replacement>schema_1_syncope1.html</replacement>
+                    </fileMapper>
+                  </fileMappers>
+                </transformationSet>
+              </transformationSets>
+            </configuration>
+          </plugin>
+          
+          <!-- 3. Fix external references -->
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <inherited>true</inherited>
+            <executions>
+              <execution>
+                <id>fix-html-ext-refs</id>
+                <phase>process-resources</phase>
+                <configuration>
+                  <target>
+                    <replace file="${project.build.directory}/generated/wadl/index.html"
+                             token="../webjars/jquery/${jquery.version}/jquery.min.js"
+                             value="https://code.jquery.com/jquery-${jquery.version}.min.js"/>
+                    <replace file="${project.build.directory}/generated/wadl/index.html"
+                             token="../webjars/jquery-ui/${jquery-ui.version}/jquery-ui.min.js"
+                             value="http://code.jquery.com/ui/${jquery-ui.version}/jquery-ui.min.js"/>
+                    <replace file="${project.build.directory}/generated/wadl/index.html"
+                             token="../webjars/jquery-ui-themes/${jquery-ui.version}/smoothness/jquery-ui.min.css"
+                             value="https://code.jquery.com/ui/${jquery-ui.version}/themes/smoothness/jquery-ui.css"/>
     
+
+                    <replace file="${project.build.directory}/generated/wadl/schema_1_syncope1.html"
+                             token="../webjars/highlightjs/${highlightjs.version}/highlight.min.js"
+                             value="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/${highlightjs.version}/highlight.min.js"/>
+                    <replace file="${project.build.directory}/generated/wadl/schema_1_syncope1.html"
+                             token="../webjars/highlightjs/${highlightjs.version}/styles/default.min.css"
+                             value="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/${highlightjs.version}/styles/default.min.css"/>
     
+                  </target>
+                </configuration>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/syncope/blob/4cd1c1ea/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/WADLServlet.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/WADLServlet.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/WADLServlet.java
new file mode 100644
index 0000000..e05012a
--- /dev/null
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/WADLServlet.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.syncope.core.rest.cxf;
+
+import java.io.IOException;
+import java.net.URL;
+import java.rmi.ServerException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.cocoon.pipeline.CachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.component.XMLGenerator;
+import org.apache.cocoon.sax.component.XMLSerializer;
+import org.apache.cocoon.sax.component.XSLTTransformer;
+
+public class WADLServlet extends HttpServlet {
+
+    private static final long serialVersionUID = -6737005675471095560L;
+
+    private static final Pattern SCHEMA_PATTERN = Pattern.compile("/schema_(.*)_(.*)\\.html");
+
+    /**
+     * Handles the HTTP <code>GET</code> method.
+     *
+     * @param request servlet request
+     * @param response servlet response
+     * @throws ServletException if a servlet-specific error occurs
+     * @throws IOException if an I/O error occurs
+     */
+    @Override
+    protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
+            throws ServletException, IOException {
+
+        String requestURI = request.getRequestURI().substring(
+                request.getRequestURI().indexOf(request.getServletPath()) + request.getServletPath().length());
+        Matcher schemaMatcher = SCHEMA_PATTERN.matcher(requestURI);
+
+        Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<>();
+        final String wadlURL = request.getRequestURL().
+                substring(0, request.getRequestURL().indexOf("/doc")) + "/?_wadl";
+        pipeline.addComponent(new XMLGenerator(new URL(wadlURL)));
+        if ("/".equals(requestURI)) {
+            XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/wadl2html/index.xsl"));
+
+            Map<String, Object> parameters = new HashMap<>();
+            parameters.put("contextPath", request.getContextPath());
+            xslt.setParameters(parameters);
+
+            pipeline.addComponent(xslt);
+        } else if (schemaMatcher.matches()) {
+            XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/wadl2html/schema.xsl"));
+
+            Map<String, Object> parameters = new HashMap<>();
+            parameters.put("contextPath", request.getContextPath());
+            parameters.put("schema-position", schemaMatcher.group(1));
+            parameters.put("schema-prefix", schemaMatcher.group(2));
+            xslt.setParameters(parameters);
+
+            pipeline.addComponent(xslt);
+        } else {
+            throw new ServerException("URL not supported: " + request.getRequestURI());
+        }
+
+        pipeline.addComponent(XMLSerializer.createHTML4Serializer());
+        pipeline.setup(response.getOutputStream());
+        try {
+            pipeline.execute();
+        } catch (Exception e) {
+            throw new ServletException(e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/4cd1c1ea/core/rest-cxf/src/main/resources/META-INF/web-fragment.xml
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/resources/META-INF/web-fragment.xml b/core/rest-cxf/src/main/resources/META-INF/web-fragment.xml
index e9ded9d..a8a6e1f 100644
--- a/core/rest-cxf/src/main/resources/META-INF/web-fragment.xml
+++ b/core/rest-cxf/src/main/resources/META-INF/web-fragment.xml
@@ -47,6 +47,16 @@ under the License.
     <url-pattern>/rest/*</url-pattern>
   </servlet-mapping>
 
+  <servlet>
+    <servlet-name>WADLServlet</servlet-name>
+    <servlet-class>org.apache.syncope.core.rest.cxf.WADLServlet</servlet-class>
+    <load-on-startup>2</load-on-startup> 
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>WADLServlet</servlet-name>
+    <url-pattern>/rest/doc/*</url-pattern>
+  </servlet-mapping>
+
   <filter>
     <filter-name>encodingFilter</filter-name>
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

http://git-wip-us.apache.org/repos/asf/syncope/blob/4cd1c1ea/core/rest-cxf/src/main/resources/restCXFContext.xml
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/resources/restCXFContext.xml b/core/rest-cxf/src/main/resources/restCXFContext.xml
index b5b75db..2f6e70b 100644
--- a/core/rest-cxf/src/main/resources/restCXFContext.xml
+++ b/core/rest-cxf/src/main/resources/restCXFContext.xml
@@ -81,10 +81,20 @@ under the License.
   <bean id="addDomainFilter" class="org.apache.syncope.core.rest.cxf.AddDomainFilter"/>
   <bean id="addETagFilter" class="org.apache.syncope.core.rest.cxf.AddETagFilter"/>
   
+  <bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
+    <property name="applicationTitle" value="Apache Syncope ${syncope.version}"/>
+    <property name="namespacePrefix" value="syncope"/>
+    <property name="linkAnyMediaTypeToXmlSchema" value="true"/>
+    <property name="useJaxbContextForQnames" value="true"/>
+    <property name="addResourceAndMethodIds" value="true"/>
+    <property name="ignoreMessageWriters" value="true"/>
+    <property name="usePathParamsToCompareOperations" value="false"/>
+    <property name="javaDocPath" value="/WEB-INF/lib/syncope-common-rest-api-${syncope.version}-javadoc.jar"/>
+  </bean>
+  
   <jaxrs:server id="restContainer" address="/"
                 basePackages="org.apache.syncope.common.rest.api.service, org.apache.syncope.core.rest.cxf.service"

-                staticSubresourceResolution="true"
-                docLocation="classpath:/META-INF/resources/doc/syncope.wadl">
+                staticSubresourceResolution="true">
     <jaxrs:properties> 
       <entry key="search.lax.property.match" value="true"/> 
       <entry key="convert.wadl.resources.to.dom" value="false"/>
@@ -102,6 +112,7 @@ under the License.
       <ref bean="searchContextProvider"/>
       <ref bean="addDomainFilter"/>
       <ref bean="addETagFilter"/>
+      <ref bean="wadlGenerator"/>
     </jaxrs:providers>
     <jaxrs:extensionMappings>
       <entry key="json" value="application/json;charset=UTF-8"/>


Mime
View raw message