Commit 19334b41 authored by Rostislav Vatolin [SLB]'s avatar Rostislav Vatolin [SLB]
Browse files

Merge branch 'handle-no-host' into 'master'

Adding handler for NoHostAvailableException

See merge request !106
parents 9db36d8b 3d3b46cf
Pipeline #64405 passed with stages
in 26 minutes and 48 seconds
......@@ -46,11 +46,11 @@ The following software have components provided under the terms of this license:
- Apache Commons Pool (from https://commons.apache.org/proper/commons-pool/)
- Apache Commons Text (from https://commons.apache.org/proper/commons-text)
- Apache Geronimo JMS Spec 2.0 (from http://geronimo.apache.org/maven/${siteId}/${version})
- Apache Groovy (from http://groovy-lang.org)
- Apache Groovy (from https://groovy-lang.org)
- Apache Groovy (from https://groovy-lang.org)
- Apache Groovy (from http://groovy-lang.org)
- Apache Groovy (from https://groovy-lang.org)
- Apache Groovy (from http://groovy-lang.org)
- Apache Groovy (from http://groovy-lang.org)
- Apache Log4j API (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api)
- Apache Log4j Core (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core)
- Apache Log4j JUL Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-jul)
......@@ -88,7 +88,7 @@ The following software have components provided under the terms of this license:
- Google Cloud Core (from https://github.com/googleapis/java-core)
- Google Cloud Core HTTP (from https://github.com/googleapis/java-core)
- Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc)
- Google Cloud Datastore (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-datastore)
- Google Cloud Datastore (from https://github.com/googleapis/java-datastore)
- Google Cloud IAM Service Account Credentials (from https://github.com/googleapis/java-iamcredentials)
- Google Cloud Key Management Service (KMS) API v1-rev9-1.22.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms)
- Google Cloud Logging (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-logging)
......@@ -112,7 +112,7 @@ The following software have components provided under the terms of this license:
- HikariCP (from https://github.com/brettwooldridge/HikariCP)
- HttpClient (from http://hc.apache.org/httpcomponents-client)
- HttpClient Cache (from http://hc.apache.org/httpcomponents-client)
- HttpCore (from http://hc.apache.org/httpcomponents-core-ga/)
- HttpCore (from http://hc.apache.org/httpcomponents-core-ga)
- IBM COS Java SDK for Amazon S3 (from https://github.com/ibm/ibm-cos-sdk-java)
- IBM COS Java SDK for COS KMS (from https://github.com/ibm/ibm-cos-sdk-java)
- IBM COS SDK For Java (from https://github.com/ibm/ibm-cos-sdk-java)
......@@ -138,11 +138,11 @@ The following software have components provided under the terms of this license:
- Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-jackson2)
- Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-jackson2)
- Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary)
- Jackson datatype: JSR310 (from http://wiki.fasterxml.com/JacksonModuleJSR310)
- Jackson datatype: JSR310 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310)
- Jackson datatype: jdk8 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8)
- Jackson extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-jackson)
- Jackson module: Afterburner (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: JAXB-annotations (from http://github.com/FasterXML/jackson-module-jaxb-annotations)
- Jackson module: JAXB Annotations (from https://github.com/FasterXML/jackson-modules-base)
- Jackson-annotations (from http://github.com/FasterXML/jackson)
- Jackson-core (from https://github.com/FasterXML/jackson-core)
- Jackson-dataformat-XML (from http://wiki.fasterxml.com/JacksonExtensionXmlDataBinding)
......@@ -151,10 +151,10 @@ The following software have components provided under the terms of this license:
- Jackson-module-parameter-names (from https://repo1.maven.org/maven2/com/fasterxml/jackson/module/jackson-module-parameter-names)
- Jakarta Bean Validation API (from https://beanvalidation.org)
- Jakarta Expression Language Implementation (from https://projects.eclipse.org/projects/ee4j.el)
- Jakarta Servlet (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java Native Access (from https://github.com/java-native-access/jna)
- Java Native Access Platform (from https://github.com/java-native-access/jna)
- Java Servlet 4.0 API (from )
- Java Servlet API (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java UUID Generator (from http://wiki.fasterxml.com/JugHome)
- JavaPoet (from http://github.com/square/javapoet/)
- Javassist (from http://www.javassist.org/)
......@@ -208,17 +208,13 @@ The following software have components provided under the terms of this license:
- Objenesis (from http://objenesis.org)
- Objenesis (from http://objenesis.org)
- OkHttp Logging Interceptor (from https://repo1.maven.org/maven2/com/squareup/okhttp3/logging-interceptor)
- Okio (from https://github.com/square/okio/)
- Okio (from https://repo1.maven.org/maven2/com/squareup/okio/okio)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- PWDB :: Database (from https://repo1.maven.org/maven2/org/linguafranca/pwdb/database)
- PowerMock (from http://www.powermock.org)
- PowerMock (from http://www.powermock.org)
- PowerMock (from http://www.powermock.org)
- PowerMock (from http://www.powermock.org)
- PowerMock (from http://www.powermock.org)
- Protocol Buffer extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-protobuf)
- Proton-J (from https://repo1.maven.org/maven2/org/apache/qpid/proton-j)
- QpidJMS Client (from )
......@@ -234,6 +230,7 @@ The following software have components provided under the terms of this license:
- Spring Beans (from https://github.com/spring-projects/spring-framework)
- Spring Boot Data JDBC Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-data-jdbc)
- Spring Boot Tomcat Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-tomcat)
- Spring Boot Undertow Starter (from http://projects.spring.io/spring-boot/)
- Spring Commons Logging Bridge (from https://github.com/spring-projects/spring-framework)
- Spring Context (from https://github.com/spring-projects/spring-framework)
- Spring Core (from https://github.com/spring-projects/spring-framework)
......@@ -268,7 +265,6 @@ The following software have components provided under the terms of this license:
- asm (from http://asm.ow2.io/)
- boto3 (from https://github.com/boto/boto3)
- botocore (from https://github.com/boto/botocore)
- com.google.api.grpc:proto-google-cloud-datastore-v1 (from https://github.com/googleapis/googleapis)
- com.google.api.grpc:proto-google-cloud-monitoring-v3 (from https://github.com/googleapis/googleapis)
- datastore-v1-proto-client (from https://repo1.maven.org/maven2/com/google/cloud/datastore/datastore-v1-proto-client)
- embedded-redis (from https://github.com/ozimov/embedded-redis)
......@@ -305,12 +301,17 @@ The following software have components provided under the terms of this license:
- org.apiguardian:apiguardian-api (from https://github.com/apiguardian-team/apiguardian)
- org.conscrypt:conscrypt-openjdk-uber (from https://conscrypt.org/)
- org.opentest4j:opentest4j (from https://github.com/ota4j-team/opentest4j)
- org.xmlunit:xmlunit-core (from https://www.xmlunit.org/)
- org.xmlunit:xmlunit-core (from http://www.xmlunit.org/)
- perfmark:perfmark-api (from https://github.com/perfmark/perfmark)
- pgdjbc Postgresql-jre7 (from https://jdbc.postgresql.org)
- picocli - a mighty tiny Command Line Interface (from http://picocli.info)
- powermock-api-support (from https://repo1.maven.org/maven2/org/powermock/powermock-api-support)
- powermock-core (from http://www.powermock.org)
- powermock-module-junit4 (from http://www.powermock.org)
- powermock-module-junit4-common (from https://repo1.maven.org/maven2/org/powermock/powermock-module-junit4-common)
- powermock-reflect (from https://repo1.maven.org/maven2/org/powermock/powermock-reflect)
- project ':json-path' (from https://github.com/jayway/JsonPath)
- proto-google-cloud-datastore-v1 (from https://github.com/googleapis/java-datastore/proto-google-cloud-datastore-v1)
- proto-google-cloud-iamcredentials-v1 (from https://github.com/googleapis/java-iamcredentials/proto-google-cloud-iamcredentials-v1)
- proto-google-cloud-logging-v2 (from https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2)
- proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/java-pubsub/proto-google-cloud-pubsub-v1)
......@@ -344,7 +345,6 @@ The following software have components provided under the terms of this license:
- spring-boot-starter-logging (from https://spring.io/projects/spring-boot)
- spring-boot-starter-security (from https://spring.io/projects/spring-boot)
- spring-boot-starter-test (from https://spring.io/projects/spring-boot)
- spring-boot-starter-undertow (from https://spring.io/projects/spring-boot)
- spring-boot-starter-validation (from https://spring.io/projects/spring-boot)
- spring-boot-starter-web (from https://spring.io/projects/spring-boot)
- spring-boot-test (from https://spring.io/projects/spring-boot)
......@@ -511,8 +511,8 @@ The following software have components provided under the terms of this license:
- JUnit Platform Engine API (from https://junit.org/junit5/)
- Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca)
- Jakarta Expression Language Implementation (from https://projects.eclipse.org/projects/ee4j.el)
- Jakarta Servlet (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java Servlet 4.0 API (from )
- Java Servlet API (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java(TM) API for WebSocket (from https://repo1.maven.org/maven2/org/jboss/spec/javax/websocket/jboss-websocket-api_1.1_spec)
- Logback Classic Module (from https://repo1.maven.org/maven2/ch/qos/logback/logback-classic)
- Logback Contrib :: JSON :: Classic (from https://repo1.maven.org/maven2/ch/qos/logback/contrib/logback-json-classic)
......@@ -539,8 +539,8 @@ The following software have components provided under the terms of this license:
- JUnit Platform Engine API (from https://junit.org/junit5/)
- Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca)
- Jakarta Expression Language Implementation (from https://projects.eclipse.org/projects/ee4j.el)
- Jakarta Servlet (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java Servlet 4.0 API (from )
- Java Servlet API (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java(TM) API for WebSocket (from https://repo1.maven.org/maven2/org/jboss/spec/javax/websocket/jboss-websocket-api_1.1_spec)
========================================================================
......@@ -570,8 +570,8 @@ The following software have components provided under the terms of this license:
- Common Annotations 1.3 API (from )
- Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca)
- Jakarta Expression Language Implementation (from https://projects.eclipse.org/projects/ee4j.el)
- Jakarta Servlet (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java Servlet 4.0 API (from )
- Java Servlet API (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java(TM) API for WebSocket (from https://repo1.maven.org/maven2/org/jboss/spec/javax/websocket/jboss-websocket-api_1.1_spec)
- JavaBeans Activation Framework (from )
- javax.annotation-api (from http://jcp.org/en/jsr/detail?id=250)
......@@ -586,8 +586,8 @@ The following software have components provided under the terms of this license:
- Common Annotations 1.3 API (from )
- Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca)
- Jakarta Expression Language Implementation (from https://projects.eclipse.org/projects/ee4j.el)
- Jakarta Servlet (from https://projects.eclipse.org/projects/ee4j.servlet)
- Java Servlet 4.0 API (from )
- Java Servlet API (from https://projects.eclipse.org/projects/ee4j.servlet)
- Project Lombok (from https://projectlombok.org)
- Project Lombok (from https://projectlombok.org)
......
package org.opengroup.osdu.entitlements.v2.azure.error;
import org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
@ControllerAdvice
public class AzureExceptionHandler extends ResponseEntityExceptionHandler {
@Autowired
private JaxRsDpsLog jaxRsDpsLog;
@ExceptionHandler(value = {NoHostAvailableException.class})
public ResponseEntity<AppError> handleNoHostAvailableException(Exception e){
AppError appError = AppError.builder()
.code(HttpStatus.SERVICE_UNAVAILABLE.value())
.message("No available upstream host, please contact support team")
.build();
jaxRsDpsLog.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE.value()).body(appError);
}
}
package org.opengroup.osdu.entitlements.v2.azure.error;
import org.apache.tinkerpop.gremlin.driver.exception.NoHostAvailableException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppError;
import org.springframework.http.ResponseEntity;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(MockitoJUnitRunner.class)
public class AzureExceptionHandlerTest {
@Mock
private JaxRsDpsLog jaxRsDpsLog;
@InjectMocks
private AzureExceptionHandler azureExceptionHandler;
@Test
public void shouldReturnNoHostAvailableException(){
NoHostAvailableException exception = new NoHostAvailableException();
ResponseEntity<AppError> response = azureExceptionHandler.handleNoHostAvailableException(exception);
assertEquals(503, response.getStatusCodeValue());
assertNotNull(response.getBody());
AppError body = response.getBody();
assertEquals(503, body.getCode());
assertEquals("No available upstream host, please contact support team", body.getMessage());
Mockito.verify(jaxRsDpsLog).error(exception.getMessage(), exception);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment