Created
October 15, 2011 10:28
-
-
Save thorque/1289371 to your computer and use it in GitHub Desktop.
RESTful webservice with Spring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Constellation{ | |
... | |
@XStreamOmmitField | |
private byte[] starCardData; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Constellation{ | |
... | |
@XStreamImplicit(itemFiledName = "names") | |
private List<ConstellationName> names; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class ConstellationServiceController { | |
@Inject | |
private ConstellationService service; | |
@RequestMapping(value = "/constellations") | |
public ModelAndView getAllConstellations() { | |
List<Constellation> constellations = service.findAllConstellations(); | |
ModelAndView mav = new ModelAndView("xmlView", | |
BindingResult.MODEL_KEY_PREFIX + "constellations", | |
constellations); | |
return mav; | |
} | |
@RequestMapping("/constellation_by_code/{code}") | |
public ModelAndView findConstellationByCode(@PathVariable String code) { | |
Constellation constellation = service.findConstellationByCode(code); | |
for (ConstellationName name : constellation.getNames()) { | |
name.toString(); | |
} | |
return new ModelAndView("xmlView", BindingResult.MODEL_KEY_PREFIX | |
+ "constellations", constellation); | |
} | |
@RequestMapping("/constellations_by_search/{search}") | |
public ModelAndView findConstellationByCodeOrName( | |
@PathVariable String search) { | |
return new ModelAndView("xmlView", BindingResult.MODEL_KEY_PREFIX | |
+ "constellations", | |
service.findAllConstellationByCodeOrName(search)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class ConstellationServiceController { | |
@Inject | |
private ConstellationService service; | |
@RequestMapping(value = "/constellations") | |
public ModelAndView getAllConstellations() { | |
List<Constellation> constellations = service.findAllConstellations(); | |
ModelAndView mav = new ModelAndView("xmlView", | |
BindingResult.MODEL_KEY_PREFIX + "constellations", constellations); | |
return mav; | |
} | |
@RequestMapping("/constellation_by_code/{code}") | |
public ModelAndView findConstellationByCode(@PathVariable String code) { | |
Constellation constellation = service.findConstellationByCode(code); | |
return new ModelAndView("xmlView", BindingResult.MODEL_KEY_PREFIX | |
+ "constellations", constellation); | |
} | |
@RequestMapping("/constellations_by_search/{search}") | |
public ModelAndView findConstellationByCodeOrName | |
@PathVariable String search) { | |
return new ModelAndView("xmlView", BindingResult.MODEL_KEY_PREFIX | |
+ "constellations", service.findAllConstellationByCodeOrName(search)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.agilebackoffice.wafe</groupId> | |
<artifactId>wafe</artifactId> | |
<name>WAFE</name> | |
<version>1.0.0-SNAPSHOT</version> | |
<packaging>pom</packaging> | |
<modules> | |
<module>wafe-backend</module> | |
<module>wafe-importer</module> | |
<module>wafe-ui-wicket</module> | |
</modules> | |
<url>https://thorque@github.com/thorque/wafe.git</url> | |
<issueManagement> | |
<system>PivotalTracker</system> | |
<url>https://www.pivotaltracker.com/projects/362513</url> | |
</issueManagement> | |
<inceptionYear>2011</inceptionYear> | |
<scm> | |
<developerConnection>ssh://git@github.com:thorque/wafe.git</developerConnection> | |
<tag>master</tag> | |
<connection>ssh://git@github.com:thorque/wafe.git</connection> | |
<url>https://thorque@github.com/thorque/wafe.git</url> | |
</scm> | |
<organization> | |
<name>Agile BackOffice</name> | |
<url>http://www.agilebackoffice.org/</url> | |
</organization> | |
<profiles> | |
<profile> | |
<id>integration-test</id> | |
<modules> | |
<module>wafe-it</module> | |
</modules> | |
</profile> | |
</profiles> | |
<build> | |
<pluginManagement> | |
<plugins> | |
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> | |
<plugin> | |
<groupId>org.eclipse.m2e</groupId> | |
<artifactId>lifecycle-mapping</artifactId> | |
<version>1.0.0</version> | |
<configuration> | |
<lifecycleMappingMetadata> | |
<pluginExecutions> | |
<pluginExecution> | |
<pluginExecutionFilter> | |
<groupId> | |
org.codehaus.gmaven | |
</groupId> | |
<artifactId> | |
gmaven-plugin | |
</artifactId> | |
<versionRange> | |
[1.3,) | |
</versionRange> | |
<goals> | |
<goal>testCompile</goal> | |
</goals> | |
</pluginExecutionFilter> | |
<action> | |
<ignore></ignore> | |
</action> | |
</pluginExecution> | |
</pluginExecutions> | |
</lifecycleMappingMetadata> | |
</configuration> | |
</plugin> | |
</plugins> | |
</pluginManagement> | |
</build> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(value = "/constellations") | |
public ModelAndView getAllConstellations() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping("/constellation_by_code/{code}") | |
public ModelAndView findConstellationByCode(@PathVariable String code) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<constallation> | |
<id>4</id> | |
<name>Andromeda</name> | |
<code>and</code> | |
... | |
<names> | |
<id>19</id> | |
<name>Andromeda</name> | |
<langCode>de</langCode> | |
<code>and</code> | |
</names> | |
<names> | |
<id>20</id> | |
<name>Andromeda</name> | |
<langCode>en</langCode> | |
<code>and</code> | |
</names> | |
... | |
</constellation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /> | |
<bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller" | |
p:autodetectAnnotations="true" /> | |
<bean id="xmlView" class="org.springframework.web.servlet.view.xml.MarshallingView" | |
p:contentType="application/xml"> | |
<constructor-arg ref="xstreamMarshaller" /> | |
</bean> | |
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> | |
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> | |
<property name="mediaTypes"> | |
<map> | |
<entry key="json" value="application/json" /> | |
<entry key="xml" value="application/xml" /> | |
</map> | |
</property> | |
<property name="defaultViews"> | |
<list> | |
<ref bean="jsonView" /> | |
<ref bean="xmlView" /> | |
</list> | |
</property> | |
<property name="ignoreAcceptHeader" value="true" /> | |
</bean> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class Service{ | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<web-app> | |
<context-param> | |
<param-name>contextConfigLocation</param-name> | |
<param-value>/WEB-INF/rpc-servlet.xml</param-value> | |
</context-param> | |
<listener> | |
<listener-class> | |
org.springframework.web.context.ContextLoaderListener | |
</listener-class> | |
</listener> | |
<servlet> | |
<servlet-name>rpc</servlet-name> | |
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>rpc</servlet-name> | |
<url-pattern>/rpc/*</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment