3 Replies Latest reply on Sep 2, 2015 9:52 PM by amit.mahajan

    How to implement REST services for a custom content type in Jive 6?

    jliano

      I'm creating a new content type and I am basing most of it on the Document/DbDocument code that Jive core uses.

       

      I've got the struts action configured and the soy templates to display the input form and load all the additional soy templates, including the submit button. Upon clicking submit the application tries to do a post to: /__services/v2/rest/[content-type]

       

      I can't find a way to define the Web Service in spring so that it receives the calls made by the client.

       

      <jaxrs:server id="[content-type]RestService" address="/v2/rest/[content-type]">

      <jaxrs:serviceBeans>

      <ref bean="[content-type]ContentService" />

      </jaxrs:serviceBeans>

               <jaxrs:providers>

                   <ref bean="secureJacksonJsonProvider"/>

                   <ref bean="internalRestExceptionMapper"/>

               </jaxrs:providers>

      </jaxrs:server>

       

      I was going down the path of mimicking how the documents are done, but just creating a Service Class that extends ContentService<C,U> doesn't seemed to be picked up and I can't get the webservice to respond .

       

      Any help or push in the right direction is appreciated it.

       

      Thanks,

      JOrge.

        • Re: How to implement REST services for a custom content type in Jive 6?
          amit.mahajan

          Hi Jorge

           

          You can refer Jive 5 Webservices REST and SOAP with CXF and Spring

           

          You need to make 2 entries in spring.xml one you memtioned above and another for service manager bean (<ref bean="[content-type]ContentService" />).

          example:

           

              <bean id="abcWebService" class="com.impl.ABCServiceImpl">

                  <property name="abcManager" ref="abcManager" />

              </bean>

           

           

              <bean id="abcManager" class="com.impl.ABCManagerImpl">

              ...

              </bean>

           

           

              <jaxrs:server id="abcWS" address="asdf/abc">

                  <jaxrs:serviceBeans>

                      <ref bean="abcWebService" />

                  </jaxrs:serviceBeans>

                  <jaxrs:providers>

                      <ref bean="..." />

                  </jaxrs:providers>

              </jaxrs:server>

           

          The ABCManager or its interface needs to have webservice annotations

          example:

           

          @Produces({"application/json"})

          public class ABCServiceImpl implements ABCService {

              private static final Logger log = Logger.getLogger(ABCServiceImpl.class);

              private ABCManager abcManager;

           

              @GET

              @Override

              public Z getXYZ(@HeaderParam("PARAM") long param) { ...

           

          On deployment you can access the service from jive url /asdf/abc

            • Re: How to implement REST services for a custom content type in Jive 6?
              mckenzie_j

              HI Amit,

               

              I was trying to follow this example to create a custom web service in Jive 8.0.1. I am facing spring initialization error:

               

              org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insightServer': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)

              [WARNING] [talledLocalContainer] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)

              [WARNING] [talledLocalContainer] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)

              [WARNING] [talledLocalContainer] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)

              [WARNING] [talledLocalContainer] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)

              [WARNING] [talledLocalContainer] at com.jivesoftware.community.lifecycle.JiveApplication.initialize(JiveApplication.java:151)

              [WARNING] [talledLocalContainer] at com.jivesoftware.community.Jive.start(Jive.java:142)

              [WARNING] [talledLocalContainer] at com.jivesoftware.community.web.JiveApplicationContextLoaderListener.contextInitialized(JiveApplicationContextLoaderListener.java:29)

              [WARNING] [talledLocalContainer] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)

              [WARNING] [talledLocalContainer] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)

              [WARNING] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

              [WARNING] [talledLocalContainer] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)

              [WARNING] [talledLocalContainer] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)

              [WARNING] [talledLocalContainer] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)

              [WARNING] [talledLocalContainer] at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)

              [WARNING] [talledLocalContainer] at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)

              [WARNING] [talledLocalContainer] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

              [WARNING] [talledLocalContainer] at java.util.concurrent.FutureTask.run(FutureTask.java:266)

              [WARNING] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

              [WARNING] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

              [WARNING] [talledLocalContainer] at java.lang.Thread.run(Thread.java:745)

              [WARNING] [talledLocalContainer] Caused by: org.apache.cxf.service.factory.ServiceConstructionException

              [WARNING] [talledLocalContainer] at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:215)

              [WARNING] [talledLocalContainer] at sun.reflect.GeneratedMethodAccessor207.invoke(Unknown Source)

              [WARNING] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              [WARNING] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:497)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1696)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1635)

              [WARNING] [talledLocalContainer] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)

              [WARNING] [talledLocalContainer] ... 27 more

              [WARNING] [talledLocalContainer] Caused by: javax.ws.rs.NotFoundException

              [WARNING] [talledLocalContainer] at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJAXRSFactoryBean.java:317)

              [WARNING] [talledLocalContainer] at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:152)

              [WARNING] [talledLocalContainer] ... 33 more

               

               

               

              My spring configuration  is making use of the following configuration:

               

              <?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:util="http://www.springframework.org/schema/util"
                 xmlns:jaxrs="http://cxf.apache.org/jaxrs"
                 xsi:schemaLocation="
                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"
                 default-autowire="no" default-init-method="init" default-destroy-method="destroy">

               

               

               

                 <bean id="spaceInsightService" class="class path to ServiceImpl">

                 <property name="spaceInsightManager" ref = "spaceInsightManager"/>

               

                 </bean>

               

                 <bean id="spaceInsightDAO" class="class path to DAOImpl">

                 <property name="dataSource">

                 <util:property-path path="dataSourceFactory.dataSource"/>

                 </property>

                 </bean>

                 <bean id="spaceInsightManager" class="class path to ManagerImpl">

                 <property name="spaceInsightDAO" ref = "spaceInsightDAO"/>

               

                 </bean>

               

               

                 <jaxrs:server id="insightServer" address="/" bus="apiCxfBus">

                 <jaxrs:serviceBeans>

                 <ref bean="spaceInsightService"/>

                 </jaxrs:serviceBeans>

                 <jaxrs:providers>

                 <ref bean="insightSecureJacksonJsonProvider"/>

                 </jaxrs:providers>

                 </jaxrs:server>

               

                 <bean id="insightSecureJacksonJsonProvider"
                 class="com.jivesoftware.community.webservices.rest.SecureJiveJacksonJSONProvider"/>

               

              </beans>

               

              Is there anything that is missing??

               

               

              cc:

              Ryan Rutan  - Can you help me in this please ?