Last active
August 29, 2015 14:08
-
-
Save xenoterracide/66cafbc651c938aa74e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns="http://maven.apache.org/POM/4.0.0" | |
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>com.xenoterracide</groupId> | |
<artifactId>rpf</artifactId> | |
<version>0.1.0</version> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>1.1.8.RELEASE</version> | |
</parent> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-data-rest</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-data-jpa</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-logging</artifactId> | |
</dependency> | |
<!-- | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-security</artifactId> | |
</dependency> | |
--> | |
<dependency> | |
<groupId>com.h2database</groupId> | |
<artifactId>h2</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.postgresql</groupId> | |
<artifactId>postgresql</artifactId> | |
<version>9.3-1102-jdbc41</version> | |
</dependency> | |
</dependencies> | |
<properties> | |
<!-- use UTF-8 for everything --> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |
<start-class>com.xenoterracide.rpf.Application</start-class> | |
<java.version>1.8</java.version> | |
</properties> | |
<repositories> | |
<repository> | |
<id>spring-releases</id> | |
<url>http://repo.spring.io/libs-release</url> | |
</repository> | |
<repository> | |
<id>spring-milestones</id> | |
<name>Spring Milestones</name> | |
<url>http://repo.spring.io/milestone</url> | |
<snapshots> | |
<enabled>false</enabled> | |
</snapshots> | |
</repository> | |
</repositories> | |
<pluginRepositories> | |
<pluginRepository> | |
<id>spring-releases</id> | |
<url>http://repo.spring.io/libs-release</url> | |
</pluginRepository> | |
</pluginRepositories> | |
</project> |
This file contains hidden or 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
package com.xenoterracide.rpf.abstracts; | |
import org.hibernate.annotations.GenericGenerator; | |
import org.hibernate.annotations.Type; | |
import org.springframework.data.jpa.domain.AbstractPersistable; | |
import javax.persistence.Column; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
import javax.persistence.MappedSuperclass; | |
import javax.validation.constraints.NotNull; | |
import java.util.UUID; | |
@MappedSuperclass | |
public abstract class AbstractEntityBase extends AbstractPersistable<UUID> { | |
@Id | |
@NotNull | |
@Override | |
@Type(type = "pg-uuid") | |
@GeneratedValue(generator = "uuid2") | |
@GenericGenerator(name = "uuid2", strategy = "uuid2") | |
@Column(name = "task_id", columnDefinition = "uuid") | |
public UUID getId() { | |
return super.getId(); | |
} | |
} |
This file contains hidden or 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
package com.xenoterracide.rpf; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.Import; | |
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | |
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; | |
@Configuration | |
@ComponentScan | |
@EnableJpaRepositories | |
@Import(RepositoryRestMvcConfiguration.class) | |
@EnableAutoConfiguration | |
public class Application { | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
} |
This file contains hidden or 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
package com.xenoterracide.rpf.infrastructure; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.stereotype.Component; | |
import javax.servlet.*; | |
import javax.servlet.http.HttpServletResponse; | |
import java.io.IOException; | |
@Component | |
public class CORSFilter implements Filter { | |
private static final Logger log = LoggerFactory.getLogger(CORSFilter.class); | |
@Override | |
public void init(final FilterConfig filterConfig) throws ServletException { | |
} | |
@Override | |
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { | |
log.debug("request: {}", request); | |
HttpServletResponse res = (HttpServletResponse) response; | |
res.setHeader("Access-Control-Allow-Origin", "*"); | |
res.setHeader("Access-Control-Allow-", "POST, GET, PUT, OPTIONS, DELETE"); | |
res.setHeader("Access-Control-Allow-Headers", "content-type, x-requested-with"); | |
res.setHeader("Access-Control-Expose-Headers", "Location"); | |
res.setIntHeader("Access-Control-Max-Age", 3600); | |
chain.doFilter(request, response); | |
} | |
@Override | |
public void destroy() { | |
} | |
} |
This file contains hidden or 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
package com.xenoterracide.rpf.model; | |
import com.xenoterracide.rpf.abstracts.AbstractEntityBase; | |
import javax.persistence.Entity; | |
import javax.persistence.Table; | |
import javax.validation.constraints.NotNull; | |
@Entity | |
@Table(name = "characters") | |
public class Character extends AbstractEntityBase { | |
String name; | |
@NotNull | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
} |
This file contains hidden or 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
package com.xenoterracide.rpf.model; | |
import org.springframework.data.repository.PagingAndSortingRepository; | |
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | |
import java.util.UUID; | |
@RepositoryRestResource(collectionResourceRel = "characters", path = "characters") | |
public interface CharacterRepo extends PagingAndSortingRepository<Character, UUID> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment