Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerstolzenberg committed Apr 23, 2014
0 parents commit 83bf923
Show file tree
Hide file tree
Showing 15 changed files with 769 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
*.iml
.gradle/
164 changes: 164 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
buildscript {
repositories {
maven() {
url "https://ci.it.ewerk.com/nexus/content/groups/public"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.1.RELEASE")

/*
* This configuration works. I can run 'gradle pitest' without problems. I also
* can run 'gradle bootRun' without problems.
*
* URL: http://localhost:8080/dashboard/index.html -> OK
* URL: http://localhost:8080/dashboard/api/greeting -> OK
*/
classpath("info.solidsoft.gradle.pitest:gradle-pitest-plugin:0.32.0") {
exclude group: "org.pitest"
}
classpath "org.pitest:pitest-command-line:0.33"

/*
* Commenting out lines 17-20 and using 0.33.0-SNAPSHOT of the plugin breaks the build
*
* - pitest tasks is working
* - I cannot start the application because the configuration file is no more picked up.
* - moving the application.properties to project root folder workarounds this,
* but logging config is missing
*
* URL: http://localhost:8080/dashboard/index.html -> NOT_FOUND
* URL: http://localhost:8080/dashboard/api/greeting -> STILL OK
*
* It turns out the the pitest SNAPSHOT plugin somehow scrambles the builds setup, the whole
* 'src/main/resources' folder seems to be ignored and no more recognised by spring-boot. So
* all static resources are missing within the deployment.
*
* I do not think this is an issue with the spring-boot-gradle-plugin (not sure though), as
* with gradle-pitest-plugin-0.32.0 everything is working fine.
*/
//classpath("info.solidsoft.gradle.pitest:gradle-pitest-plugin:0.33.0-SNAPSHOT")
}
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: "pitest"
apply plugin: 'spring-boot'

configurations {
all*.exclude(group: "commons-logging")
all*.exclude(group: "joda-time")
}

ext {
sourceCompatibility = 1.8
targetCompatibility = 1.8

assertjVersion = "1.5.0"
flywayGradleVersion = "2.3.1"
guavaVersion = "16.0.1"
hibernateVersion = "4.3.4.Final"
hibernateValidatorVersion = "5.1.0.Final"
hikariVersion = "1.3.5"
jacksonVersion = "2.3.1"
jettyVersion = "9.1.4.v20140401"
logbackVersion = "1.1.1"
mockitoVersion = "1.9.5"
mysqlVersion = "5.1.29"
pitestPluginVersion = "0.32.0"
queryDslVersion = "3.3.1"
slf4jVersion = "1.7.6"
springVersion = "4.0.3.RELEASE"
springBootVersion = "1.0.1.RELEASE"
springDataCommonsVersion = "1.7.1.RELEASE"
springDataJpaVersion = "1.5.2.RELEASE"
springSecurityVersion = "3.2.3.RELEASE"
testngVersion = "6.8.8"
validationVersion = "1.1.0.Final"
}

repositories {
mavenCentral()
}

dependencies {
// Spring Framework
compile "org.springframework:spring-aspects:" + springVersion
compile "org.springframework:spring-jdbc:" + springVersion
compile "org.springframework:spring-orm:" + springVersion
compile "org.springframework:spring-tx:" + springVersion
compile "org.springframework:spring-webmvc:" + springVersion

// Spring Security
compile("org.springframework.security:spring-security-web:" + springSecurityVersion) {
exclude group: "org.springframework"
}
compile("org.springframework.security:spring-security-config:" + springSecurityVersion) {
exclude group: "org.springframework"
}

// Spring boot
compile("org.springframework.boot:spring-boot-starter:" + springBootVersion) {
exclude module: "spring-boot-starter-logging"
}
compile("org.springframework.boot:spring-boot-starter-jetty:" + springBootVersion) {
exclude group: "org.eclipse.jetty"
}

// JSR-303
compile "javax.validation:validation-api:" + validationVersion
compile "org.hibernate:hibernate-validator:" + hibernateValidatorVersion

// Guava
compile "com.google.guava:guava:" + guavaVersion

// Jetty9
compile "org.eclipse.jetty:jetty-webapp:" + jettyVersion
compile "org.eclipse.jetty:jetty-jsp:" + jettyVersion

// Logging Stack
compile "org.slf4j:slf4j-api:" + slf4jVersion
compile "org.slf4j:jcl-over-slf4j:" + slf4jVersion
compile "org.slf4j:log4j-over-slf4j:" + slf4jVersion
compile "org.slf4j:jul-to-slf4j:" + slf4jVersion
compile "ch.qos.logback:logback-classic:" + logbackVersion

// Jackson
compile "com.fasterxml.jackson.core:jackson-databind:" + jacksonVersion
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:" + jacksonVersion
//compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate4:" + jacksonVersion

// Testing
compile "org.testng:testng:" + testngVersion
compile "org.mockito:mockito-core:" + mockitoVersion
compile "org.assertj:assertj-core:" + assertjVersion
}

jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}

test {
useTestNG()

minHeapSize = "128m"
maxHeapSize = "512m"
}

pitest {
targetClasses = ['com.company.hello.*']
threads = 6
}

jar {
manifest {
attributes(
"Implementation-Title": "com.company.hello",
"Implementation-Version": version,
"Built-JDK": System.getProperty("java.version"),
"Built-Gradle": gradle.gradleVersion
)
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/company/hello/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.company.hello;

import com.company.hello.security.SecurityConfiguration;
import com.company.hello.web.WebConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@ComponentScan
@EnableAutoConfiguration(
exclude = {MessageSourceAutoConfiguration.class, BatchAutoConfiguration.class})
@Import({WebConfiguration.class, SecurityConfiguration.class})
public class Application {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(Application.class);
application.setShowBanner(false);
application.setHeadless(true);
application.setRegisterShutdownHook(true);
application.setWebEnvironment(true);
application.setLogStartupInfo(true);
application.run(args);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/company/hello/api/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.company.hello.api;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/api", produces = "text/plain")
@RestController
public class HelloController {

@RequestMapping("/greeting")
public String greeting() {
return "Greetings from Spring Boot!";
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/company/hello/security/HttpError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.company.hello.security;

import com.company.hello.util.Arguments;
import com.google.common.base.Objects;

public class HttpError {
private final int httpStatus;

private final String errorMessage;

public HttpError(final int httpStatus, final String errorMessage) {
Arguments.greaterThan("httpStatus", httpStatus, 0);

this.httpStatus = httpStatus;
this.errorMessage = errorMessage;
}

public int getHttpStatus() {
return httpStatus;
}

public String getErrorMessage() {
return errorMessage;
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("httpStatus", httpStatus)
.add("errorMessage", errorMessage)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.company.hello.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {

static final int UNAUTHORIZED = HttpStatus.UNAUTHORIZED.value();

private final ObjectMapper objectMapper;

public RestAuthenticationEntryPoint(final ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

@Override
public void commence(@NotNull final HttpServletRequest request,
@NotNull final HttpServletResponse response, final AuthenticationException authException)
throws IOException, ServletException {

String message = "No authentication exception provided. This is an unexpected error.";
if (authException != null) {
message = authException.getMessage();
}

HttpError error = new HttpError(UNAUTHORIZED, message);

final String data = objectMapper.writeValueAsString(error);

response.setContentType("application/json;charset=UTF-8");
response.setStatus(error.getHttpStatus());
response.setContentLength(data.length());
response.getWriter().print(data);
response.getWriter().flush();
}
}
Loading

0 comments on commit 83bf923

Please sign in to comment.