Commits

Ben Woskow committed f43151d

forgot to commit additional modifications

  • Participants
  • Parent commits 71bea2a

Comments (0)

Files changed (4)

File src/main/java/com/example/plugins/tutorial/servlet/HelloWorldServlet.java

         
         try
         {
-            //Check and see if a license is currently stored
+            //Check and see if a license is currently stored.
+            //This accessor method can be used whether or not a licensing-aware UPM is present.
             if (licenseManager.getLicense().isDefined())
             {
                 for (PluginLicense pluginLicense : licenseManager.getLicense())

File src/main/java/com/example/plugins/tutorial/servlet/LicenseServlet.java

 import com.atlassian.sal.api.ApplicationProperties;
 import com.atlassian.upm.api.license.entity.PluginLicense;
 import com.atlassian.upm.api.util.Option;
+import com.atlassian.upm.license.storage.lib.PluginLicenseStoragePluginUnresolvedException;
 import com.atlassian.upm.license.storage.lib.ThirdPartyPluginLicenseStorageManager;
 
 import org.apache.commons.lang.StringUtils;
 
 public class LicenseServlet extends HttpServlet
 {
-    private final ThirdPartyPluginLicenseStorageManager thirdPartyPluginLicenseStorageManager;
+    private final ThirdPartyPluginLicenseStorageManager licenseManager;
     private final ApplicationProperties applicationProperties;
 
-    public LicenseServlet(ThirdPartyPluginLicenseStorageManager thirdPartyPluginLicenseStorageManager,
-                          ApplicationProperties applicationProperties)
+    public LicenseServlet(ThirdPartyPluginLicenseStorageManager licenseManager, ApplicationProperties applicationProperties)
     {
-        this.thirdPartyPluginLicenseStorageManager = thirdPartyPluginLicenseStorageManager;
+        this.licenseManager = licenseManager;
         this.applicationProperties = applicationProperties;
     }
 
         resp.setContentType("text/html");
         resp.getWriter().write("<html><body><b>");
 
-        if (!thirdPartyPluginLicenseStorageManager.isUpmLicensingAware())
+        try
         {
-            String license = req.getParameter("license");
-            if (!StringUtils.isEmpty(license))
+            if (!licenseManager.isUpmLicensingAware())
             {
-                //we have a non-empty license parameter - let's update the license if it is valid.
-                Option<PluginLicense> validatedLicense = thirdPartyPluginLicenseStorageManager.validateLicense(license);
-                if (validatedLicense.isDefined())
+                String license = req.getParameter("license");
+                if (!StringUtils.isEmpty(license))
                 {
-                    thirdPartyPluginLicenseStorageManager.setRawLicense(license);
-                    resp.getWriter().write("Valid license. License has been updated.");
+                    //we have a non-empty license parameter - let's update the license if it is valid.
+                    Option<PluginLicense> validatedLicense = licenseManager.validateLicense(license);
+                    if (validatedLicense.isDefined())
+                    {
+                        licenseManager.setRawLicense(license);
+                        resp.getWriter().write("Valid license. License has been updated.");
+                    }
+                    else
+                    {
+                        resp.getWriter().write("Invalid license. License has not been updated.");
+                    }
                 }
                 else
                 {
-                    resp.getWriter().write("Invalid license. License has not been updated.");
+                    //we have an empty/null license parameter - let's remove the stored license
+                    licenseManager.removeRawLicense();
+                    resp.getWriter().write("License has been removed.");
                 }
             }
             else
             {
-                //we have an empty/null license parameter - let's remove the stored license
-                thirdPartyPluginLicenseStorageManager.removeRawLicense();
-                resp.getWriter().write("License has been removed.");
+                //don't allow POSTs to occur to our license servlet if UPM is licensing-aware
+                resp.getWriter().write("Nice try! You cannot update your plugin license with this API when UPM is licensing-aware.");
             }
         }
-        else
+        catch (PluginLicenseStoragePluginUnresolvedException e)
         {
-            //don't allow POSTs to occur to our license servlet if UPM is licensing-aware
-            resp.getWriter().write("Nice try! You cannot update your plugin license with this API when UPM is licensing-aware.");
+            resp.getWriter().write("<br>Sorry, but we cannot find the required licensing support to execute the requested operation. "
+                    + "Please ensure that the Plugin License Storage plugin is installed and enabled. Restarting this plugin " +
+                    		"should resolve the problem.");
         }
 
         resp.getWriter().write("</b>");
 
     private void outputBody(HttpServletResponse resp) throws ServletException, IOException
     {
-        resp.getWriter().write("<br><br>UPM is licensing-aware: " + thirdPartyPluginLicenseStorageManager.isUpmLicensingAware());
-        resp.getWriter().write("<br>Plugin key: " + thirdPartyPluginLicenseStorageManager.getPluginKey());
-
-        if (!thirdPartyPluginLicenseStorageManager.isUpmLicensingAware())
+        try
         {
-            resp.getWriter().write("<br><br>Update your license");
-            resp.getWriter().write("<br><form action=\"" + applicationProperties.getBaseUrl() + "/plugins/servlet/licenseservlet\" method=\"POST\">");
-            resp.getWriter().write("<textarea name=\"license\" cols=\"80\" rows=\"10\">");
-            for (String storedRawLicense : thirdPartyPluginLicenseStorageManager.getRawLicense())
+            resp.getWriter().write("<br><br>UPM is licensing-aware: " + licenseManager.isUpmLicensingAware());
+            resp.getWriter().write("<br>Plugin key: " + licenseManager.getPluginKey());
+    
+            if (!licenseManager.isUpmLicensingAware())
+            {
+                resp.getWriter().write("<br><br>Update your license");
+                resp.getWriter().write("<br><form action=\"" + applicationProperties.getBaseUrl() + "/plugins/servlet/licenseservlet\" method=\"POST\">");
+                resp.getWriter().write("<textarea name=\"license\" cols=\"80\" rows=\"10\">");
+                for (String storedRawLicense : licenseManager.getRawLicense())
+                {
+                    //enter the stored license into the textarea, if the license has been stored
+                    resp.getWriter().write(storedRawLicense);
+                }
+                resp.getWriter().write("</textarea>");
+                resp.getWriter().write("<br><input type=\"submit\" value=\"Save\" />");
+                resp.getWriter().write("</form>");
+            }
+            else
             {
-                //enter the stored license into the textarea, if the license has been stored
-                resp.getWriter().write(storedRawLicense);
+                resp.getWriter().write("<br>Cannot modify plugin licenses with this API when UPM is licensing-aware. Please use ");
+                resp.getWriter().write("<a href=\"" + licenseManager.getPluginManagementUri() + "\">UPM's licensing UI</a>.");
             }
-            resp.getWriter().write("</textarea>");
-            resp.getWriter().write("<br><input type=\"submit\" value=\"Save\" />");
-            resp.getWriter().write("</form>");
         }
-        else
+        catch (PluginLicenseStoragePluginUnresolvedException e)
         {
-            resp.getWriter().write("<br>Cannot modify plugin licenses with this API when UPM is licensing-aware. Please use ");
-            resp.getWriter().write("<a href=\"" + thirdPartyPluginLicenseStorageManager.getPluginManagementUri() + "\">UPM's licensing UI</a>.");
+            resp.getWriter().write("<br>Sorry, but we cannot find the required licensing support to execute the requested operation. "
+                    + "Please ensure that the Plugin License Storage plugin is installed and enabled. Restarting this plugin " +
+                            "should resolve the problem.");
         }
     }
 }

File src/main/resources/atlassian-plugin.properties

 #Wed Jan 18 14:37:39 PST 2012
 license-servlet.name=License Servlet
 license-servlet.description=The License Servlet Plugin
+hello-world-servlet.description=The Hello World Servlet Plugin
+hello-world-servlet.name=Hello World Servlet

File src/main/resources/atlassian-plugin.xml

     <description key="license-servlet.description">The License Servlet Plugin</description>
     <url-pattern>/licenseservlet</url-pattern>
   </servlet>
+  
+  <servlet name="Hello World Servlet" i18n-name-key="hello-world-servlet.name" key="hello-world-servlet" class="com.example.plugins.tutorial.servlet.HelloWorldServlet">
+    <description key="hello-world-servlet.description">The Hello World Servlet Plugin</description>
+    <url-pattern>/helloworldservlet</url-pattern>
+  </servlet>
 
   <resource type="i18n" name="i18n" location="atlassian-plugin"/>