Commits

Don Brown committed 8423565

Initial commit

Comments (0)

Files changed (8)

+*.iml
+*.ipr
+*.iws
+.idea
+target
+Standalone "universal binary" Atlassian Remote App plugin
+
+This is a "unversal binary" remote app that demonstrates a single artifact that can be deployed
+standalone outside an Atlassian application on a hosting service such as Heroku, or for behind-the-firewall
+instances, install as a plugin.
+
+To get started, build the app:
+  mvn package
+  
+To install the app, upload the plugin to a target instance such as https://remoteapps.jira.com
+
+Instructions on running standalone to come...
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.atlassian.labs</groupId>
+    <artifactId>helloworldpage-app-plugin</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>Hello World Page App Plugin</name>
+    <packaging>atlassian-plugin</packaging>
+    <description>
+        A sample remote app plugin (universal binary) that shows a hello world general page.
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.atlassian.labs</groupId>
+            <artifactId>remoteapps-servlet-kit</artifactId>
+            <version>0.4.99-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.samskivert</groupId>
+            <artifactId>jmustache</artifactId>
+            <version>1.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>org.springframework.context</artifactId>
+            <version>2.5.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.6</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-amps-plugin</artifactId>
+                <version>3.9</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <productVersion>2.15.0</productVersion>
+                    <extractDependencies>true</extractDependencies>
+                    <pluginArtifacts>
+                        <pluginArtifact>
+                            <groupId>com.atlassian.labs</groupId>
+                            <artifactId>remoteapps-plugin</artifactId>
+                            <version>0.4.99-SNAPSHOT</version>
+                        </pluginArtifact>
+                    </pluginArtifacts>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

src/main/java/services/Renderer.java

+package services;
+
+import com.samskivert.mustache.Mustache;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.Map;
+
+/**
+ *
+ */
+@Component
+public class Renderer
+{
+    public void renderHtml(HttpServletResponse resp, String template, Map<String, Object> context) throws IOException
+    {
+        resp.setContentType("text/html");
+        byte[] bytes = render(template, context).getBytes(Charset.forName("UTF-8"));
+        resp.setContentLength(bytes.length);
+        resp.getOutputStream().write(bytes);
+        resp.getOutputStream().close();
+    }
+
+    public static String render(String template, Map<String,Object> context)
+    {
+        StringWriter writer = new StringWriter();
+        InputStream resourceAsStream = null;
+        try
+        {
+            resourceAsStream = Renderer.class.getClassLoader().getResourceAsStream("templates/" + template);
+            Mustache.compiler().compile(
+                new InputStreamReader(resourceAsStream)).execute(context,
+                writer);
+        }
+        finally
+        {
+            try
+            {
+                resourceAsStream.close();
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+        return writer.toString();
+    }
+}

src/main/java/servlets/HelloWorldServlet.java

+package servlets;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import services.Renderer;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Date;
+
+/**
+ *
+ */
+@Component
+public class HelloWorldServlet extends HttpServlet
+{
+    private final Renderer renderer;
+
+    @Autowired
+    public HelloWorldServlet(Renderer renderer)
+    {
+        this.renderer = renderer;
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+    {
+        renderer.renderHtml(resp, "hello-world.html.mu",
+                Collections.<String, Object>singletonMap("date", new Date().toString()));
+
+    }
+}

src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="helloworldpage-app-plugin" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <version>${project.version}</version>
+    </plugin-info>
+</atlassian-plugin>

src/main/resources/atlassian-remote-app.xml

+<remote-app key="helloworldpage-app-plugin" name="Hello World Page App Plugin" version="1" icon-url="https://atlassian.com/favicon.ico"
+            display-url="-- to be replaced --">
+    <vendor name="Atlassian" url="http://atlassian.com" />
+    <description>
+        Demonstrates a "universal binary" app plugin
+    </description>
+
+    <general-page key="helloWorld" name="Hello World" url="/helloWorld"/>
+</remote-app>

src/main/resources/templates/hello-world.html.mu

+<html>
+    <head>
+        <script src="https://remoteapps.jira.com/remoteapps/all.js" type="text/javascript"></script>
+    </head>
+    <body>
+        <h2>Hello World at {{date}}</h2>
+        <script type="text/javascript">
+            RA.init();
+        </script>
+    </body>
+</html>