Boa noite! galera no Video 2 da Aula 14 do Curso Spring MVC I ensina a simular um finalização de carrinho com JSON e Rest estou usando a extensão Restlet Client no Chrome. aparentemente esta tudo funcionando no Eclipse, quando eu clico no botão finalizar comprar ele manda para tela de listagem de produtos e imprime o a mensagem de "pagamento realizado com Sucesso" só na minha extensão do Restlet Client não aparece nada. tenho que fazer alguma configuração na minha extensão? agradeço pela ajuda, informo que não tenho nenhum conhecimento em Rest e Json kkkkk estou apreendendo...
classe do pagamento
public class DadosPagamento {
private BigDecimal value;
public DadosPagamento(BigDecimal value){
this.value = value;
}
public DadosPagamento(){
}
public BigDecimal getValue(){
return value;
}
}
Classe de configuração
@EnableWebMvc
@ComponentScan(basePackageClasses={HomeController.class, ProdutoDAO.class, FileSaver.class, CarrinhoCompras.class})
public class AppWebConfiguration extends WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver internalResourceViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposedContextBeanNames("carrinhoCompras");
return resolver;
}
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("/WEB-INF/messages");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setCacheSeconds(1);
return messageSource;
}
@Bean
public FormattingConversionService mvcConversionService(){
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
registrar.setFormatter(new DateFormatter("dd/MM/yyyy"));
registrar.registerFormatters(conversionService);
return conversionService;
}
@Bean
public MultipartResolver multipartResolver(){
return new StandardServletMultipartResolver();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/imagens/**").addResourceLocations("/WEB-INF/imagens/");
}
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
classe do Controller de Pagamento
@Controller
@RequestMapping("/pagamento")
public class PagamentoController {
@Autowired
CarrinhoCompras carrinho;
@Autowired
RestTemplate restTemplate;
@RequestMapping(value = "/finalizar", method = RequestMethod.POST)
public ModelAndView finalizar(RedirectAttributes redirectAttributes) {
String url = "http://book-payment.herokuapp.com/payment";
String response = restTemplate.postForObject(url, new DadosPagamento(carrinho.getTotal()), String.class);
System.out.println(carrinho.getTotal());
System.out.println(response);
redirectAttributes.addFlashAttribute("Sucesso", response);
return new ModelAndView("redirect:/produtos");
}
}
minha JSP itens.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<!DOCTYPE html>
<html>
<head>
<c:url value="/" var="contextPath" />
<meta charset="utf-8"/>
</head>
<body>
<header id="layout-header">
<div class="clearfix container">
<a href="/" id="logo"></a>
<div id="header-content">
<nav id="main-nav">
<ul class="clearfix">
<li><a href="${s:mvcUrl('CCC#itens').build() }" rel="nofollow">Carrinho (${carrinhoCompras.quantidade })</a></li>
<li><a href="/pages/sobre-a-casa-do-codigo" rel="nofollow">Sobre Nós</a></li>
<li><a href="/pages/perguntas-frequentes" rel="nofollow">Perguntas Frequentes</a></li>
</ul>
</nav>
</div>
</div>
</header>
<nav class="categories-nav">
<ul class="container">
<li class="category"><a href="http://www.casadocodigo.com.br">Home</a></li>
<li class="category"><a href="/collections/livros-de-agile">
Agile </a></li>
<li class="category"><a href="/collections/livros-de-front-end">
Front End </a></li>
<li class="category"><a href="/collections/livros-de-games">
Games </a></li>
<li class="category"><a href="/collections/livros-de-java">
Java </a></li>
<li class="category"><a href="/collections/livros-de-mobile">
Mobile </a></li>
<li class="category"><a href=#> Web </a></li>
</ul>
</nav>
<section class="container middle">
<h2 id="cart-title">Seu carrinho de compras</h2>
<table id="cart-table">
<colgroup>
<col class="item-col"/>
<col class="item-price-col"/>
<col class="item-quantity-col"/>
<col class="line-price-col"/>
<col class="delete-col"/>
</colgroup>
<thead>
<tr>
<th class="cart-img-col"></th>
<th width="65%">Item</th>
<th width="10%">Preço</th>
<th width="10%">Quantidade</th>
<th width="10%">Total</th>
<th width="5%"></th>
</tr>
</thead>
<tbody>
<c:forEach items="${carrinhoCompras.itens }" var="item">
<tr>
<td class="cart-img-col"><img src="/casadocodigo/imagens/livro-a-venda.png" width="71px" height="100px"/></td>
<td class="item-title" align="center">${item.produto.titulo }</td>
<td class="numeric-cell" align="center">${item.preco }</td>
<td class="quantity-input-cell" align="center">
<input type="number" min="0" readonly="readonly" id="quantidade" name="quantidade" value="${carrinhoCompras.getQuantidade(item) }" /></td>
<td class="numeric-cell" align="center">${carrinhoCompras.getTotal(item)}</td>
<td class="remove-item">
<form action="${s:mvcUrl('CCC#remover').arg(0, item.produto.id).arg(1, item.tipoPreco).build() }" method="post">
<input type="image" src="/casadocodigo/imagens/excluir.png" alt="Excluir" title="Excluir" >
</form>
</td>
</tr>
</c:forEach>
</tbody>
<tfoot>
<tr>
<td colspan="3">
<form action="${s:mvcUrl('PC#finalizar').build() }" method="post">
<input type="submit" class="checkout" name="checkout" value="Finalizar compra" />
</form>
</td>
<td class="numeric-cell"> ${carrinhoCompras.total }</td>
</tr>
</tfoot>
</table>
<h2>Você já conhece os outros livros da Casa do Código?</h2>
<ul id="collection" class="related-books">
<li class="col-left">
<a href="/products/livro-plsql" class="block clearfix book-suggest" data-book="PL/SQL: Domine a linguagem do banco de dados Oracle">
<img width="113px" height="160px" src="http:////cdn.shopify.com/s/files/1/0155/7645/products/plsql-featured_compact.png?v=1434740236" />
</a>
</li>
</ul>
<h2><a href="${pageContext.request.contextPath}/produtos">Veja todos os livros que publicamos!</a></h2>
</section>
<footer id="layout-footer">
<div class="clearfix container">
<div id="collections-footer">
<!-- cdc-footer -->
<p class="footer-title">Coleções de Programação</p>
<ul class="footer-text-links">
<li><a href="/collections/livros-de-java">Java</a></li>
<li><a href="/collections/livros-desenvolvimento-web">Desenvolvimento Web</a></li>
<li><a href="/collections/livros-de-mobile">Mobile</a></li>
<li><a href="/collections/games">Games</a></li>
<li><a href="/collections/livros-de-front-end">Front End</a></li>
</ul>
<p class="footer-title">Outros Assuntos</p>
<ul class="footer-text-links">
<li><a href="/collections/livros-de-agile">Agile</a></li>
<li><a href="/produtos/">e outros...</a></li>
</ul>
</div>
<div id="social-footer">
<!-- books-footer -->
<p class="footer-title">Links da Casa do Código</p>
<ul class="footer-text-links">
<li><a href="http://livros.casadocodigo.com.br" rel="nofollow">Meus E-books</a></li>
<li><a href="/pages/sobre-a-casa-do-codigo">Sobre a Casa do Código</a></li>
<li><a href="/pages/perguntas-frequentes">Perguntas Frequentes</a></li>
<li><a href="https://www.caelum.com.br">Caelum - Ensino e Inovação</a></li>
<li><a href="http://www.codecrushing.com/" rel="nofollow">Code Crushing</a></li>
<li><a
href="http://www.casadocodigo.com.br/pages/politica-de-privacidade" rel="nofollow">Política de Privacidade</a></li>
</ul>
<p class="footer-title">Redes Sociais</p>
<ul>
<li class="social-links"><a
href="http://www.twitter.com/casadocodigo" target="_blank" id="twitter" rel="nofollow">Facebook</a> <a
href="http://www.facebook.com/casadocodigo" target="_blank" id="facebook" rel="nofollow">Twitter</a></li>
</ul>
</div>
<div id="newsletter-footer">
<!-- social-footer -->
<p class="footer-title">Receba as Novidades e Lançamentos</p>
<div id="form-newsletter">
<form
action="" method="POST" id="ss-form" class="form-newsletter">
<ul>
<li><input type="hidden" name="pageNumber" value="0"/><input
type="hidden" name="backupCache" value=""/><input
type="email" name="entry.0.single" value="" class="ss-q-short" id="entry_0" placeholder="seu@email.com"/></li>
<li><input type="submit" name="submit"
value="Quero Receber!" id="submit-newsletter"/></li>
</ul>
</form>
<ul>
<li class="ie8"><a
href="" rel="nofollow">Receba as Novidades e Lançamentos</a></li>
</ul>
</div>
<ul class="footer-payments">
<li></li>
<li></li>
</ul>
</div>
</div>
</footer>
</body>
</html>
meu pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.casadocodigo</groupId>
<artifactId>casadocodigo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.37</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>runtime</scope>
</dependency>
<!-- Configuracao jpa e driver -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.15</version>
</dependency>
<!-- JSR 303 with Hibernate validator -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
<build>
<finalName>casadocodigo</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
meu web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"/>