mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-29 06:39:38 +00:00
Removed RSS/rome and added JSon
RSS is becoming outdated, JSon is a better example
This commit is contained in:
parent
c2c404bff5
commit
80c1d243a1
6 changed files with 80 additions and 102 deletions
38
pom.xml
38
pom.xml
|
@ -44,8 +44,7 @@
|
||||||
<logback.version>1.1.2</logback.version>
|
<logback.version>1.1.2</logback.version>
|
||||||
<slf4j.version>1.7.10</slf4j.version>
|
<slf4j.version>1.7.10</slf4j.version>
|
||||||
|
|
||||||
<!-- RSS and JSon-->
|
<!-- JSon-->
|
||||||
<rome.version>1.5.0</rome.version>
|
|
||||||
<json-path.version>0.9.1</json-path.version>
|
<json-path.version>0.9.1</json-path.version>
|
||||||
|
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
|
@ -107,6 +106,7 @@
|
||||||
<version>${jaxb-impl.version}</version>
|
<version>${jaxb-impl.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- JSon -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.jsonpath</groupId>
|
<groupId>com.jayway.jsonpath</groupId>
|
||||||
<artifactId>json-path</artifactId>
|
<artifactId>json-path</artifactId>
|
||||||
|
@ -123,6 +123,7 @@
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>*</artifactId>
|
<artifactId>*</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
<!-- because Spring Data usually comes with a slightly older version of Spring -->
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -174,7 +175,18 @@
|
||||||
<version>${spring-framework.version}</version>
|
<version>${spring-framework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjrt</artifactId>
|
||||||
|
<version>${aspectj.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjweaver</artifactId>
|
||||||
|
<version>${aspectj.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Database connection pool
|
<!-- Database connection pool
|
||||||
See here for more details on commons-dbcp versus tomcat-jdbc:
|
See here for more details on commons-dbcp versus tomcat-jdbc:
|
||||||
http://blog.ippon.fr/2013/03/13/improving-the-performance-of-the-spring-petclinic-sample-application-part-3-of-5/
|
http://blog.ippon.fr/2013/03/13/improving-the-performance-of-the-spring-petclinic-sample-application-part-3-of-5/
|
||||||
|
@ -199,13 +211,6 @@
|
||||||
<version>${logback.version}</version>
|
<version>${logback.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- used for Atom -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.rometools</groupId>
|
|
||||||
<artifactId>rome</artifactId>
|
|
||||||
<version>${rome.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Date and Time -->
|
<!-- Date and Time -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -299,19 +304,6 @@
|
||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjrt</artifactId>
|
|
||||||
<version>${aspectj.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjweaver</artifactId>
|
|
||||||
<version>${aspectj.version}</version>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Dandelion -->
|
<!-- Dandelion -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.dandelion</groupId>
|
<groupId>com.github.dandelion</groupId>
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.springframework.samples.petclinic.model.Vets;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
import org.springframework.samples.petclinic.service.ClinicService;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
@ -40,7 +41,7 @@ public class VetController {
|
||||||
this.clinicService = clinicService;
|
this.clinicService = clinicService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/vets")
|
@RequestMapping(value="/vets.xml")
|
||||||
public String showVetList(Map<String, Object> model) {
|
public String showVetList(Map<String, Object> model) {
|
||||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||||
// so it is simpler for Object-Xml mapping
|
// so it is simpler for Object-Xml mapping
|
||||||
|
@ -49,6 +50,15 @@ public class VetController {
|
||||||
model.put("vets", vets);
|
model.put("vets", vets);
|
||||||
return "vets/vetList";
|
return "vets/vetList";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/vets.json")
|
||||||
|
public @ResponseBody Vets showResourcesVetList() {
|
||||||
|
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||||
|
// so it is simpler for JSon/Object mapping
|
||||||
|
Vets vets = new Vets();
|
||||||
|
vets.getVetList().addAll(this.clinicService.findVets());
|
||||||
|
return vets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.samples.petclinic.web;
|
|
||||||
|
|
||||||
import com.rometools.rome.feed.atom.Entry;
|
|
||||||
import com.rometools.rome.feed.atom.Feed;
|
|
||||||
import com.rometools.rome.feed.atom.Content;
|
|
||||||
import org.springframework.samples.petclinic.model.Vet;
|
|
||||||
import org.springframework.samples.petclinic.model.Vets;
|
|
||||||
import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A view creating a Atom representation from a list of Visit objects.
|
|
||||||
*
|
|
||||||
* @author Alef Arendsen
|
|
||||||
* @author Arjen Poutsma
|
|
||||||
*/
|
|
||||||
public class VetsAtomView extends AbstractAtomFeedView {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) {
|
|
||||||
feed.setId("tag:springsource.org");
|
|
||||||
feed.setTitle("Veterinarians");
|
|
||||||
//feed.setUpdated(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Entry> buildFeedEntries(Map<String, Object> model,
|
|
||||||
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
||||||
|
|
||||||
Vets vets = (Vets) model.get("vets");
|
|
||||||
List<Vet> vetList = vets.getVetList();
|
|
||||||
List<Entry> entries = new ArrayList<Entry>(vetList.size());
|
|
||||||
|
|
||||||
for (Vet vet : vetList) {
|
|
||||||
Entry entry = new Entry();
|
|
||||||
// see http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
|
|
||||||
entry.setId(String.format("tag:springsource.org,%s", vet.getId()));
|
|
||||||
entry.setTitle(String.format("Vet: %s %s", vet.getFirstName(), vet.getLastName()));
|
|
||||||
//entry.setUpdated(visit.getDate().toDate());
|
|
||||||
|
|
||||||
Content summary = new Content();
|
|
||||||
summary.setValue(vet.getSpecialties().toString());
|
|
||||||
entry.setSummary(summary);
|
|
||||||
|
|
||||||
entries.add(entry);
|
|
||||||
}
|
|
||||||
response.setContentType("blabla");
|
|
||||||
return entries;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -27,10 +27,6 @@
|
||||||
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
|
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
|
||||||
</mvc:view-resolvers>
|
</mvc:view-resolvers>
|
||||||
|
|
||||||
|
|
||||||
<!-- Renders an Atom feed of the visits. Used by the BeanNameViewResolver -->
|
|
||||||
<bean id="vets/vetList.atom" class="org.springframework.samples.petclinic.web.VetsAtomView"/>
|
|
||||||
|
|
||||||
<!-- Renders an XML view. Used by the BeanNameViewResolver -->
|
<!-- Renders an XML view. Used by the BeanNameViewResolver -->
|
||||||
<bean id="vets/vetList.xml" class="org.springframework.web.servlet.view.xml.MarshallingView">
|
<bean id="vets/vetList.xml" class="org.springframework.web.servlet.view.xml.MarshallingView">
|
||||||
<property name="marshaller" ref="marshaller"/>
|
<property name="marshaller" ref="marshaller"/>
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<a href="<spring:url value="/vets.xml" htmlEscape="true" />">View as XML</a>
|
<a href="<spring:url value="/vets.xml" htmlEscape="true" />">View as XML</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="<spring:url value="/vets.atom" htmlEscape="true" />">Subscribe to Atom feed</a>
|
<a href="<spring:url value="/vets.json" htmlEscape="true" />">View as JSon</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package org.springframework.samples.petclinic.web;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for the UserResource REST controller.
|
||||||
|
*
|
||||||
|
* @see UserResource
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration({"classpath:spring/business-config.xml", "classpath:spring/tools-config.xml", "classpath:spring/mvc-core-config.xml"})
|
||||||
|
@WebAppConfiguration
|
||||||
|
@ActiveProfiles("spring-data-jpa")
|
||||||
|
public class VetControllerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VetController vetController;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebApplicationContext ctx;
|
||||||
|
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
this.mockMvc = MockMvcBuilders.standaloneSetup(vetController).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetExistingUser() throws Exception {
|
||||||
|
ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
actions.andExpect(content().contentType("application/json;charset=UTF-8"))
|
||||||
|
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue