Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Bump zalando problem libs #946

Merged
merged 26 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Upgraded dependencies
- Refactored exceptions
- Moved Problem creation to controller
- Upgraded Zalando-problem libraries

## [2.8.3] - 2018-08-01

Expand Down
15 changes: 6 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath 'org.yaml:snakeyaml:1.21'
classpath 'org.owasp:dependency-check-gradle:3.3.2'
}
}

Expand All @@ -28,6 +29,7 @@ apply plugin: 'checkstyle'
apply plugin: 'project-report'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.owasp.dependencycheck'

group 'org.zalando'
sourceCompatibility = 1.8
Expand Down Expand Up @@ -127,9 +129,9 @@ dependencies {
compile('org.zalando.stups:stups-spring-oauth2-server:1.0.22') {
exclude module: "httpclient"
}
compile 'org.zalando:jackson-datatype-problem:0.5.0'
compile 'org.zalando:problem:0.5.0'
compile 'org.zalando:problem-spring-web:0.5.0'
compile 'org.zalando:jackson-datatype-problem:0.22.0'
compile 'org.zalando:problem:0.22.0'
compile 'org.zalando:problem-spring-web:0.23.0'
compile 'com.google.guava:guava:25.1-jre'
compile 'org.slf4j:slf4j-log4j12'
compile "io.dropwizard.metrics:metrics-core:$dropwizardVersion"
Expand Down Expand Up @@ -187,11 +189,6 @@ dependencies {
}
// end::dependencies[]

// tag::wrapper[]
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}

tasks.withType(FindBugs) {
reports {
xml.enabled = false
Expand Down Expand Up @@ -265,7 +262,7 @@ task fullAcceptanceTest(type: GradleBuild) {
}

task acceptanceTest(type: Test) {
testClassesDir = sourceSets.acceptanceTest.output.classesDir
testClassesDirs = sourceSets.acceptanceTest.output
classpath = sourceSets.acceptanceTest.runtimeClasspath
maxParallelForks = Runtime.runtime.availableProcessors()
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionType=ALL
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.http.ContentType.JSON;
import static java.text.MessageFormat.format;
import static javax.ws.rs.core.HttpHeaders.CONTENT_ENCODING;
import static javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE;
import static org.springframework.http.HttpHeaders.CONTENT_ENCODING;
import static org.zalando.problem.Status.NOT_ACCEPTABLE;

public class CompressedEventPublishingAT extends BaseAT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.zalando.nakadi.repository.kafka.KafkaTestHelper;
import org.zalando.nakadi.utils.EventTypeTestBuilder;
import org.zalando.nakadi.webservice.utils.NakadiTestUtils;
import org.zalando.problem.MoreStatus;
import org.zalando.problem.Problem;

import java.io.IOException;
Expand All @@ -49,6 +48,7 @@
import static org.zalando.nakadi.utils.TestUtils.resourceAsString;
import static org.zalando.nakadi.utils.TestUtils.waitFor;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishEvent;
import static org.zalando.problem.Status.UNPROCESSABLE_ENTITY;

public class EventTypeAT extends BaseAT {

Expand Down Expand Up @@ -346,7 +346,7 @@ public void whenUpdateETAuthObjectThen422() throws Exception {
.put("/event-types/" + eventType.getName())
.then()
.statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY)
.body(equalTo(MAPPER.writer().writeValueAsString(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY,
.body(equalTo(MAPPER.writer().writeValueAsString(Problem.valueOf(UNPROCESSABLE_ENTITY,
"Changing authorization object to `null` is not possible due to existing one"))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void whenListPartitionsThenTopicNotFound() throws IOException {
.then()
.statusCode(HttpStatus.NOT_FOUND.value())
.and()
.body("detail", equalTo("topic not found"));
.body("detail", equalTo("EventType \"not-existing-topic\" does not exist."));
}

@Test
Expand Down Expand Up @@ -145,7 +145,7 @@ public void whenGetPartitionThenTopicNotFound() throws IOException {
.then()
.statusCode(HttpStatus.NOT_FOUND.value())
.and()
.body("detail", equalTo("topic not found"));
.body("detail", equalTo("EventType \"not-existing-topic\" does not exist."));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.zalando.nakadi.webservice.utils.NakadiTestUtils;
import org.zalando.nakadi.webservice.utils.TestStreamingClient;
import org.zalando.nakadi.webservice.utils.ZookeeperTestUtils;
import org.zalando.problem.MoreStatus;
import org.zalando.problem.Problem;

import java.io.IOException;
Expand Down Expand Up @@ -63,6 +62,7 @@
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishBusinessEventWithUserDefinedPartition;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishEvents;
import static org.zalando.nakadi.webservice.utils.TestStreamingClient.SESSION_ID_UNKNOWN;
import static org.zalando.problem.Status.UNPROCESSABLE_ENTITY;

public class SubscriptionAT extends BaseAT {

Expand Down Expand Up @@ -473,7 +473,7 @@ public void whenStreamDuplicatePartitionsThenUnprocessableEntity() throws IOExce
.then()
.statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY)
.body(JSON_HELPER.matchesObject(Problem.valueOf(
MoreStatus.UNPROCESSABLE_ENTITY,
UNPROCESSABLE_ENTITY,
"Duplicated partition specified")));
}

Expand All @@ -493,7 +493,7 @@ public void whenStreamWrongPartitionsThenUnprocessableEntity() throws IOExceptio
.then()
.statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY)
.body(JSON_HELPER.matchesObject(Problem.valueOf(
MoreStatus.UNPROCESSABLE_ENTITY,
UNPROCESSABLE_ENTITY,
"Wrong partitions specified - some partitions don't belong to subscription: " +
"EventTypePartition{eventType='" + et + "', partition='1'}, " +
"EventTypePartition{eventType='dummy-et-123', partition='0'}")));
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/org/zalando/nakadi/config/SecurityConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
import org.zalando.nakadi.exceptions.runtime.UnknownStatusCodeException;
import org.zalando.problem.Status;
import org.zalando.problem.StatusType;
import org.zalando.stups.oauth2.spring.security.expression.ExtendedOAuth2WebSecurityExpressionHandler;

import javax.ws.rs.core.Response;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
Expand All @@ -31,6 +33,8 @@
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.PUT;
import static org.zalando.problem.Status.INTERNAL_SERVER_ERROR;
import static org.zalando.problem.Status.UNAUTHORIZED;

@EnableResourceServer
@Configuration
Expand Down Expand Up @@ -137,24 +141,24 @@ private static class ProblemOauthMessageConverter extends MappingJackson2HttpMes

@Override
protected void writeInternal(final Object object, final HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
throws IOException, HttpMessageNotWritableException, UnknownStatusCodeException {
super.writeInternal(toJsonResponse(object), outputMessage);
}

protected Object toJsonResponse(final Object object) {
protected Object toJsonResponse(final Object object) throws UnknownStatusCodeException {
if (object instanceof OAuth2Exception) {
final OAuth2Exception oae = (OAuth2Exception) object;
if (oae.getCause() != null) {
if (oae.getCause() instanceof AuthenticationException) {
return new ProblemResponse(Response.Status.UNAUTHORIZED, oae.getCause().getMessage());
return new ProblemResponse(UNAUTHORIZED, oae.getCause().getMessage());
}
return new ProblemResponse(Response.Status.INTERNAL_SERVER_ERROR, oae.getMessage());
return new ProblemResponse(INTERNAL_SERVER_ERROR, oae.getMessage());
}

return new ProblemResponse(Response.Status.fromStatusCode(oae.getHttpErrorCode()), oae.getMessage());
return new ProblemResponse(fromStatusCode(oae.getHttpErrorCode()), oae.getMessage());
}

return new ProblemResponse(Response.Status.INTERNAL_SERVER_ERROR,
return new ProblemResponse(INTERNAL_SERVER_ERROR,
"Unrecognized error happened in authentication path");
}
}
Expand All @@ -165,7 +169,7 @@ private static class ProblemResponse {
private final int status;
private final String detail;

ProblemResponse(final Response.StatusType status, final String detail) {
ProblemResponse(final StatusType status, final String detail) {
this.type = "https://httpstatus.es/" + status.getStatusCode();
this.title = status.getReasonPhrase();
this.status = status.getStatusCode();
Expand All @@ -189,4 +193,12 @@ public String getDetail() {
}
}

private static Status fromStatusCode(final int code) throws UnknownStatusCodeException {
for (final Status status: Status.values()) {
if (status.getStatusCode() == code) {
return status;
}
}
throw new UnknownStatusCodeException("Unknown status code: " + code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.NativeWebRequest;
import org.zalando.nakadi.domain.EventType;
import org.zalando.nakadi.domain.NakadiCursor;
import org.zalando.nakadi.domain.NakadiCursorLag;
import org.zalando.nakadi.domain.ShiftedNakadiCursor;
import org.zalando.nakadi.exceptions.runtime.CursorConversionException;
import org.zalando.nakadi.exceptions.runtime.InternalNakadiException;
import org.zalando.nakadi.exceptions.runtime.InvalidCursorException;
import org.zalando.nakadi.exceptions.runtime.InvalidCursorOperation;
import org.zalando.nakadi.exceptions.runtime.NakadiBaseException;
import org.zalando.nakadi.exceptions.runtime.NoSuchEventTypeException;
import org.zalando.nakadi.exceptions.runtime.NotFoundException;
Expand All @@ -32,9 +29,6 @@
import org.zalando.nakadi.view.CursorDistance;
import org.zalando.nakadi.view.CursorLag;
import org.zalando.nakadi.view.ShiftedCursor;
import org.zalando.problem.MoreStatus;
import org.zalando.problem.Problem;
import org.zalando.problem.spring.web.advice.Responses;

import javax.validation.Valid;
import java.util.List;
Expand All @@ -43,7 +37,6 @@

import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.ResponseEntity.status;
import static org.zalando.problem.MoreStatus.UNPROCESSABLE_ENTITY;

@RestController
public class CursorOperationsController {
Expand Down Expand Up @@ -133,35 +126,6 @@ public List<CursorLag> cursorsLag(@PathVariable("eventTypeName") final String ev
.collect(Collectors.toList());
}

@ExceptionHandler(InvalidCursorOperation.class)
public ResponseEntity<?> invalidCursorOperation(final InvalidCursorOperation e,
final NativeWebRequest request) {
LOG.debug("User provided invalid cursor for operation. Reason: " + e.getReason(), e);
return Responses.create(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY,
clientErrorMessage(e.getReason())), request);
}

@ExceptionHandler(CursorConversionException.class)
public ResponseEntity<Problem> handleCursorConversionException(final CursorConversionException exception,
final NativeWebRequest request) {
LOG.error(exception.getMessage(), exception);
return Responses.create(UNPROCESSABLE_ENTITY, exception.getMessage(), request);
}

private String clientErrorMessage(final InvalidCursorOperation.Reason reason) {
switch (reason) {
case TIMELINE_NOT_FOUND: return "Timeline not found. It might happen in case the cursor refers to a " +
"timeline that has already expired.";
case PARTITION_NOT_FOUND: return "Partition not found.";
case CURSOR_FORMAT_EXCEPTION: return "Сursor format is not supported.";
case CURSORS_WITH_DIFFERENT_PARTITION: return "Cursors with different partition. Pairs of cursors should " +
"have matching partitions.";
default:
LOG.error("Unexpected invalid cursor operation reason " + reason);
throw new NakadiBaseException();
}
}

private CursorLag toCursorLag(final NakadiCursorLag nakadiCursorLag) {
return new CursorLag(
nakadiCursorLag.getPartition(),
Expand Down
Loading