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 CorsFilter extends OncePerRequestFilter { | |
@Override | |
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | |
throws ServletException, IOException { | |
if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) { | |
// CORS "pre-flight" request | |
response.addHeader("Access-Control-Allow-Origin", "*"); | |
response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); | |
response.addHeader("Access-Control-Allow-Headers", "Content-Type"); |
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 | |
@RequestMapping("/employee") | |
public class EmployeeController { | |
private static ConcurrentHashMap<Long, Employee> employees = new ConcurrentHashMap<Long, Employee>(); | |
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = { "application/json" }) | |
public ResponseEntity<Employee> update(@RequestBody Employee employee, @PathVariable long id) { | |
if (employee.getId() != id) { | |
throw new IdNotMatchException(); | |
} | |
employees.put(id, employee); |
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 CorsFilter extends OncePerRequestFilter { | |
@Override | |
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | |
throws ServletException, IOException { | |
response.addHeader("Access-Control-Allow-Origin", "*"); | |
if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) { | |
// CORS "pre-flight" request |
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 = "/{id}", method = RequestMethod.PUT, consumes = { "application/json" }) | |
@ResponseStatus(HttpStatus.OK) | |
public void update(@RequestBody Employee employee, @PathVariable long id) { | |
if (employee.getId() != id) { | |
throw new IdNotMatchException(); | |
} | |
employees.put(id, employee); | |
} |
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
<dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-mxj</artifactId> | |
<version>5.0.12</version> | |
<scope>test</scope> | |
</dependency> |
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
import java.io.IOException; | |
import org.apache.commons.io.FileUtils; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.jdbc.datasource.DriverManagerDataSource; | |
import com.mysql.management.MysqldResource; | |
public class EmbeddedMysqlDatabase extends DriverManagerDataSource { |
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
import java.io.File; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Random; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.core.io.DefaultResourceLoader; | |
import org.springframework.core.io.ResourceLoader; | |
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; |
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
import javax.sql.DataSource; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
public class EmbeddedDataSourceConfig implements DataSourceConfig { | |
@Override | |
@Bean(destroyMethod="shutdown") |
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
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.assertNull; | |
import static org.junit.Assert.assertThat; | |
import javax.sql.DataSource; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; |
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
<dependency> | |
<groupId>com.fasterxml.jackson.jaxrs</groupId> | |
<artifactId>jackson-jaxrs-json-provider</artifactId> | |
<version>2.2.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.amqp</groupId> | |
<artifactId>spring-rabbit</artifactId> | |
<version>1.2.0.RELEASE</version> | |
</dependency> |
OlderNewer