There is not a whole lot of documentation out there on this subject out on the Web. Nevertheless, there is one document that is available on the Jive Software community which gives a real good start.
https://community.jivesoftware.com/docs/DOC-28795
This actually is a much better document than came with the 4.0 Jive SBS Developer’s Traning Course which gave me a broken build which crashed the server when deployed. Still, some items are left out of this document leaving. I hope to fill the void with this document.
The first thing you need to do is to create a generic maven structured plugin – a process not covered in this document. Nevertheless, I will include the contents of my POM file here.
<?xml version=”1.0″ encoding=”UTF-8″?>
<!–
~ $Revision: 96475 $
~ $Date: 2009-11-02 16:51:02 -0800 (Mon, 02 Nov 2009) $
~
~ Copyright (C) 1999-${YEAR} Jive Software. All rights reserved.
~
~ This software is the proprietary information of Jive Software. Use is subject to license terms.
–>
<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“>
<!–
These parameters were pased in via the commandline when this pom was created by the archetype.
–>
<modelVersion>4.0.0</modelVersion>
<groupId>JiveWebServiceDemo</groupId>
<artifactId>JiveWebServiceDemo</artifactId>
<name>JiveWebServiceDemo</name>
<version>1.0</version>
<packaging>jar</packaging>
<url>http://www.jivesoftware.com</url><build>
<finalName>${final.name}</finalName>
<plugins>
<!– For compilation–>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!– Weave transactions into the plugin –>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/src/main/assembly/assembly-plugin.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId> org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<!– Unpackages this SBS plugin. That way it can be used in conjunction with the -DpluginDirs= property, which
bypasses the standard plugin installation (which happens via the admin console), by pointing to exploded plugin jar created by this. –>
<id>explode-sbs-plugin</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir=”${basedir}/target/${final.name}” />
<unjar src=”${basedir}/target/${final.name}.jar” dest=”${basedir}/target/${final.name}” />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!– For unit testing –>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<exclude>**/selenium/*Test.java</exclude>
</excludes>
<argLine>-Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m</argLine>
</configuration>
</plugin></plugins>
</build>
<dependencies>
<dependency>
<groupId>com.jivesoftware</groupId>
<artifactId>jive-sbs-public</artifactId>
<version>4.5.5.2</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jivesoftware</groupId>
<artifactId>jive-sbs-public-all</artifactId>
<version>4.5.5.2</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.3</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.codehaus.jra</groupId>
<artifactId>jra</artifactId>
<version>1.0-alpha-4</version>
</dependency>
</dependencies>
<!–
This is where you set the Jive SBS version your plugin is compiled against.
–>
<properties>
<sbs.version>4.5.5.2</sbs.version>
<final.name>${project.artifactId}-${project.version}-${sbs.version}</final.name>
<build.number>${env.BUILD_NUMBER}</build.number>
<build.project.name>${env.TEAMCITY_PROJECT_NAME}</build.project.name>
</properties>
</project>
The Struts file needs not additions or changes. The webservices do not make use of the struts.xml file. The plugin.xml file needs to be updated as any other Jive plugin needs updated. The schema.xml file also is not needed unless database changes are being done.
The spring.xml file does need modifications. Here is a working spring file for this demo.
<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:jaxws=”http://cxf.apache.org/jaxws”
xmlns:util=”http://www.springframework.org/schema/util”
xsi:schemaLocation=”
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd“
default-autowire=”no” default-init-method=”init” default-destroy-method=”destroy”><bean id=”demoServiceImpl”>
<property name=”communityManager” ref=”communityManager” />
<property name=”documentManager” ref=”documentManager” />
<property name=”wsUtil” ref=”wsUtil” />
</bean>
<jaxws:endpoint id=”demoRestService”
address=”/rest/demoService”
bindingUri=”http://apache.org/cxf/binding/http“>
<jaxws:implementor>
<ref bean=”demoServiceImpl” />
</jaxws:implementor>
<jaxws:serviceFactory>
<ref bean=”wrappedServiceFactory” />
</jaxws:serviceFactory>
</jaxws:endpoint>
</beans>
With this spring.xml file properly in place, now we need to create an interface and a class that will define the webservice calls.
package com.jivesoftware.community.webservices;import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import org.codehaus.jra.*;
import java.util.List;@WebService(portName=”DemoServicePort”, serviceName = “DemoService”,
targetNamespace = “http://jivesoftware.com/clearspace/webservices“)
public interface DemoService {
/**
* http://alvjpxw05:8080/rpc/rest/demoService/GetReply
*/
@WebMethod
@Get
@HttpResource(location=”/GetReply”)
public String getMyReply();/**
* Use Groovy Script to access
*/
@WebMethod
@Put
@HttpResource(location=”/MyDocumentService”)
public List<WSDocument> getMyDocumentsFromCommunity(@WebParam(name = “community_id”)int community_id);
}
And here is the class which implements the interface.
package com.jivesoftware.community.webservices;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.codehaus.jra.Get;
import org.codehaus.jra.HttpResource;import java.util.*;
import com.jivesoftware.community.*;
import com.jivesoftware.base.User;
import com.jivesoftware.community.webservices.server.WSUtil;
import com.jivesoftware.community.proxy.DocumentProxy;
import static com.jivesoftware.community.renderer.impl.v2.JAXPUtils.toXmlString;
import com.jivesoftware.util.StringUtils;
import com.jivesoftware.community.renderer.impl.v2.JAXPUtils;
@WebService(portName=”DemoService”, serviceName = “DemoService”, targetNamespace = “http://jivesoftware.com/clearspace/webservices“)
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class DemoServiceImpl implements DemoService {
private static final Logger log = LogManager.getLogger(DemoServiceImpl.class);
private CommunityManager communityManager;
private DocumentManager documentManager;
private WSUtil wsUtil;
@WebMethod
public String getMyReply() {
return “My answers are limited, you must ask the right question.”;
}
@WebMethod
public List<WSDocument> getMyDocumentsFromCommunity(@WebParam(name = “community_id”)int community_id) {
List<WSDocument> list = new Vector<WSDocument>();
Community community = null;
try {
community = communityManager.getCommunity(community_id);
}catch (Exception e)
{
log.info(e);
}
if(community!=null){
for (Document d : documentManager.getDocuments(community)) {
DocumentType dt = d.getDocumentType();
DocumentProxy dp = (DocumentProxy)d;
DocumentAttributes attributes = dp.getDocumentAttributes();
boolean isPublished = attributes.isPublished();
if(isPublished)
{
list.add(wsUtil.convert(d));
}
}
}
return list;
}public void setCommunityManager(CommunityManager communityManager) {
this.communityManager = communityManager;
}public void setDocumentManager(DocumentManager documentManager) {
this.documentManager = documentManager;
}public void setWsUtil(WSUtil wsUtil) {
this.wsUtil = wsUtil;
}
}
Now compile the plugin and install it into Jive.
To see that the webservice exists, go to the following URL.
There is a URL to know if the webservice exists.
You can use this as a url for the first method which uses GET.
http://myjivesbsserver/rpc/rest/demoService/GetReply
You can use a groovy script to access the second one using the PUT method.
