Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id ECFA1200CAD for ; Mon, 5 Jun 2017 17:35:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id EBACE160BD4; Mon, 5 Jun 2017 15:35:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2086C160BBF for ; Mon, 5 Jun 2017 17:35:29 +0200 (CEST) Received: (qmail 67617 invoked by uid 500); 5 Jun 2017 15:35:28 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 67595 invoked by uid 99); 5 Jun 2017 15:35:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jun 2017 15:35:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D0995E000B; Mon, 5 Jun 2017 15:35:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: csierra@apache.org To: commits@aries.apache.org Date: Mon, 05 Jun 2017 15:35:27 -0000 Message-Id: <2608dedf25a94607bf3f3e6b5c50816b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] aries-jax-rs-whiteboard git commit: Register services in order archived-at: Mon, 05 Jun 2017 15:35:31 -0000 Repository: aries-jax-rs-whiteboard Updated Branches: refs/heads/master c34b36fce -> a012f18ef Register services in order Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/32396a87 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/32396a87 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/32396a87 Branch: refs/heads/master Commit: 32396a87fd90de88f5472e0c21354ce5da5a246b Parents: c34b36f Author: Carlos Sierra Authored: Wed Apr 5 18:44:39 2017 +0200 Committer: Carlos Sierra Committed: Mon Jun 5 16:25:07 2017 +0200 ---------------------------------------------------------------------- .../internal/CXFJaxRsServiceRegistrator.java | 35 ++++++++++++++------ .../aries/jax/rs/whiteboard/internal/Utils.java | 10 +++--- 2 files changed, 31 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/32396a87/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java index dd91521..57e095a 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java @@ -19,9 +19,11 @@ package org.apache.aries.jax.rs.whiteboard.internal; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeSet; import javax.ws.rs.core.Application; import javax.ws.rs.ext.RuntimeDelegate; @@ -47,7 +49,8 @@ public class CXFJaxRsServiceRegistrator { private final Map _properties; private final Collection _providers = new ArrayList<>(); private Server _server; - private final Collection _services = new ArrayList<>(); + private final Collection>> + _services = new TreeSet<>(Comparator.reverseOrder()); private static final String CXF_ENDPOINT_ADDRESS = "CXF_ENDPOINT_ADDRESS"; @@ -193,34 +196,46 @@ public class CXFJaxRsServiceRegistrator { String address = safeToString(_properties.get(CXF_ENDPOINT_ADDRESS)); - if (address != null) { - jaxRsServerFactoryBean.setAddress(address); - } + jaxRsServerFactoryBean.setAddress(address); _server = jaxRsServerFactoryBean.create(); _server.start(); } - public static class ResourceInformation { - private final String prefixPath; + public static class ResourceInformation> + implements Comparable> { + + private final String _prefixPath; + private final T _comparable; private final ResourceProvider _resourceProvider; public ResourceInformation( - String prefixPath, ResourceProvider resourceProvider) { + T comparable, String prefixPath, + ResourceProvider resourceProvider) { - this.prefixPath = prefixPath; - this._resourceProvider = resourceProvider; + _comparable = comparable; + + _resourceProvider = resourceProvider; } public String getPrefixPath() { - return prefixPath; + return _prefixPath; } public ResourceProvider getResourceProvider() { return _resourceProvider; } + @Override + public int compareTo(ResourceInformation resourceInformation) { + if (resourceInformation == null) { + return 1; + } + + return _comparable.compareTo(resourceInformation._comparable); + } + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/32396a87/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java index 0951f6e..0836ac0 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java @@ -23,6 +23,7 @@ import org.apache.cxf.Bus; import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; import org.apache.cxf.message.Message; import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceObjects; import org.osgi.framework.ServiceReference; import org.osgi.framework.wiring.BundleWiring; @@ -129,8 +130,9 @@ public class Utils { try { thread.setContextClassLoader(classLoader); - ResourceInformation resourceInformation = new ResourceInformation( - resourceBase, resourceProvider); + ResourceInformation> resourceInformation = + new ResourceInformation<>( + serviceReference, resourceBase, resourceProvider); registrator.add(resourceInformation); return just(resourceInformation); } @@ -139,8 +141,8 @@ public class Utils { } } - public static String safeToString(Object resourceBaseObject) { - return resourceBaseObject == null ? "" : resourceBaseObject.toString(); + public static String safeToString(Object object) { + return object == null ? "" : object.toString(); } public static ResourceProvider getResourceProvider(