Skip to content

Instantly share code, notes, and snippets.

@r351574nc3
Last active August 29, 2015 14:09
Show Gist options
  • Save r351574nc3/12e7d74198ce1efc00da to your computer and use it in GitHub Desktop.
Save r351574nc3/12e7d74198ce1efc00da to your computer and use it in GitHub Desktop.
Jersey and Kuali Setup
package com.github.kualigan.ducktyping.api;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
*
* @author Leo Przybylski
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"id" })
public interface Organization {
@XmlElement
String getId();
void setId(final String id);
@XmlElement
String getName();
void setName(final String name);
}
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="organizationService" class="com.github.kualigan.ducktyping.impl.OrganizationServiceImpl" />
<context:component-scan base-package="com.github.kualigan.ducktyping.rest" />
</beans>
<bean id="rice.ksb.serviceBus"
class="org.kuali.rice.core.framework.resourceloader.GlobalResourceLoaderServiceFactoryBean">
<property name="serviceName" value="rice.ksb.serviceBus" />
</bean>
<bean id="organizationService" class="com.github.kualigan.ducktyping.impl.OrganizationServiceImpl" />
<bean id="jsonOrganizationService" class="com.github.kualigan.ducktyping.rest.JsonOrganizationService">
<property name="organizationService" ref="organizationService" />
</bean>
<bean id="OrganizationService" class="org.kuali.rice.ksb.api.bus.support.RestServiceDefinition">
<property name="serviceNameSpaceURI" value="KUALI"/>
<property name="service" ref="jsonOrganizationService"/>
<property name="resourceClass"
value="com.github.kualigan.ducktyping.rest.JsonOrganizationService"/>
<property name="localServiceName" value="jsonOrganizationService"/>
</bean>
<bean class="org.kuali.rice.ksb.api.bus.support.ServiceBusExporter">
<property name="serviceBus" ref="rice.ksb.serviceBus"/>
<property name="serviceDefinition" ref="OrganizationService"/>
</bean>
package com.github.kualigan.ducktyping.rest;
import com.github.kualigan.ducktyping.api.Organization;
import com.github.kualigan.ducktyping.api.OrganizationService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Service implementation for looking up {@link Organization} over ReST or JAX-WS
*
* @author Leo Przybylski
*/
@Path("/Organizations")
@Produces(MediaType.APPLICATION_JSON)
@Component
public class JsonOrganizationService {
@Autowired
private OrganizationService organizationService;
@GET
@Path("/get/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getOrganization(@PathParam("id") final String organizationId) {
return Response.ok(getOrganizationService().getOrganization(organizationId)).build();
}
public void setOrganizationService(final OrganizationService organizationService) {
this.organizationService = organizationService;
}
public OrganizationService getOrganizationService() {
return this.organizationService;
}
}
package com.github.kualigan.ducktyping.model;
/**
*
* @author Leo Przybylski
*/
public class Organization implements com.github.kualigan.ducktyping.api.Organization {
protected String id;
protected String name;
public Organization(final String organizationId) {
this.id = organizationId;
}
@Override
public void setId(final String id) {
this.id = id;
}
@Override
public String getId() {
return id;
}
@Override
public void setName(final String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}
package com.github.kualigan.ducktyping;
import com.github.kualigan.ducktyping.model.Organization;
/**
* Lookup and retrieve an {@link Organization}
*
* @author Leo Przybylski
*/
public interface OrganizationService {
Organization getOrganization(final String organizationId);
}
package com.github.kualigan.ducktyping.impl;
import com.github.kualigan.ducktyping.api.Organization;
import com.github.kualigan.ducktyping.api.OrganizationService;
/**
* Service implementation for looking up {@link Organization} over ReST or JAX-WS
*
* @author Leo Przybylski
*/
public class OrganizationServiceImpl implements OrganizationService {
@Override
public Organization getOrganization(final String organizationId) {
final Organization retval = new com.github.kualigan.ducktyping.model.Organization(organizationId);
retval.setName("Human Resources");
return retval;
}
}
<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">
<name>The ducktyping-example Jersey Module</name>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.kualigan</groupId>
<artifactId>ducktyping-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ducktyping-example-jersey</artifactId>
<packaging>war</packaging>
<properties>
<jersey.version>1.18.2</jersey.version>
<jackson.version>1.9.13</jackson.version>
</properties>
...
...
<dependencies>
...
...
<!-- Jersey + Spring -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>ducktyping-example</display-name>
<context-param>
<param-name>environment</param-name>
<param-value>dev</param-value>
</context-param>
<context-param>
<param-name>web.bootstrap.spring.file</param-name>
<param-value>classpath:com/github/kualigan/ducktyping/BootStrapSpringBeans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
...
...
<servlet>
<servlet-name>krad</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.github.kualigan.ducktyping.rest</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/kr-login/*</url-pattern>
</servlet-mapping>
...
...
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment