Skip to content

Commit

Permalink
Fix of java-enabler and helloworld-jersey (#174)
Browse files Browse the repository at this point in the history
* TLS error handling improvement

* WIP!

* ApimlEurekaInstanceConfig

* Add missing files

* Fix problem with registering

* Remove hardcode ip value and add ui routes

* Set IBM-1047 encoding for IBM Java only on z/OS

* Set virtual hostname

* Fix greeting controller routing

* Fix routing for /application/* routes through GW

* Fix api documentation endpoint

* Fix hellospring unit tests and integration tests and remove integration-enabler-jersey reference from gradle files

* Use same style in build.gradle to be consistent with other dependencies
  • Loading branch information
taban03 committed Jan 9, 2019
1 parent 5e8a872 commit 96b0180
Show file tree
Hide file tree
Showing 38 changed files with 412 additions and 562 deletions.
1 change: 0 additions & 1 deletion Jenkinsfile
Expand Up @@ -271,7 +271,6 @@ pipeline {
archiveArtifacts artifacts: 'integration-enabler-spring-v1-sample-app/build/libs/**/*.jar'
archiveArtifacts artifacts: 'common-service-core/build/libs/**/*.jar'
archiveArtifacts artifacts: 'gateway-common/build/libs/**/*.jar'
archiveArtifacts artifacts: 'integration-enabler-jersey/build/libs/**/*.jar'
archiveArtifacts artifacts: 'scripts/apiml_cm.sh'
archiveArtifacts artifacts: 'api-layer.tar.gz'

Expand Down
Expand Up @@ -43,4 +43,4 @@ messages:
- key: apiml.common.internalRequestError
number: AML0106
type: ERROR
text: "The request to the URI '%s' has failed: %s"
text: "The request to the URI '%s' has failed: %s caused by: %s"
10 changes: 5 additions & 5 deletions docs/local-configuration.md
Expand Up @@ -85,12 +85,12 @@ If you need some more information about SSL configuration status while deploying

5. Navigate to [https://localhost:10011]([https://localhost:10011]) and check if the service is registered to the discovery service. You should be able to reach the following endpoints using HTTPS:

* [https://localhost:10011/eureka/apps/HELLOWORLD-JERSEY/localhost:helloworld-jersey:10016](https://localhost:10011/eureka/apps/HELLOWORLD-JERSEY/localhost:helloworld-jersey:10016) for metadata and service information
* [https://localhost:10016/helloworld-jersey/api-doc](https://localhost:10016/helloworld-jersey/api-doc) which contains the API documentation
* [https://localhost:10016/helloworld-jersey/application/health](https://localhost:10016/helloworld-jersey/application/health) for the health check endpoint containing the status of the application
* [https://localhost:10011/eureka/apps/HELLOJERSEY/localhost:hellojersey:10016](https://localhost:10011/eureka/apps/HELLOJERSEY/localhost:hellojersey:10016) for metadata and service information
* [https://localhost:10016/hellojersey/api-doc](https://localhost:10016/hellojersey/api-doc) which contains the API documentation
* [https://localhost:10016/hellojersey/application/health](https://localhost:10016/hellojersey/application/health) for the health check endpoint containing the status of the application
* [https://localhost:10016](https://localhost:10016) for the homepage
* [https://localhost:10016/helloworld-jersey/application/info](https://localhost:10016/helloworld-jersey/application/info) for the service informations such as hostname, port etc
* [https://localhost:10016/helloworld-jersey/v1/greeting](https://localhost:10016/helloworld-jersey/v1/greeting) for the greeting endpoint
* [https://localhost:10016/hellojersey/application/info](https://localhost:10016/hellojersey/application/info) for the service informations such as hostname, port etc
* [https://localhost:10016/hellojersey/v1/greeting](https://localhost:10016/hellojersey/v1/greeting) for the greeting endpoint

Go to the [API Catalog](https://localhost:10010/ui/v1/apicatalog) and check if the API documentation of the service is retrieved.

Expand Down
Expand Up @@ -75,7 +75,7 @@ private ResponseEntity<ApiMessage> logAndCreateReponseForInternalError(HttpServl
final int status = ErrorUtils.getErrorStatus(request);
final String errorMessage = ErrorUtils.getErrorMessage(request);
ApiMessage message = errorService.createApiMessage("apiml.common.internalRequestError", ErrorUtils.getGatewayUri(request),
ExceptionUtils.getMessage(exc));
ExceptionUtils.getMessage(exc), ExceptionUtils.getRootCauseMessage(exc));
log.error("Unresolved request error: {}", errorMessage, exc);
return ResponseEntity.status(status).body(message);
}
Expand Down
Expand Up @@ -20,7 +20,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLException;
import javax.servlet.http.HttpServletRequest;

/**
Expand All @@ -36,11 +36,11 @@ public TlsErrorCheck(ErrorService errorService) {

public ResponseEntity<ApiMessage> checkError(HttpServletRequest request, Throwable exc) {
if (exc instanceof ZuulException) {
int handshakeExceptionIndex = ExceptionUtils.indexOfType(exc, SSLHandshakeException.class);
if (handshakeExceptionIndex != -1) {
Throwable sslHandshakeException = ExceptionUtils.getThrowables(exc)[handshakeExceptionIndex];
log.debug("TLS request error: {}", sslHandshakeException.getMessage(), sslHandshakeException);
return tlsErrorResponse(request, sslHandshakeException.getMessage());
int exceptionIndex = ExceptionUtils.indexOfType(exc, SSLException.class);
if (exceptionIndex != -1) {
Throwable sslException = ExceptionUtils.getThrowables(exc)[exceptionIndex];
log.debug("TLS request error: {}", sslException.getMessage(), sslException);
return tlsErrorResponse(request, sslException.getMessage());
}
}

Expand Down
1 change: 0 additions & 1 deletion gradle/publish.gradle
Expand Up @@ -4,7 +4,6 @@ ext.springBootEnablers= [
]

ext.javaEnablers = [
'integration-enabler-jersey',
'integration-enabler-java'
]

Expand Down
8 changes: 1 addition & 7 deletions gradle/sonar.gradle
Expand Up @@ -46,12 +46,6 @@ project(":api-catalog-ui") {
}
}

// Workaround since tests don't exist
project(":integration-enabler-jersey") {
sonarqube{
skipProject = true
}
}

// Packaging project; sonar does not apply
project(":zowe-install") {
Expand All @@ -69,4 +63,4 @@ project(":integration-tests") {
property "sonar.java.binaries", "build/libs"
}
}
}
}
13 changes: 12 additions & 1 deletion gradle/versions.gradle
Expand Up @@ -43,6 +43,9 @@ ext {
springHateoasVersion = '0.23.0.RELEASE'
springRetryVersion = '1.2.2.RELEASE'
jsonUnitVersion = '1.25.0'
swaggerJerseyJaxrsVersion = '1.5.10'
jacksonDataformatYamlVersion = '2.9.7'
jerseyVersion = '2.26'

libraries = [
lombok : "org.projectlombok:lombok:${lombokVersion}",
Expand Down Expand Up @@ -120,6 +123,14 @@ ext {
apache_velocity : "org.apache.velocity:velocity-engine-core:${velocityVersion}",
snakeyaml : "org.yaml:snakeyaml:${snakeyamlVersion}",
json_unit : "net.javacrumbs.json-unit:json-unit:${jsonUnitVersion}",
json_unit_fluent : "net.javacrumbs.json-unit:json-unit-fluent:${jsonUnitVersion}"
json_unit_fluent : "net.javacrumbs.json-unit:json-unit-fluent:${jsonUnitVersion}",
swagger_jersey2_jaxrs : "io.swagger:swagger-jersey2-jaxrs:${swaggerJerseyJaxrsVersion}",
jackson_dataformat_yaml : "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonDataformatYamlVersion}",
jersey_server : "org.glassfish.jersey.core:jersey-server:${jerseyVersion}",
jersey_hk2 : "org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}",
jersey_container_servlet_core : "org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}",
jersey_media_json_jackson : "org.glassfish.jersey.media:jersey-media-json-jackson:${jerseyVersion}",
jersey_test_provider_jdk_http : "org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-jdk-http:${jerseyVersion}"

]
}
16 changes: 10 additions & 6 deletions helloworld-jersey/build.gradle
Expand Up @@ -16,16 +16,20 @@ repositories {
}

dependencies {
compile(project(':integration-enabler-jersey'))
compile(project(':integration-enabler-java'))

compile libraries.springFox
compile group: 'io.swagger', name: 'swagger-jersey2-jaxrs', version: '1.5.10'
compile libraries.jackson_dataformat_yaml
compileOnly libraries.lombok
compile libraries.logback_classic
compile group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.26'
compile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version:'2.26'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet-core', version:'2.26'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version:'2.26'
compile libraries.jersey_server
compile libraries.jersey_hk2
compile libraries.jersey_container_servlet_core
compile libraries.jersey_media_json_jackson

testCompile libraries.junit
testCompile group: 'org.glassfish.jersey.test-framework.providers', name: 'jersey-test-framework-provider-jdk-http', version: '2.26'
testCompile libraries.jersey_test_provider_jdk_http


def tomcatVersion = '8.0.39'
Expand Down
@@ -0,0 +1,36 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/
package com.ca.hwsjersey.listener;

import com.ca.mfaas.eurekaservice.client.ApiMediationClient;
import com.ca.mfaas.eurekaservice.client.config.ApiMediationServiceConfig;
import com.ca.mfaas.eurekaservice.client.impl.ApiMediationClientImpl;
import com.ca.mfaas.eurekaservice.client.util.ApiMediationServiceConfigReader;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class ApiDiscoveryListener implements ServletContextListener {
private ApiMediationClient apiMediationClient;

@Override
public void contextInitialized(ServletContextEvent sce) {
apiMediationClient = new ApiMediationClientImpl();
String configurationFile = "/service-configuration.yml";
ApiMediationServiceConfig config = new ApiMediationServiceConfigReader(configurationFile).readConfiguration();
apiMediationClient.register(config);
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
apiMediationClient.unregister();
}
}
Expand Up @@ -7,8 +7,9 @@
*
* Copyright Contributors to the Zowe Project.
*/
package com.ca.mfaas.eurekaservice;
package com.ca.hwsjersey.resource;

import com.ca.mfaas.eurekaservice.client.impl.ApiMediationClientImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,18 +30,19 @@ public class ApiDocController {
@Path("/api-doc")
@Produces(MediaType.APPLICATION_JSON)
public Response getApiDoc() {
if (Bootstrap.getApiDocEndpoint() == null) {
log.info("apidocendpoint value: " + ApiMediationClientImpl.getApiDocEndpoint());
if (ApiMediationClientImpl.getApiDocEndpoint() == null) {
throw new IllegalStateException("API Doc target endpoint is not set, API Doc cannot be accessed via /api-doc.");
}
try {
String apiDoc = client.target(Bootstrap.getApiDocEndpoint())
String apiDoc = client.target(ApiMediationClientImpl.getApiDocEndpoint())
.request()
.accept(MediaType.APPLICATION_JSON)
.get(String.class);
return Response.ok(apiDoc).build();
} catch (Exception e) {
log.error(e.getMessage(), e);
return Response.serverError().entity(e.getMessage() + ": " + Bootstrap.getApiDocEndpoint()).build();
return Response.serverError().entity(e.getMessage() + ": " + ApiMediationClientImpl.getApiDocEndpoint()).build();
}
}
}
@@ -0,0 +1,45 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/
package com.ca.hwsjersey.resource;

import com.ca.mfaas.eurekaservice.model.Health;
import com.ca.mfaas.eurekaservice.model.InstanceInfo;
import io.swagger.annotations.ApiOperation;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;


@Path("/api/v1/application")
public class DiscoveryController {

@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Send the application info",
notes = "Send a application info to the caller",
response = InstanceInfo.class)
public Object getDiscoveryInfo() {
return new HashMap<String, String>();
}

@GET
@Path("/health")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Send the health status",
notes = "Send a status greeting to the caller",
response = Health.class)
public Object getHealth() {
return new Health("UP");
}
}
Expand Up @@ -21,7 +21,7 @@
import java.util.Date;

@Api(value = "Greeting", tags = {"Greeting Controller"})
@Path("/v1")
@Path("/api/v1")
public class GreetingController {

private static final String TEMPLATE = "Hello, %s!";
Expand Down
112 changes: 0 additions & 112 deletions helloworld-jersey/src/main/resources/eureka-client.properties

This file was deleted.

0 comments on commit 96b0180

Please sign in to comment.