killbill-memoizeit

Simplify plugin name registration

3/27/2013 4:07:07 PM

Changes

osgi/pom.xml 6(+6 -0)

Details

diff --git a/api/src/main/java/com/ning/billing/ErrorCode.java b/api/src/main/java/com/ning/billing/ErrorCode.java
index f458c24..50e4fde 100644
--- a/api/src/main/java/com/ning/billing/ErrorCode.java
+++ b/api/src/main/java/com/ning/billing/ErrorCode.java
@@ -267,6 +267,7 @@ public enum ErrorCode {
     PAYMENT_REFUND_AMOUNT_TOO_LARGE(7025, "Refund amount if larger than payment"),
     PAYMENT_REFUND_AMOUNT_NEGATIVE_OR_NULL(7026, "Refund amount needs to be strictly positive"),
     PAYMENT_BAD_ACCOUNT(7027, "Account %s has payments left in an unknwon state"),
+    PAYMENT_NO_SUCH_PAYMENT_PLUGIN(7028, "Payment plugin %s is not registered"),
 
     PAYMENT_PLUGIN_TIMEOUT(7100, "Plugin timeout for account %s and invoice %s"),
     PAYMENT_PLUGIN_ACCOUNT_INIT(7101, "Account initialization for account %s and plugin % s failed: %s"),
diff --git a/api/src/main/java/com/ning/billing/osgi/api/OSGIPluginProperties.java b/api/src/main/java/com/ning/billing/osgi/api/OSGIPluginProperties.java
index e1873e0..6e952a0 100644
--- a/api/src/main/java/com/ning/billing/osgi/api/OSGIPluginProperties.java
+++ b/api/src/main/java/com/ning/billing/osgi/api/OSGIPluginProperties.java
@@ -23,15 +23,6 @@ package com.ning.billing.osgi.api;
 public interface OSGIPluginProperties {
 
     /** Name of the plugin when it registers itself */
-    // TODO We should make sure that this mataches the 'symbolic name' of the plugin, or if not how those two play together
     public static final String PLUGIN_NAME_PROP = "killbill.pluginName";
 
-    /** Name of the instnace of the plugin; if 2 instances of the same plugin register */
-    public static final String PLUGIN_INSTANCE_PROP = "killbill.pluginInstance";
-
-    /** Used to export an additional configuration string for that service
-     *  For instance for Servlet services this is used to specify the path of the servlet.
-     */
-    public static final String PLUGIN_SERVICE_INFO = "killbill.pluginServiceInfo";
-
 }
diff --git a/api/src/main/java/com/ning/billing/osgi/api/OSGIServiceDescriptor.java b/api/src/main/java/com/ning/billing/osgi/api/OSGIServiceDescriptor.java
index d281471..c4ca936 100644
--- a/api/src/main/java/com/ning/billing/osgi/api/OSGIServiceDescriptor.java
+++ b/api/src/main/java/com/ning/billing/osgi/api/OSGIServiceDescriptor.java
@@ -27,17 +27,6 @@ public interface OSGIServiceDescriptor {
      *
      * @return the unique of that service-- plugin should rely on namespace to enforce the uniqueness
      */
-    public String getServiceName();
+    public String getRegistrationName();
 
-    /**
-     *
-     * @return additional service info that can be interpreted by the OSGIServiceRegistration system
-     */
-    public String getServiceInfo();
-
-    /**
-     *
-     * @return the type of the service being registered
-     */
-    public String getServiceType();
 }
diff --git a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java
index 200be59..f2d0687 100644
--- a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java
+++ b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java
@@ -28,11 +28,6 @@ import com.ning.billing.util.callcontext.TenantContext;
 public interface PaymentPluginApi {
 
     /**
-     * @return plugin name
-     */
-    public String getName();
-
-    /**
      * Charge a specific amount in the Gateway. Required.
      *
      * @param kbAccountId        killbill accountId

osgi/pom.xml 6(+6 -0)

diff --git a/osgi/pom.xml b/osgi/pom.xml
index f626d05..b2d9bef 100644
--- a/osgi/pom.xml
+++ b/osgi/pom.xml
@@ -78,6 +78,12 @@
         </dependency>
         <!-- TEST SCOPE -->
         <dependency>
+            <groupId>com.ning.billing</groupId>
+            <artifactId>killbill-util </artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>
diff --git a/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIServiceDescriptor.java b/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIServiceDescriptor.java
index dcbcd4d..4701296 100644
--- a/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIServiceDescriptor.java
+++ b/osgi/src/main/java/com/ning/billing/osgi/DefaultOSGIServiceDescriptor.java
@@ -22,14 +22,10 @@ public class DefaultOSGIServiceDescriptor implements OSGIServiceDescriptor {
 
     private final String pluginSymbolicName;
     private final String serviceName;
-    private final String serviceInfo;
-    private final String serviceType;
 
-    public DefaultOSGIServiceDescriptor(final String pluginSymbolicName, final String serviceName, final String serviceInfo, final String serviceType) {
+    public DefaultOSGIServiceDescriptor(final String pluginSymbolicName, final String serviceName) {
         this.pluginSymbolicName = pluginSymbolicName;
         this.serviceName = serviceName;
-        this.serviceInfo = serviceInfo;
-        this.serviceType = serviceType;
     }
 
     @Override
@@ -38,17 +34,7 @@ public class DefaultOSGIServiceDescriptor implements OSGIServiceDescriptor {
     }
 
     @Override
-    public String getServiceName() {
+    public String getRegistrationName() {
         return serviceName;
     }
-
-    @Override
-    public String getServiceInfo() {
-        return serviceInfo;
-    }
-
-    @Override
-    public String getServiceType() {
-        return serviceType;
-    }
 }
diff --git a/osgi/src/main/java/com/ning/billing/osgi/http/DefaultServletRouter.java b/osgi/src/main/java/com/ning/billing/osgi/http/DefaultServletRouter.java
index 68487f5..281373b 100644
--- a/osgi/src/main/java/com/ning/billing/osgi/http/DefaultServletRouter.java
+++ b/osgi/src/main/java/com/ning/billing/osgi/http/DefaultServletRouter.java
@@ -44,7 +44,7 @@ public class DefaultServletRouter implements OSGIServiceRegistration<Servlet> {
         // Enforce each route to start with /
         final String pathPrefix = getPathPrefixFromDescriptor(desc);
         if (pathPrefix == null) {
-            logger.warn("Skipping registration of OSGI servlet for service {} (service info is not specified)", desc.getServiceName());
+            logger.warn("Skipping registration of OSGI servlet for service {} (service info is not specified)", desc.getRegistrationName());
             return;
         }
 
@@ -65,7 +65,7 @@ public class DefaultServletRouter implements OSGIServiceRegistration<Servlet> {
     }
 
     private void registerServiceInternal(final OSGIServiceDescriptor desc) {
-        pluginRegistrations.put(desc.getServiceName(), desc);
+        pluginRegistrations.put(desc.getRegistrationName(), desc);
     }
 
     @Override
@@ -75,11 +75,11 @@ public class DefaultServletRouter implements OSGIServiceRegistration<Servlet> {
             if (desc != null) {
                 final String pathPrefix = getPathPrefixFromDescriptor(desc);
                 if (pathPrefix == null) {
-                    logger.warn("Skipping unregistration of OSGI servlet for service {} (service info is not specified)", desc.getServiceName());
+                    logger.warn("Skipping unregistration of OSGI servlet for service {} (service info is not specified)", desc.getRegistrationName());
                     return;
                 }
 
-                logger.info("Unregistering OSGI servlet " + desc.getServiceName() + " at path " + pathPrefix);
+                logger.info("Unregistering OSGI servlet " + desc.getRegistrationName() + " at path " + pathPrefix);
                 synchronized (this) {
                     unRegisterServletInternal(pathPrefix);
                     unRegisterServiceInternal(desc);
@@ -98,7 +98,7 @@ public class DefaultServletRouter implements OSGIServiceRegistration<Servlet> {
     }
 
     private OSGIServiceDescriptor unRegisterServiceInternal(final OSGIServiceDescriptor desc) {
-        return pluginRegistrations.remove(desc.getServiceName());
+        return pluginRegistrations.remove(desc.getRegistrationName());
     }
 
     @Override
@@ -112,7 +112,7 @@ public class DefaultServletRouter implements OSGIServiceRegistration<Servlet> {
     }
 
     private String getPathPrefixFromDescriptor(final OSGIServiceDescriptor desc) {
-        return sanitizePathPrefix(desc.getServiceInfo());
+        return sanitizePathPrefix(desc.getRegistrationName());
     }
 
     public Servlet getServiceForPath(final String path) {
diff --git a/osgi/src/main/java/com/ning/billing/osgi/KillbillActivator.java b/osgi/src/main/java/com/ning/billing/osgi/KillbillActivator.java
index c2b038c..ed3e179 100644
--- a/osgi/src/main/java/com/ning/billing/osgi/KillbillActivator.java
+++ b/osgi/src/main/java/com/ning/billing/osgi/KillbillActivator.java
@@ -16,15 +16,12 @@
 
 package com.ning.billing.osgi;
 
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Observable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -52,7 +49,9 @@ import com.google.common.collect.ImmutableList;
 
 public class KillbillActivator implements BundleActivator, ServiceListener {
 
-    // TODO : Is that ok for system bundle to use Killbill Logger or do we need to LoggerService like we do for any other bundle
+    final static int PLUGIN_NAME_MAX_LENGTH = 40;
+    final static Pattern PLUGIN_NAME_PATTERN = Pattern.compile("\\p{Lower}(?:\\p{Lower}|\\d|-|_)*");
+
     private final static Logger logger = LoggerFactory.getLogger(KillbillActivator.class);
 
     private final OSGIKillbill osgiKillbill;
@@ -124,7 +123,7 @@ public class KillbillActivator implements BundleActivator, ServiceListener {
     private <T> boolean listenForServiceType(final ServiceReference serviceReference, final int eventType, final Class<T> claz, final OSGIServiceRegistration<T> registration) {
         // Make sure we can retrieve the plugin name
         final String serviceName = (String) serviceReference.getProperty(OSGIPluginProperties.PLUGIN_NAME_PROP);
-        if (serviceName == null) {
+        if (serviceName == null || !checkSanityPluginRegistrationName(serviceName)) {
             // Quite common for non Killbill bundles
             logger.debug("Ignoring registered OSGI service {} with no {} property", claz.getName(), OSGIPluginProperties.PLUGIN_NAME_PROP);
             return true;
@@ -137,19 +136,32 @@ public class KillbillActivator implements BundleActivator, ServiceListener {
         }
         final T theService = (T) theServiceObject;
 
-        final String serviceInfo = (String) serviceReference.getProperty(OSGIPluginProperties.PLUGIN_SERVICE_INFO);
-        final OSGIServiceDescriptor desc = new DefaultOSGIServiceDescriptor(serviceReference.getBundle().getSymbolicName(), serviceName, serviceInfo, claz.getName());
+        final OSGIServiceDescriptor desc = new DefaultOSGIServiceDescriptor(serviceReference.getBundle().getSymbolicName(), serviceName);
         switch (eventType) {
             case ServiceEvent.REGISTERED:
                 final T wrappedService = ContextClassLoaderHelper.getWrappedServiceWithCorrectContextClassLoader(theService);
                 registration.registerService(desc, wrappedService);
                 break;
             case ServiceEvent.UNREGISTERING:
-                registration.unregisterService(desc.getServiceName());
+                registration.unregisterService(desc.getRegistrationName());
                 break;
             default:
                 break;
         }
         return true;
     }
+
+
+    private final boolean checkSanityPluginRegistrationName(final String pluginName) {
+        final Matcher m = PLUGIN_NAME_PATTERN.matcher(pluginName);
+        if (!m.matches()) {
+            logger.warn("Invalid plugin name {} : should be of the form {}", pluginName, PLUGIN_NAME_PATTERN.toString());
+            return false;
+        }
+        if (pluginName.length() > PLUGIN_NAME_MAX_LENGTH) {
+            logger.warn("Invalid plugin name {} : too long, should be less than {}", pluginName, PLUGIN_NAME_MAX_LENGTH);
+            return false;
+        }
+        return true;
+    }
 }
diff --git a/osgi/src/test/java/com/ning/billing/osgi/KillbillActivatorTest.java b/osgi/src/test/java/com/ning/billing/osgi/KillbillActivatorTest.java
new file mode 100644
index 0000000..0c9971f
--- /dev/null
+++ b/osgi/src/test/java/com/ning/billing/osgi/KillbillActivatorTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning 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 com.ning.billing.osgi;
+
+import java.util.regex.Matcher;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.ning.billing.GuicyKillbillTestSuiteNoDB;
+
+public class KillbillActivatorTest extends GuicyKillbillTestSuiteNoDB {
+
+    @Test(groups= "fast")
+    public void testPluginNamePatternGood() {
+        Matcher m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("a");
+        Assert.assertTrue(m.matches());
+
+        m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("abc1223");
+        Assert.assertTrue(m.matches());
+
+        m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("abc123-");
+        Assert.assertTrue(m.matches());
+
+        m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("abc123-zs");
+        Assert.assertTrue(m.matches());
+
+        m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("xyz_1");
+        Assert.assertTrue(m.matches());
+    }
+
+
+    @Test(groups= "fast")
+    public void testPluginNamePatternBad() {
+        Matcher m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("1abd");
+        Assert.assertFalse(m.matches());
+
+        m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("Tata");
+        Assert.assertFalse(m.matches());
+
+
+        m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("Tata#");
+        Assert.assertFalse(m.matches());
+
+        m = KillbillActivator.PLUGIN_NAME_PATTERN.matcher("yo:");
+        Assert.assertFalse(m.matches());
+    }
+
+    @Test(groups = "false")
+    public void testPluginNameLength() {
+
+        String pluginNameGood = "foofofoSuperFoo";
+        Assert.assertTrue(pluginNameGood.length() < KillbillActivator.PLUGIN_NAME_MAX_LENGTH);
+
+        String pluginNameBAd = "foofoofooSuperFoosupersuperLongreallyLong";
+        Assert.assertFalse(pluginNameBAd.length() < KillbillActivator.PLUGIN_NAME_MAX_LENGTH);
+    }
+}
diff --git a/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java b/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java
index c4383ce..ddd411e 100644
--- a/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java
+++ b/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java
@@ -68,11 +68,6 @@ public class JRubyPaymentPlugin extends JRubyPlugin implements PaymentPluginApi 
         super.stopPlugin(context);
     }
 
-    @Override
-    public String getName() {
-        return pluginMainClass;
-    }
-
 
     @Override
     public PaymentInfoPlugin processPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency,  final CallContext context) throws PaymentPluginApiException {
diff --git a/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java b/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
index 90ad690..ee22e5a 100644
--- a/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
+++ b/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
@@ -44,11 +44,6 @@ public class TestPaymentPluginApi implements PaymentPluginApi {
     }
 
     @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
     public PaymentInfoPlugin processPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final CallContext context) throws PaymentPluginApiException {
         testDao.insertProcessedPayment(kbPaymentId, kbPaymentMethodId, amount);
         return new PaymentInfoPlugin() {
diff --git a/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
index 129e1c5..82acb4b 100644
--- a/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
+++ b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
@@ -45,11 +45,6 @@ public class TestPaymentPluginApi implements PaymentPluginApiWithTestControl {
     }
 
     @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
     public PaymentInfoPlugin processPayment(final UUID accountId, final UUID kbPaymentId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final CallContext context) throws PaymentPluginApiException {
         return withRuntimeCheckForExceptions(new PaymentInfoPlugin() {
             @Override
diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java
index d3efe4b..21b2144 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java
@@ -90,10 +90,10 @@ public class PaymentMethodProcessor extends ProcessorBase {
                 PaymentPluginApi pluginApi = null;
                 try {
                     pluginApi = pluginRegistry.getServiceForName(paymentPluginServiceName);
-                    // TODO PIERRE Should we really use the plugin instance name here?
-                    // We default to the plugin name when paymentPluginServiceName is null (i.e. for the default plugin name)
-                    final String pluginName = Objects.firstNonNull(paymentPluginServiceName, pluginApi.getName());
-                    pm = new DefaultPaymentMethod(account.getId(), pluginName, paymentMethodProps);
+                    if (pluginApi == null) {
+                        throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_PAYMENT_PLUGIN, paymentPluginServiceName);
+                    }
+                    pm = new DefaultPaymentMethod(account.getId(), paymentPluginServiceName, paymentMethodProps);
                     pluginApi.addPaymentMethod(account.getId(), pm.getId(), paymentMethodProps, setDefault, context.toCallContext());
                     final PaymentMethodModelDao pmModel = new PaymentMethodModelDao(pm.getId(), pm.getCreatedDate(), pm.getUpdatedDate(),
                                                                                     pm.getAccountId(), pm.getPluginName(), pm.isActive());
diff --git a/payment/src/main/java/com/ning/billing/payment/glue/DefaultPaymentProviderPluginRegistryProvider.java b/payment/src/main/java/com/ning/billing/payment/glue/DefaultPaymentProviderPluginRegistryProvider.java
index ed47264..8ba4dcc 100644
--- a/payment/src/main/java/com/ning/billing/payment/glue/DefaultPaymentProviderPluginRegistryProvider.java
+++ b/payment/src/main/java/com/ning/billing/payment/glue/DefaultPaymentProviderPluginRegistryProvider.java
@@ -48,17 +48,9 @@ public class DefaultPaymentProviderPluginRegistryProvider implements Provider<OS
                 return null;
             }
             @Override
-            public String getServiceName() {
+            public String getRegistrationName() {
                 return ExternalPaymentProviderPlugin.PLUGIN_NAME;
             }
-            @Override
-            public String getServiceInfo() {
-                return null;
-            }
-            @Override
-            public String getServiceType() {
-                return null;
-            }
         };
         pluginRegistry.registerService(desc, externalPaymentProviderPlugin);
 
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java b/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java
index 670a81d..bc046b0 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java
@@ -85,11 +85,6 @@ public class DefaultNoOpPaymentProviderPlugin implements NoOpPaymentPluginApi {
     }
 
     @Override
-    public String getName() {
-        return PLUGIN_NAME;
-    }
-
-    @Override
     public PaymentInfoPlugin processPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final CallContext context) throws PaymentPluginApiException {
         if (makeNextInvoiceFailWithException.getAndSet(false)) {
             throw new PaymentPluginApiException("", "test error");
@@ -166,7 +161,7 @@ public class DefaultNoOpPaymentProviderPlugin implements NoOpPaymentPluginApi {
     public RefundInfoPlugin processRefund(final UUID kbAccountId, final UUID kbPaymentId, final BigDecimal refundAmount, final Currency currency, final CallContext context) throws PaymentPluginApiException {
         final PaymentInfoPlugin paymentInfoPlugin = getPaymentInfo(kbAccountId, kbPaymentId, context);
         if (paymentInfoPlugin == null) {
-            throw new PaymentPluginApiException("", String.format("No payment found for payment id %s (plugin %s)", kbPaymentId.toString(), getName()));
+            throw new PaymentPluginApiException("", String.format("No payment found for payment id %s (plugin %s)", kbPaymentId.toString(), PLUGIN_NAME));
         }
 
         BigDecimal maxAmountRefundable = paymentInfoPlugin.getAmount();
@@ -175,7 +170,7 @@ public class DefaultNoOpPaymentProviderPlugin implements NoOpPaymentPluginApi {
         }
         if (maxAmountRefundable.compareTo(refundAmount) < 0) {
             throw new PaymentPluginApiException("", String.format("Refund amount of %s for payment id %s is bigger than the payment amount %s (plugin %s)",
-                                                                  refundAmount, kbPaymentId.toString(), paymentInfoPlugin.getAmount(), getName()));
+                                                                  refundAmount, kbPaymentId.toString(), paymentInfoPlugin.getAmount(), PLUGIN_NAME));
         }
 
         final DefaultNoOpRefundInfoPlugin refundInfoPlugin = new DefaultNoOpRefundInfoPlugin(refundAmount, clock.getUTCNow(), clock.getUTCNow(), RefundPluginStatus.PROCESSED, null);
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/DefaultPaymentProviderPluginRegistry.java b/payment/src/main/java/com/ning/billing/payment/provider/DefaultPaymentProviderPluginRegistry.java
index 492df8b..41b5f78 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/DefaultPaymentProviderPluginRegistry.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/DefaultPaymentProviderPluginRegistry.java
@@ -28,7 +28,6 @@ import com.ning.billing.osgi.api.OSGIServiceRegistration;
 import com.ning.billing.payment.plugin.api.PaymentPluginApi;
 import com.ning.billing.util.config.PaymentConfig;
 
-import com.google.common.base.Strings;
 import com.google.inject.Inject;
 
 public class DefaultPaymentProviderPluginRegistry implements OSGIServiceRegistration<PaymentPluginApi> {
@@ -46,24 +45,22 @@ public class DefaultPaymentProviderPluginRegistry implements OSGIServiceRegistra
 
     @Override
     public void registerService(final OSGIServiceDescriptor desc, final PaymentPluginApi service) {
-        log.info("DefaultPaymentProviderPluginRegistry registering service " + desc.getServiceName().toLowerCase());
-        pluginsByName.put(desc.getServiceName().toLowerCase(), service);
+        log.info("DefaultPaymentProviderPluginRegistry registering service " + desc.getRegistrationName());
+        pluginsByName.put(desc.getRegistrationName(), service);
     }
 
     @Override
     public void unregisterService(final String serviceName) {
-        log.info("DefaultPaymentProviderPluginRegistry unregistering service " + serviceName.toLowerCase());
-        pluginsByName.remove(serviceName.toLowerCase());
+        log.info("DefaultPaymentProviderPluginRegistry unregistering service " + serviceName);
+        pluginsByName.remove(serviceName);
     }
 
     @Override
     public PaymentPluginApi getServiceForName(final String name) {
-        final PaymentPluginApi plugin = pluginsByName.get((Strings.emptyToNull(name) == null ? defaultPlugin : name).toLowerCase());
-
-        if (plugin == null) {
-            throw new IllegalArgumentException("No payment provider plugin is configured for " + name);
+        if (name == null) {
+            throw new IllegalArgumentException("Null payment plugin APi name");
         }
-
+        final PaymentPluginApi plugin = pluginsByName.get(name);
         return plugin;
     }
 
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java b/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java
index ac621ba..106499a 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java
@@ -35,10 +35,4 @@ public class ExternalPaymentProviderPlugin extends DefaultNoOpPaymentProviderPlu
     public ExternalPaymentProviderPlugin(final Clock clock) {
         super(clock);
     }
-
-    @Override
-    public String getName() {
-        return PLUGIN_NAME;
-    }
-
 }
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPluginProvider.java b/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPluginProvider.java
index 2a9cf4c..e669b92 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPluginProvider.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPluginProvider.java
@@ -52,17 +52,9 @@ public class NoOpPaymentProviderPluginProvider implements Provider<DefaultNoOpPa
                 return null;
             }
             @Override
-            public String getServiceName() {
+            public String getRegistrationName() {
                 return instanceName;
             }
-            @Override
-            public String getServiceInfo() {
-                return null;
-            }
-            @Override
-            public String getServiceType() {
-                return null;
-            }
         };
         registry.registerService(desc, plugin);
         return plugin;
diff --git a/payment/src/test/java/com/ning/billing/payment/core/TestPaymentMethodProcessorNoDB.java b/payment/src/test/java/com/ning/billing/payment/core/TestPaymentMethodProcessorNoDB.java
index 4f3048d..50113fc 100644
--- a/payment/src/test/java/com/ning/billing/payment/core/TestPaymentMethodProcessorNoDB.java
+++ b/payment/src/test/java/com/ning/billing/payment/core/TestPaymentMethodProcessorNoDB.java
@@ -41,7 +41,6 @@ public class TestPaymentMethodProcessorNoDB extends PaymentTestSuiteNoDB {
 
         // The first call should create the payment method
         final ExternalPaymentProviderPlugin providerPlugin = paymentMethodProcessor.getExternalPaymentProviderPlugin(account, internalCallContext);
-        Assert.assertEquals(providerPlugin.getName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
         final List<PaymentMethod> paymentMethods = paymentMethodProcessor.getPaymentMethods(account, false, internalCallContext);
         Assert.assertEquals(paymentMethods.size(), 1);
         Assert.assertEquals(paymentMethods.get(0).getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
@@ -51,7 +50,7 @@ public class TestPaymentMethodProcessorNoDB extends PaymentTestSuiteNoDB {
         final UUID externalPaymentMethodId = paymentMethods.get(0).getId();
         for (int i = 0; i < 50; i++) {
             final ExternalPaymentProviderPlugin foundProviderPlugin = paymentMethodProcessor.getExternalPaymentProviderPlugin(account, internalCallContext);
-            Assert.assertEquals(foundProviderPlugin.getName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
+            Assert.assertNotNull (foundProviderPlugin);
 
             final List<PaymentMethod> foundPaymentMethods = paymentMethodProcessor.getPaymentMethods(account, false, internalCallContext);
             Assert.assertEquals(foundPaymentMethods.size(), 1);
diff --git a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
index cb49626..33497c4 100644
--- a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
+++ b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
@@ -91,11 +91,6 @@ public class MockPaymentProviderPlugin implements NoOpPaymentPluginApi {
     }
 
     @Override
-    public String getName() {
-        return PLUGIN_NAME;
-    }
-
-    @Override
     public PaymentInfoPlugin processPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final CallContext context) throws PaymentPluginApiException {
         if (makeNextInvoiceFailWithException.getAndSet(false)) {
             throw new PaymentPluginApiException("", "test error");
@@ -161,7 +156,7 @@ public class MockPaymentProviderPlugin implements NoOpPaymentPluginApi {
     public RefundInfoPlugin processRefund(final UUID kbAccountId, final UUID kbPaymentId, final BigDecimal refundAmount, final Currency currency, final CallContext context) throws PaymentPluginApiException {
         final PaymentInfoPlugin paymentInfoPlugin = getPaymentInfo(kbAccountId, kbPaymentId, context);
         if (paymentInfoPlugin == null) {
-            throw new PaymentPluginApiException("", String.format("No payment found for payment id %s (plugin %s)", kbPaymentId.toString(), getName()));
+            throw new PaymentPluginApiException("", String.format("No payment found for payment id %s (plugin %s)", kbPaymentId.toString(), PLUGIN_NAME));
         }
 
         BigDecimal maxAmountRefundable = paymentInfoPlugin.getAmount();
@@ -170,7 +165,7 @@ public class MockPaymentProviderPlugin implements NoOpPaymentPluginApi {
         }
         if (maxAmountRefundable.compareTo(refundAmount) < 0) {
             throw new PaymentPluginApiException("", String.format("Refund amount of %s for payment id %s is bigger than the payment amount %s (plugin %s)",
-                                                                  refundAmount, kbPaymentId.toString(), paymentInfoPlugin.getAmount(), getName()));
+                                                                  refundAmount, kbPaymentId.toString(), paymentInfoPlugin.getAmount(), PLUGIN_NAME));
         }
 
         final DefaultNoOpRefundInfoPlugin refundInfoPlugin = new DefaultNoOpRefundInfoPlugin(refundAmount, clock.getUTCNow(), clock.getUTCNow(), RefundPluginStatus.PROCESSED, null);
diff --git a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPluginProvider.java b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPluginProvider.java
index 0c4f4ac..dbd92bf 100644
--- a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPluginProvider.java
+++ b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPluginProvider.java
@@ -51,17 +51,9 @@ public class MockPaymentProviderPluginProvider implements Provider<MockPaymentPr
                 return null;
             }
             @Override
-            public String getServiceName() {
+            public String getRegistrationName() {
                 return instanceName;
             }
-            @Override
-            public String getServiceInfo() {
-                return null;
-            }
-            @Override
-            public String getServiceType() {
-                return null;
-            }
         };
         registry.registerService(desc, plugin);
         return plugin;
diff --git a/payment/src/test/java/com/ning/billing/payment/provider/TestExternalPaymentProviderPlugin.java b/payment/src/test/java/com/ning/billing/payment/provider/TestExternalPaymentProviderPlugin.java
index d5e3c6b..71929c7 100644
--- a/payment/src/test/java/com/ning/billing/payment/provider/TestExternalPaymentProviderPlugin.java
+++ b/payment/src/test/java/com/ning/billing/payment/provider/TestExternalPaymentProviderPlugin.java
@@ -46,10 +46,6 @@ public class TestExternalPaymentProviderPlugin extends PaymentTestSuiteNoDB {
         plugin = new ExternalPaymentProviderPlugin(clock);
     }
 
-    @Test(groups = "fast")
-    public void testGetName() throws Exception {
-        Assert.assertEquals(plugin.getName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
-    }
 
     @Test(groups = "fast")
     public void testProcessPayment() throws Exception {