You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/01/30 13:54:33 UTC

[1/2] syncope git commit: Restoring QueryResourceInfoComparator removed by SYNCOPE-630 in order to avoid test failures with JDK 6

Repository: syncope
Updated Branches:
  refs/heads/2_0_X 64fa513e1 -> 0430d834c


Restoring QueryResourceInfoComparator removed by SYNCOPE-630 in order to avoid test failures with JDK 6


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

Branch: refs/heads/2_0_X
Commit: aea63b64d144b9f4d95cf5927ec0b19312085679
Parents: 64fa513
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Fri Jan 30 13:53:16 2015 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Fri Jan 30 13:53:16 2015 +0100

----------------------------------------------------------------------
 .../rest/utils/QueryResourceInfoComparator.java | 114 +++++++++++++++++++
 core/src/main/resources/restContext.xml         |   3 +
 2 files changed, 117 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/aea63b64/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java b/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java
new file mode 100644
index 0000000..bcc015d
--- /dev/null
+++ b/core/src/main/java/org/apache/syncope/core/rest/utils/QueryResourceInfoComparator.java
@@ -0,0 +1,114 @@
+/*
+ * 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.utils;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.jaxrs.ext.ResourceComparator;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Message;
+
+public class QueryResourceInfoComparator extends OperationResourceInfoComparator implements ResourceComparator {
+
+    public QueryResourceInfoComparator() {
+        super(null, null);
+    }
+
+    @Override
+    public int compare(final ClassResourceInfo cri1, final ClassResourceInfo cri2, final Message message) {
+        // Leave Class selection to CXF
+        return 0;
+    }
+
+    @Override
+    public int compare(final OperationResourceInfo oper1, final OperationResourceInfo oper2, final Message message) {
+        // Check if CXF can make a decision
+        int cxfResult = super.compare(oper1, oper2);
+        if (cxfResult != 0) {
+            return cxfResult;
+        }
+
+        int op1Counter = getMatchingRate(oper1, message);
+        int op2Counter = getMatchingRate(oper2, message);
+
+        return op1Counter == op2Counter
+                ? 0
+                : op1Counter < op2Counter
+                ? 1
+                : -1;
+    }
+
+    /**
+     * This method calculates a number indicating a good or bad match between values provided within the request and
+     * expected method parameters. A higher number means a better match.
+     *
+     * @param operation The operation to be rated, based on contained parameterInfo values.
+     * @param message A message containing query and header values from user request
+     * @return A positive or negative number, indicating a good match between query and method
+     */
+    protected int getMatchingRate(final OperationResourceInfo operation, final Message message) {
+        List<Parameter> params = operation.getParameters();
+        if (params == null || params.isEmpty()) {
+            return 0;
+        }
+
+        // Get Request QueryParams
+        String query = (String) message.get(Message.QUERY_STRING);
+        String path = (String) message.get(Message.REQUEST_URI);
+        Map<String, List<String>> qParams = JAXRSUtils.getStructuredParams(query, "&", true, false);
+        Map<String, List<String>> mParams = JAXRSUtils.getMatrixParams(path, true);
+        // Get Request Headers
+        Map<?, ?> qHeader = (java.util.Map<?, ?>) message.get(Message.PROTOCOL_HEADERS);
+
+        int rate = 0;
+        for (Parameter p : params) {
+            switch (p.getType()) {
+                case QUERY:
+                    if (qParams.containsKey(p.getName())) {
+                        rate += 2;
+                    } else if (p.getDefaultValue() == null) {
+                        rate -= 1;
+                    }
+                    break;
+                case MATRIX:
+                    if (mParams.containsKey(p.getName())) {
+                        rate += 2;
+                    } else if (p.getDefaultValue() == null) {
+                        rate -= 1;
+                    }
+                    break;
+                case HEADER:
+                    if (qHeader.containsKey(p.getName())) {
+                        rate += 2;
+                    } else if (p.getDefaultValue() == null) {
+                        rate -= 1;
+                    }
+                    break;
+                default:
+                    break;
+            }
+        }
+        return rate;
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/aea63b64/core/src/main/resources/restContext.xml
----------------------------------------------------------------------
diff --git a/core/src/main/resources/restContext.xml b/core/src/main/resources/restContext.xml
index 7b6fe30..1b71e31 100644
--- a/core/src/main/resources/restContext.xml
+++ b/core/src/main/resources/restContext.xml
@@ -100,6 +100,9 @@ under the License.
   <jaxrs:server id="restContainer" address="/" 
                 basePackages="org.apache.syncope.common.services, org.apache.syncope.core.services" 
                 staticSubresourceResolution="true">
+    <jaxrs:resourceComparator>
+      <bean id="queryResourceInfoComparator" class="org.apache.syncope.core.rest.utils.QueryResourceInfoComparator"/>
+    </jaxrs:resourceComparator>
     <jaxrs:properties> 
       <entry key="search.lax.property.match" value="true"/> 
     </jaxrs:properties> 


[2/2] syncope git commit: JDK 7 for 2_0_X

Posted by il...@apache.org.
JDK 7 for 2_0_X


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

Branch: refs/heads/2_0_X
Commit: 0430d834cd8a2b848ca160c590bef907d1937810
Parents: aea63b6
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Fri Jan 30 13:53:53 2015 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Fri Jan 30 13:53:53 2015 +0100

----------------------------------------------------------------------
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/0430d834/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index e9245f1..6f627ae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,7 +15,7 @@
 
 language: java
 jdk:
-  - openjdk6
+  - openjdk7
 # default install is mvn install --quiet -DskipTests=true
 install: mvn --show-version --quiet -P skipTests
 #invoker.streamLogs: we cannot access to log files through Travis web ui, so display everything in the console