Commits

Anonymous committed 5b4efb4

First commit of tutorial code

Comments (0)

Files changed (5)

Empty file added.

jira-soapclient/pom.xml

+<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>
+    <parent>
+        <groupId>com.atlassian.jira.plugins</groupId>
+        <artifactId>atlassian-jira-rpc-parent</artifactId>
+        <version>4.1-SNAPSHOT</version>
+    </parent>
+
+    <groupId>com.atlassian.jira.plugins</groupId>
+    <artifactId>jira-soapclient</artifactId>
+
+    <name>JIRA SOAP Client</name>
+    <description>A plugin which provides a sample SOAP implementation.</description>
+
+
+
+<repositories>
+      <repository>
+         <id>atlassian</id>
+         <name>Atlassian Repository</name>
+         <url>https://maven.atlassian.com/content/groups/public</url>
+      </repository>
+    </repositories>
+
+
+  <pluginRepositories>
+       <pluginRepository>
+                <id>atlassian</id>
+                <name>Atlassian Repository</name>
+                <url>https://maven.atlassian.com/content/groups/public</url>
+       </pluginRepository>
+   </pluginRepositories>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>axistools-maven-plugin</artifactId>
+                <version>1.3</version>
+                <dependencies>
+                    <dependency>
+                        <groupId>axis</groupId>
+                        <artifactId>axis</artifactId>
+                        <version>1.3</version>
+                    </dependency>
+                </dependencies>
+                <configuration>
+                    <wsdlFiles>
+                        <wsdlFile>jirasoapservice-v2.wsdl</wsdlFile>
+                    </wsdlFiles>
+                    <packageSpace>com.atlassian.jira.rpc.soap.client</packageSpace>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>wsdl2java-generation</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>wsdl2java</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                    <archive>
+                        <manifest>
+                            <addClasspath>true</addClasspath>
+                            <mainClass>com.atlassian.jira_soapclient.SOAPClient</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>buildclient</id>
+            <build>
+                <defaultGoal>assembly:assembly</defaultGoal>
+            </build>
+        </profile>
+        <profile>
+            <id>fetch-wsdl</id>
+            <build>
+                <defaultGoal>generate-sources</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-antrun-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>generate-sources</phase>
+                                <goals>
+                                    <goal>run</goal>
+                                </goals>
+                                <configuration>
+                                    <tasks>
+                                        <get src="${jira.soapclient.jiraurl}/rpc/soap/jirasoapservice-v2?wsdl"
+                                             dest="${basedir}/src/main/wsdl/jirasoapservice-v2.wsdl"/>
+                                    </tasks>
+                                </configuration>
+                            </execution>
+                        </executions>
+                        <dependencies>
+                            <dependency>
+                                <groupId>axis</groupId>
+                                <artifactId>axis-ant</artifactId>
+                                <version>1.3</version>
+                            </dependency>
+                        </dependencies>
+                    </plugin>
+                </plugins>
+            </build>
+            <properties>
+                <jira.soapclient.jiraurl>http://atlas-laptop:2990/jira</jira.soapclient.jiraurl>
+            </properties>
+        </profile>
+    </profiles>
+
+    <dependencies>
+        <dependency>
+            <groupId>axis</groupId>
+            <artifactId>axis</artifactId>
+            <version>1.3</version>
+        </dependency>
+        <dependency>
+            <groupId>axis</groupId>
+            <artifactId>axis-jaxrpc</artifactId>
+            <version>1.3</version>
+        </dependency>
+        <dependency>
+            <groupId>axis</groupId>
+            <artifactId>axis-saaj</artifactId>
+            <version>1.3</version>
+        </dependency>
+        <dependency>
+            <groupId>axis</groupId>
+            <artifactId>axis-wsdl4j</artifactId>
+            <version>1.5.1</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+
+</project>

jira-soapclient/src/main/java/com/atlassian/jira_soapclient/SOAPClient.java

+package com.atlassian.jira_soapclient;
+
+import com.atlassian.jira.rpc.soap.client.RemoteComment;
+import com.atlassian.jira.rpc.soap.client.RemoteComponent;
+import com.atlassian.jira.rpc.soap.client.RemoteCustomFieldValue;
+import com.atlassian.jira.rpc.soap.client.RemoteFilter;
+import com.atlassian.jira.rpc.soap.client.RemoteIssue;
+import com.atlassian.jira.rpc.soap.client.RemoteVersion;
+import com.atlassian.jira.rpc.soap.client.JiraSoapService;
+import com.atlassian.jira.rpc.soap.client.RemoteProject;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.rmi.RemoteException;
+import java.text.DecimalFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+public class SOAPClient
+{
+
+    static final String LOGIN_NAME = "soaptester";
+    static final String LOGIN_PASSWORD = "soaptester";
+    static final String PROJECT_KEY = "TST";
+    static final String ISSUE_TYPE_ID = "1";
+    static final String SUMMARY_NAME = "An issue created via the JIRA SOAPClient sample : " + new Date();
+    static final String PRIORITY_ID = "4";
+    static final String NEW_COMMENT_BODY = "This is a new comment";
+
+    public static void main(String[] args) throws Exception
+    {
+        String baseUrl = "http://atlas-laptop:2990/jira/rpc/soap/jirasoapservice-v2";
+        System.out.println("JIRA SOAP client sample");
+
+        SOAPSession soapSession = new SOAPSession(new URL(baseUrl));
+        soapSession.connect(LOGIN_NAME, LOGIN_PASSWORD);
+
+        JiraSoapService jiraSoapService = soapSession.getJiraSoapService();
+        String authToken = soapSession.getAuthenticationToken();
+
+        RemoteIssue issue = testCreateIssue(jiraSoapService, authToken);
+
+    }
+
+    private static RemoteIssue testCreateIssue(JiraSoapService jiraSoapService, String token)
+            throws java.rmi.RemoteException
+    {
+        System.out.println("CreateIssue");
+
+            RemoteIssue issue = new RemoteIssue();
+            issue.setProject(PROJECT_KEY);
+            issue.setType(ISSUE_TYPE_ID);
+
+            issue.setSummary(SUMMARY_NAME);
+            issue.setPriority(PRIORITY_ID);
+            issue.setDuedate(Calendar.getInstance());
+            issue.setAssignee("");
+
+            // Run the create issue code
+            RemoteIssue returnedIssue = jiraSoapService.createIssue(token, issue);
+            final String issueKey = returnedIssue.getKey();
+
+            System.out.println("\tSuccessfully created issue " + issueKey);
+            printIssueDetails(returnedIssue);
+            return returnedIssue;
+    }
+
+    private static void printIssueDetails(RemoteIssue issue)
+    {
+        System.out.println("Issue Details : ");
+        Method[] declaredMethods = issue.getClass().getDeclaredMethods();
+        for (int i = 0; i < declaredMethods.length; i++)
+        {
+            Method declaredMethod = declaredMethods[i];
+            if (declaredMethod.getName().startsWith("get") && declaredMethod.getParameterTypes().length == 0)
+            {
+                System.out.print("\t Issue." + declaredMethod.getName() + "() -> ");
+                try
+                {
+                    Object obj = declaredMethod.invoke(issue, new Object[] { });
+                    if (obj instanceof Object[])
+                    {
+                        obj = arrayToStr((Object[]) obj);
+                    }
+                    else
+                    {
+                    }
+                    System.out.println(obj);
+                }
+                catch (IllegalAccessException e)
+                {
+                    e.printStackTrace();
+                }
+                catch (InvocationTargetException e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    private static String arrayToStr(Object[] o)
+    {
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < o.length; i++)
+        {
+            sb.append(o[i]).append(" ");
+        }
+        return sb.toString();
+    }
+
+    private static byte[] getBytesFromFile(File file) throws IOException
+    {
+        InputStream is = new FileInputStream(file);
+
+        long length = file.length();
+        if (length < Integer.MAX_VALUE)
+        {
+            byte[] bytes = new byte[(int) length];
+            int offset = 0;
+            int numRead;
+            while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0)
+            {
+                offset += numRead;
+            }
+
+            if (offset < bytes.length)
+            {
+                throw new IOException("Could not completely read file " + file.getName());
+            }
+
+            is.close();
+            return bytes;
+        }
+        else
+        {
+            System.out.println("File is too large");
+            return null;
+        }
+    }
+
+}

jira-soapclient/src/main/java/com/atlassian/jira_soapclient/SOAPSession.java

+package com.atlassian.jira_soapclient;
+
+import com.atlassian.jira.rpc.soap.client.JiraSoapService;
+import com.atlassian.jira.rpc.soap.client.JiraSoapServiceService;
+import com.atlassian.jira.rpc.soap.client.JiraSoapServiceServiceLocator;
+
+import java.net.URL;
+import java.rmi.RemoteException;
+import javax.xml.rpc.ServiceException;
+
+/**
+ * This represents a SOAP session with JIRA including that state of being logged in or not
+ */
+public class SOAPSession
+{
+    private JiraSoapServiceService jiraSoapServiceLocator;
+    private JiraSoapService jiraSoapService;
+    private String token;
+
+    public SOAPSession(URL webServicePort)
+    {
+        jiraSoapServiceLocator = new JiraSoapServiceServiceLocator();
+        try
+        {
+            if (webServicePort == null)
+            {
+                jiraSoapService = jiraSoapServiceLocator.getJirasoapserviceV2();
+            }
+            else
+            {
+                jiraSoapService = jiraSoapServiceLocator.getJirasoapserviceV2(webServicePort);
+                System.out.println("SOAP Session service endpoint at " + webServicePort.toExternalForm());
+            }
+        }
+        catch (ServiceException e)
+        {
+            throw new RuntimeException("ServiceException during SOAPClient contruction", e);
+        }
+    }
+
+    public SOAPSession()
+    {
+        this(null);
+    }
+
+    public void connect(String userName, String password) throws RemoteException
+    {
+        System.out.println("\tConnnecting via SOAP as : " + userName);
+        token = getJiraSoapService().login(userName, password);
+        System.out.println("\tConnected");
+    }
+
+    public String getAuthenticationToken()
+    {
+        return token;
+    }
+
+    public JiraSoapService getJiraSoapService()
+    {
+        return jiraSoapService;
+    }
+
+    public JiraSoapServiceService getJiraSoapServiceLocator()
+    {
+        return jiraSoapServiceLocator;
+    }
+}
+<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>
+    <parent>
+        <groupId>com.atlassian.pom</groupId>
+        <artifactId>atlassian-public-pom</artifactId>
+        <version>23</version>
+    </parent>
+
+    <groupId>com.atlassian.jira.plugins</groupId>
+    <artifactId>atlassian-jira-rpc-parent</artifactId>
+    <version>4.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <name>JIRA RPC parent POM</name>
+    <description>Contains the JIRA RPC plugin and a sample soap client.</description>
+    <inceptionYear>2004</inceptionYear>
+
+    <scm>
+        <connection>scm:svn:https://svn.atlassian.com/svn/public/atlassian/rpc-jira-plugin/trunk</connection>
+        <developerConnection>scm:svn:https://svn.atlassian.com/svn/public/atlassian/rpc-jira-plugin/trunk
+        </developerConnection>
+        <url>https://svn.atlassian.com/svn/public/atlassian/rpc-jira-plugin/trunk</url>
+    </scm>
+
+    <modules>
+        <module>rpc-jira-plugin</module>
+        <module>jira-soapclient</module>
+    </modules>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <fork>true</fork>
+                    <meminitial>128m</meminitial>
+                    <maxmem>512m</maxmem>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <jdkLevel>1.5</jdkLevel>
+
+        <jira.version>4.1-SNAPSHOT</jira.version>
+        <jira.data.version>4.1-SNAPSHOT</jira.data.version>
+    </properties>
+</project>