Merge branch 'DEVELOP_BE' of ssh://172.18.22.160:29418/Dropwizard/Microservices/mics-central-service into DEVELOP_BE
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..120a6d2
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,284 @@
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License 2.0 which is available at
+http://www.eclipse.org/legal/epl-2.0, or the Apache Software License
+2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0.
+
+_______________________________________________________________________
+Eclipse Public License - v 2.0
+
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+ PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
+ OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+ a) in the case of the initial Contributor, the initial content
+ Distributed under this Agreement, and
+
+ b) in the case of each subsequent Contributor:
+ i) changes to the Program, and
+ ii) additions to the Program;
+ where such changes and/or additions to the Program originate from
+ and are Distributed by that particular Contributor. A Contribution
+ "originates" from a Contributor if it was added to the Program by
+ such Contributor itself or anyone acting on such Contributor's behalf.
+ Contributions do not include changes or additions to the Program that
+ are not Modified Works.
+
+"Contributor" means any person or entity that Distributes the Program.
+
+"Licensed Patents" mean patent claims licensable by a Contributor which
+are necessarily infringed by the use or sale of its Contribution alone
+or when combined with the Program.
+
+"Program" means the Contributions Distributed in accordance with this
+Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement
+or any Secondary License (as applicable), including Contributors.
+
+"Derivative Works" shall mean any work, whether in Source Code or other
+form, that is based on (or derived from) the Program and for which the
+editorial revisions, annotations, elaborations, or other modifications
+represent, as a whole, an original work of authorship.
+
+"Modified Works" shall mean any work in Source Code or other form that
+results from an addition to, deletion from, or modification of the
+contents of the Program, including, for purposes of clarity any new file
+in Source Code form that contains any contents of the Program. Modified
+Works shall not include works that contain only declarations,
+interfaces, types, classes, structures, or files of the Program solely
+in each case in order to link to, bind by name, or subclass the Program
+or Modified Works thereof.
+
+"Distribute" means the acts of a) distributing or b) making available
+in any manner that enables the transfer of a copy.
+
+"Source Code" means the form of a Program preferred for making
+modifications, including but not limited to software source code,
+documentation source, and configuration files.
+
+"Secondary License" means either the GNU General Public License,
+Version 2.0, or any later versions of that license, including any
+exceptions or additional permissions as identified by the initial
+Contributor.
+
+2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby
+ grants Recipient a non-exclusive, worldwide, royalty-free copyright
+ license to reproduce, prepare Derivative Works of, publicly display,
+ publicly perform, Distribute and sublicense the Contribution of such
+ Contributor, if any, and such Derivative Works.
+
+ b) Subject to the terms of this Agreement, each Contributor hereby
+ grants Recipient a non-exclusive, worldwide, royalty-free patent
+ license under Licensed Patents to make, use, sell, offer to sell,
+ import and otherwise transfer the Contribution of such Contributor,
+ if any, in Source Code or other form. This patent license shall
+ apply to the combination of the Contribution and the Program if, at
+ the time the Contribution is added by the Contributor, such addition
+ of the Contribution causes such combination to be covered by the
+ Licensed Patents. The patent license shall not apply to any other
+ combinations which include the Contribution. No hardware per se is
+ licensed hereunder.
+
+ c) Recipient understands that although each Contributor grants the
+ licenses to its Contributions set forth herein, no assurances are
+ provided by any Contributor that the Program does not infringe the
+ patent or other intellectual property rights of any other entity.
+ Each Contributor disclaims any liability to Recipient for claims
+ brought by any other entity based on infringement of intellectual
+ property rights or otherwise. As a condition to exercising the
+ rights and licenses granted hereunder, each Recipient hereby
+ assumes sole responsibility to secure any other intellectual
+ property rights needed, if any. For example, if a third party
+ patent license is required to allow Recipient to Distribute the
+ Program, it is Recipient's responsibility to acquire that license
+ before distributing the Program.
+
+ d) Each Contributor represents that to its knowledge it has
+ sufficient copyright rights in its Contribution, if any, to grant
+ the copyright license set forth in this Agreement.
+
+ e) Notwithstanding the terms of any Secondary License, no
+ Contributor makes additional grants to any Recipient (other than
+ those set forth in this Agreement) as a result of such Recipient's
+ receipt of the Program under the terms of a Secondary License
+ (if permitted under the terms of Section 3).
+
+3. REQUIREMENTS
+
+3.1 If a Contributor Distributes the Program in any form, then:
+
+ a) the Program must also be made available as Source Code, in
+ accordance with section 3.2, and the Contributor must accompany
+ the Program with a statement that the Source Code for the Program
+ is available under this Agreement, and informs Recipients how to
+ obtain it in a reasonable manner on or through a medium customarily
+ used for software exchange; and
+
+ b) the Contributor may Distribute the Program under a license
+ different than this Agreement, provided that such license:
+ i) effectively disclaims on behalf of all other Contributors all
+ warranties and conditions, express and implied, including
+ warranties or conditions of title and non-infringement, and
+ implied warranties or conditions of merchantability and fitness
+ for a particular purpose;
+
+ ii) effectively excludes on behalf of all other Contributors all
+ liability for damages, including direct, indirect, special,
+ incidental and consequential damages, such as lost profits;
+
+ iii) does not attempt to limit or alter the recipients' rights
+ in the Source Code under section 3.2; and
+
+ iv) requires any subsequent distribution of the Program by any
+ party to be under a license that satisfies the requirements
+ of this section 3.
+
+3.2 When the Program is Distributed as Source Code:
+
+ a) it must be made available under this Agreement, or if the
+ Program (i) is combined with other material in a separate file or
+ files made available under a Secondary License, and (ii) the initial
+ Contributor attached to the Source Code the notice described in
+ Exhibit A of this Agreement, then the Program may be made available
+ under the terms of such Secondary Licenses, and
+
+ b) a copy of this Agreement must be included with each copy of
+ the Program.
+
+3.3 Contributors may not remove or alter any copyright, patent,
+trademark, attribution notices, disclaimers of warranty, or limitations
+of liability ("notices") contained within the Program from any copy of
+the Program which they Distribute, provided that Contributors may add
+their own appropriate notices.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities
+with respect to end users, business partners and the like. While this
+license is intended to facilitate the commercial use of the Program,
+the Contributor who includes the Program in a commercial product
+offering should do so in a manner which does not create potential
+liability for other Contributors. Therefore, if a Contributor includes
+the Program in a commercial product offering, such Contributor
+("Commercial Contributor") hereby agrees to defend and indemnify every
+other Contributor ("Indemnified Contributor") against any losses,
+damages and costs (collectively "Losses") arising from claims, lawsuits
+and other legal actions brought by a third party against the Indemnified
+Contributor to the extent caused by the acts or omissions of such
+Commercial Contributor in connection with its distribution of the Program
+in a commercial product offering. The obligations in this section do not
+apply to any claims or Losses relating to any actual or alleged
+intellectual property infringement. In order to qualify, an Indemnified
+Contributor must: a) promptly notify the Commercial Contributor in
+writing of such claim, and b) allow the Commercial Contributor to control,
+and cooperate with the Commercial Contributor in, the defense and any
+related settlement negotiations. The Indemnified Contributor may
+participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those performance
+claims and warranties, and if a court requires any other Contributor to
+pay any damages as a result, the Commercial Contributor must pay
+those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
+PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS"
+BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
+IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF
+TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
+PURPOSE. Each Recipient is solely responsible for determining the
+appropriateness of using and distributing the Program and assumes all
+risks associated with its exercise of rights under this Agreement,
+including but not limited to the risks and costs of program errors,
+compliance with applicable laws, damage to or loss of data, programs
+or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
+PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS
+SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
+PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
+EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further
+action by the parties hereto, such provision shall be reformed to the
+minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that the
+Program itself (excluding combinations of the Program with other software
+or hardware) infringes such Recipient's patent(s), then such Recipient's
+rights granted under Section 2(b) shall terminate as of the date such
+litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of
+time after becoming aware of such noncompliance. If all Recipient's
+rights under this Agreement terminate, Recipient agrees to cease use
+and distribution of the Program as soon as reasonably practicable.
+However, Recipient's obligations under this Agreement and any licenses
+granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement,
+but in order to avoid inconsistency the Agreement is copyrighted and
+may only be modified in the following manner. The Agreement Steward
+reserves the right to publish new versions (including revisions) of
+this Agreement from time to time. No one other than the Agreement
+Steward has the right to modify this Agreement. The Eclipse Foundation
+is the initial Agreement Steward. The Eclipse Foundation may assign the
+responsibility to serve as the Agreement Steward to a suitable separate
+entity. Each new version of the Agreement will be given a distinguishing
+version number. The Program (including Contributions) may always be
+Distributed subject to the version of the Agreement under which it was
+received. In addition, after a new version of the Agreement is published,
+Contributor may elect to Distribute the Program (including its
+Contributions) under the new version.
+
+Except as expressly stated in Sections 2(a) and 2(b) above, Recipient
+receives no rights or licenses to the intellectual property of any
+Contributor under this Agreement, whether expressly, by implication,
+estoppel or otherwise. All rights in the Program not expressly granted
+under this Agreement are reserved. Nothing in this Agreement is intended
+to be enforceable by any entity that is not a Contributor or Recipient.
+No third-party beneficiary rights are created under this Agreement.
+
+Exhibit A - Form of Secondary Licenses Notice
+
+"This Source Code may also be made available under the following
+Secondary Licenses when the conditions for such availability set forth
+in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
+version(s), and exceptions or additional permissions here}."
+
+ Simply including a copy of this Agreement, including this Exhibit A
+ is not sufficient to license the Source Code under Secondary Licenses.
+
+ If it is not possible or desirable to put the notice in a particular
+ file, then You may include the notice in a location (such as a LICENSE
+ file in a relevant directory) where a recipient would be likely to
+ look for such a notice.
+
+ You may add additional accurate notices of copyright ownership.
+
diff --git a/pom.xml b/pom.xml
index 5b7c1c0..ecfb9ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
<maven>3.0.0</maven>
</prerequisites>
- <groupId>pta.de</groupId>
+ <groupId>org.eclipse.openk</groupId>
<artifactId>mics-central-service</artifactId>
<version>0.1.3-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -21,7 +21,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>1.2.0</dropwizard.version>
- <mainClass>pta.de.MicsCentralApplication</mainClass>
+ <mainClass>org.eclipse.openK.MicsCentralApplication</mainClass>
<easymock.version>3.4</easymock.version>
<powermock-api-easymock.version>1.6.6</powermock-api-easymock.version>
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
diff --git a/serviceConfigDevLocal_MASTER.yml b/serviceConfigDevLocal_MASTER.yml
index 59921dc..e27524c 100644
--- a/serviceConfigDevLocal_MASTER.yml
+++ b/serviceConfigDevLocal_MASTER.yml
@@ -1,4 +1,4 @@
-servicesDistributionFileName: servicesDistributionDevLocal.json
+servicesDistributionFileName: servicesDistributionDevServer.json
logging:
@@ -12,7 +12,7 @@
archivedFileCount: 5
timeZone: UTC
loggers:
- pta: DEBUG
+ pta: INFO
org.eclipse.jetty.servlets: DEBUG
server:
diff --git a/src/main/java/pta/de/MicsCentralApplication.java b/src/main/java/org/eclipse/openK/MicsCentralApplication.java
similarity index 78%
rename from src/main/java/pta/de/MicsCentralApplication.java
rename to src/main/java/org/eclipse/openK/MicsCentralApplication.java
index b37fe22..a3c7166 100644
--- a/src/main/java/pta/de/MicsCentralApplication.java
+++ b/src/main/java/org/eclipse/openK/MicsCentralApplication.java
@@ -1,13 +1,25 @@
-package pta.de;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK;
import com.codahale.metrics.health.HealthCheck;
import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.eclipse.jetty.servlets.CrossOriginFilter;
-import pta.de.core.controller.InitServicesConfigCacheJob;
-import pta.de.health.ConfigFilePresentHealthCheck;
-import pta.de.resources.MicsCentralResource;
+import org.eclipse.openK.core.controller.InitServicesConfigCacheJob;
+import org.eclipse.openK.health.ConfigFilePresentHealthCheck;
+import org.eclipse.openK.resources.MicsCentralResource;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
diff --git a/src/main/java/org/eclipse/openK/MicsCentralConfiguration.java b/src/main/java/org/eclipse/openK/MicsCentralConfiguration.java
new file mode 100644
index 0000000..5fb7850
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/MicsCentralConfiguration.java
@@ -0,0 +1,32 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK;
+
+import io.dropwizard.Configuration;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.hibernate.validator.constraints.*;
+
+public class MicsCentralConfiguration extends Configuration {
+ @NotEmpty
+ private String servicesDistributionFileName;
+
+ @JsonProperty
+ public String getServicesDistributionFileName() {
+ return servicesDistributionFileName;
+ }
+
+ @JsonProperty
+ public void setServicesDistributionFileName(String servicesDistributionFileName) {
+ this.servicesDistributionFileName = servicesDistributionFileName;
+ }
+}
diff --git a/src/main/java/pta/de/api/ServiceDistributionCluster.java b/src/main/java/org/eclipse/openK/api/ServiceDistributionCluster.java
similarity index 87%
rename from src/main/java/pta/de/api/ServiceDistributionCluster.java
rename to src/main/java/org/eclipse/openK/api/ServiceDistributionCluster.java
index 8a37f28..8a7acb3 100644
--- a/src/main/java/pta/de/api/ServiceDistributionCluster.java
+++ b/src/main/java/org/eclipse/openK/api/ServiceDistributionCluster.java
@@ -1,4 +1,16 @@
-package pta.de.api;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.api;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotEmpty;
diff --git a/src/main/java/org/eclipse/openK/api/ServiceRequestEnvelope.java b/src/main/java/org/eclipse/openK/api/ServiceRequestEnvelope.java
new file mode 100644
index 0000000..9ade421
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/api/ServiceRequestEnvelope.java
@@ -0,0 +1,114 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.api;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.glassfish.jersey.internal.util.Base64;
+
+public class ServiceRequestEnvelope {
+ public static class HttpHeader {
+ private String attribute;
+ private String value;
+
+ public String getAttribute() {
+ return attribute;
+ }
+
+ public void setAttribute(String attribute) {
+ this.attribute = attribute;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+ private String serviceName;
+ private boolean isHttps;
+ private String method;
+ private String uriFragment;
+ private String payload;
+ private HttpHeader[] headers;
+
+ @JsonProperty
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ @JsonProperty
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ @JsonProperty
+ public boolean isHttps() {
+ return isHttps;
+ }
+
+ @JsonProperty
+ public void setHttps(boolean https) {
+ isHttps = https;
+ }
+
+ @JsonProperty
+ public String getMethod() {
+ return method;
+ }
+
+ @JsonProperty
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+ @JsonProperty
+ public String getUriFragment() {
+ return uriFragment;
+ }
+
+ @JsonProperty
+ public void setUriFragment(String uriFragment) {
+ this.uriFragment = uriFragment;
+ }
+
+ @JsonProperty
+ public String getPayload() {
+ return payload;
+ }
+
+ @JsonProperty
+ public void setPayload(String payload) {
+ this.payload = payload;
+ }
+
+ @JsonProperty
+ public HttpHeader[] getHeaders() {
+ return headers;
+ }
+
+ @JsonProperty
+ public void setHeaders(HttpHeader[] headers) {
+ this.headers = headers;
+ }
+
+ public String getPayloadDecode() {
+ return Base64.decodeAsString(payload);
+ }
+
+ public void setPayloadEncode(String payload) {
+ this.payload = Base64.encodeAsString(payload);
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/api/VersionInfo.java b/src/main/java/org/eclipse/openK/api/VersionInfo.java
new file mode 100644
index 0000000..7cd5c2b
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/api/VersionInfo.java
@@ -0,0 +1,27 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.api;
+
+public class VersionInfo {
+ private String backendVersion;
+
+ public String getBackendVersion() {
+ return backendVersion;
+ }
+
+ public void setBackendVersion(String backendVersion) {
+ this.backendVersion = backendVersion;
+ }
+
+
+}
diff --git a/src/main/java/org/eclipse/openK/core/common/Globals.java b/src/main/java/org/eclipse/openK/core/common/Globals.java
new file mode 100644
index 0000000..1f789c8
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/common/Globals.java
@@ -0,0 +1,22 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.common;
+
+
+public final class Globals {
+ public static final String HEADER_JSON_UTF8 = "application/json; charset=utf-8";
+ public static final String HEALTH_CHECK_ADD_PATH = "healthcheck?pretty=true";
+
+ private Globals() {
+ }
+}
diff --git a/src/main/java/pta/de/core/common/GsonUTCDateAdapter.java b/src/main/java/org/eclipse/openK/core/common/GsonUTCDateAdapter.java
similarity index 71%
rename from src/main/java/pta/de/core/common/GsonUTCDateAdapter.java
rename to src/main/java/org/eclipse/openK/core/common/GsonUTCDateAdapter.java
index 024080b..86d7bfa 100644
--- a/src/main/java/pta/de/core/common/GsonUTCDateAdapter.java
+++ b/src/main/java/org/eclipse/openK/core/common/GsonUTCDateAdapter.java
@@ -1,4 +1,16 @@
-package pta.de.core.common;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.common;
import com.google.gson.*;
diff --git a/src/main/java/org/eclipse/openK/core/common/JsonGeneratorBase.java b/src/main/java/org/eclipse/openK/core/common/JsonGeneratorBase.java
new file mode 100644
index 0000000..4627bae
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/common/JsonGeneratorBase.java
@@ -0,0 +1,28 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.common;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.util.Date;
+
+public class JsonGeneratorBase {
+ private JsonGeneratorBase() {}
+ public static Gson getGson() {
+ return new GsonBuilder()
+ .registerTypeAdapter(Date.class, new GsonUTCDateAdapter())
+ .disableHtmlEscaping()
+ .create();
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/core/common/util/ResourceLoaderBase.java b/src/main/java/org/eclipse/openK/core/common/util/ResourceLoaderBase.java
new file mode 100644
index 0000000..96534c2
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/common/util/ResourceLoaderBase.java
@@ -0,0 +1,38 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.common.util;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.InputStream;
+import java.io.StringWriter;
+
+public class ResourceLoaderBase {
+ private String stream2String(InputStream is) {
+ StringWriter writer = new StringWriter();
+ try {
+ IOUtils.copy(is, writer, "UTF-8");
+ } catch (Exception e) { // NOSONAR
+ return "";
+ }
+ return writer.toString();
+
+
+ }
+
+ public String loadStringFromResource(String filename) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ InputStream jsonstream = classLoader.getResourceAsStream(filename);
+ return stream2String(jsonstream);
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/core/communication/RestServiceWrapper.java b/src/main/java/org/eclipse/openK/core/communication/RestServiceWrapper.java
new file mode 100644
index 0000000..3eb5387
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/communication/RestServiceWrapper.java
@@ -0,0 +1,210 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.communication;
+
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.*;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.util.EntityUtils;
+import org.apache.log4j.Logger;
+import org.eclipse.openK.core.common.Globals;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
+
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+public class RestServiceWrapper {
+ public static class HttpHeader {
+ private String attribute;
+ private String value;
+
+ public HttpHeader(String attribute, String value) {
+ this.attribute = attribute;
+ this.value = value;
+ }
+
+ public String getAttribute() {
+ return attribute;
+ }
+
+ public void setAttribute(String attribute) {
+ this.attribute = attribute;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+ private static final Logger LOGGER = Logger.getLogger(RestServiceWrapper.class.getName());
+ private boolean useHttps;
+
+ public enum HttpMethod {GET, POST, PUT, DELETE}
+
+ public RestServiceWrapper(boolean https) {
+ this.useHttps = https;
+ }
+
+ public static HttpHeader createHeader(String attribute, String value) {
+ return new HttpHeader(attribute, value);
+ }
+
+ public String performGetRequest(String restFunctionWithParams) throws HttpStatusException {
+ LOGGER.debug("CompleteUrl: " + restFunctionWithParams);
+ // create HTTP Client
+ CloseableHttpClient httpClient = createHttpsClient();
+
+ // create new Request with given URL
+ HttpGet getRequest = new HttpGet(restFunctionWithParams);
+ getRequest.addHeader("accept", Globals.HEADER_JSON_UTF8);
+
+ HttpResponse response;
+ // Execute request an catch response
+ try {
+ response = httpClient.execute(getRequest);
+
+ } catch (IOException e) {
+ String errtext = "Get communication to <" + restFunctionWithParams + "> failed.";
+ LOGGER.warn(errtext, e);
+ throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE);
+ }
+
+ return createJson(response);
+ }
+
+ public String performPostRequest(String restFunctionWithParams, String data) throws HttpStatusException {
+
+ // create HTTP Client
+ CloseableHttpClient httpClient = createHttpsClient();
+
+ // create new Post Request with given URL
+ HttpPost postRequest = new HttpPost(restFunctionWithParams);
+
+ // add additional header to getRequest which accepts application/JSON data
+ postRequest.addHeader("accept", Globals.HEADER_JSON_UTF8);
+ postRequest.addHeader("Content-Type", Globals.HEADER_JSON_UTF8);
+
+ postRequest.setEntity(new StringEntity(data, StandardCharsets.UTF_8));
+
+ HttpResponse response;
+ // Execute request an catch response
+ try {
+ response = httpClient.execute(postRequest);
+ } catch (IOException e) {
+ String errtext = "Post communication to <" + restFunctionWithParams + "> failed!";
+ LOGGER.warn(errtext, e);
+ throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE);
+ }
+ return createJson(response);
+ }
+
+ public Response performHttpRequest(HttpMethod method, String restFunctionWithParams,
+ List<HttpHeader> headerList, String data) throws HttpStatusException {
+
+ // create HTTP Client
+ CloseableHttpClient httpClient = createHttpsClient();
+
+ HttpRequestBase request = createRequest(method, restFunctionWithParams, data);
+ for (HttpHeader header : headerList) {
+ request.addHeader(header.attribute, header.value);
+ }
+
+ HttpResponse response;
+ // Execute request an catch response
+ try {
+ response = httpClient.execute(request);
+ } catch (IOException e) {
+ String errtext = "Communication to <" + restFunctionWithParams + "> failed...";
+ LOGGER.warn(errtext, e);
+ throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE);
+ }
+
+ String ent = createJson(response);
+
+ Response.ResponseBuilder rb = Response.status(response.getStatusLine().getStatusCode());
+ if (ent != null) {
+ rb.entity(ent);
+ }
+ return rb.build();
+ }
+
+ private HttpRequestBase createRequest(HttpMethod method, String restFunctionWithParams, String data) throws HttpStatusException {
+ HttpRequestBase ret;
+ switch (method) {
+ case GET:
+ ret = new HttpGet(restFunctionWithParams);
+ break;
+ case POST:
+ ret = setPayload(new HttpPost(restFunctionWithParams), data);
+ break;
+ case PUT:
+ ret = setPayload(new HttpPut(restFunctionWithParams), data);
+ break;
+ case DELETE:
+ ret = new HttpDelete(restFunctionWithParams);
+ break;
+ default:
+ throw new HttpStatusException(HttpStatus.SC_METHOD_NOT_ALLOWED);
+ }
+ return ret;
+ }
+
+ private HttpRequestBase setPayload(HttpEntityEnclosingRequestBase req, String data) {
+ req.setEntity(new StringEntity(data, StandardCharsets.UTF_8));
+ return req;
+ }
+
+ private CloseableHttpClient createHttpsClient() throws HttpStatusException {
+ if (useHttps) {
+ try {
+ SSLContextBuilder builder = new SSLContextBuilder();
+ builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
+ SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
+
+ return HttpClients.custom().setSSLSocketFactory(sslsf).build();
+ } catch (Exception e) {
+ LOGGER.error(e);
+ throw new HttpStatusException(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ } else {
+ return HttpClientBuilder.create().build();
+ }
+ }
+
+ private String createJson(HttpResponse response) throws HttpStatusException {
+ String retJson;
+ try {
+ retJson = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ LOGGER.error(e);
+ throw new HttpStatusException(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ return retJson;
+ }
+
+}
diff --git a/src/main/java/pta/de/core/controller/BackendController.java b/src/main/java/org/eclipse/openK/core/controller/BackendController.java
similarity index 79%
rename from src/main/java/pta/de/core/controller/BackendController.java
rename to src/main/java/org/eclipse/openK/core/controller/BackendController.java
index e163863..1c528fa 100644
--- a/src/main/java/pta/de/core/controller/BackendController.java
+++ b/src/main/java/org/eclipse/openK/core/controller/BackendController.java
@@ -1,12 +1,24 @@
-package pta.de.core.controller;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
import org.apache.log4j.Logger;
import org.eclipse.jetty.http.HttpStatus;
-import pta.de.api.ServiceDistributionCluster;
-import pta.de.api.VersionInfo;
-import pta.de.core.common.Globals;
-import pta.de.core.communication.RestServiceWrapper;
-import pta.de.core.exceptions.HttpStatusException;
+import org.eclipse.openK.api.VersionInfo;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.core.common.Globals;
+import org.eclipse.openK.core.communication.RestServiceWrapper;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
import java.util.Arrays;
import java.util.List;
@@ -27,7 +39,7 @@
throw new HttpStatusException(HttpStatus.NOT_FOUND_404);
}
- public VersionInfo getVersionInfo( String version ) {
+ public VersionInfo getVersionInfo(String version ) {
VersionInfo vi = new VersionInfo();
vi.setBackendVersion( version );
return vi;
diff --git a/src/main/java/pta/de/core/controller/BaseWebService.java b/src/main/java/org/eclipse/openK/core/controller/BaseWebService.java
similarity index 74%
rename from src/main/java/pta/de/core/controller/BaseWebService.java
rename to src/main/java/org/eclipse/openK/core/controller/BaseWebService.java
index 60c64bf..c26136d 100644
--- a/src/main/java/pta/de/core/controller/BaseWebService.java
+++ b/src/main/java/org/eclipse/openK/core/controller/BaseWebService.java
@@ -1,8 +1,20 @@
-package pta.de.core.controller;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
import org.apache.log4j.Logger;
import org.eclipse.jetty.http.HttpStatus;
-import pta.de.core.exceptions.HttpStatusException;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
import javax.ws.rs.core.Response;
import java.io.IOException;
diff --git a/src/main/java/org/eclipse/openK/core/controller/DispatchController.java b/src/main/java/org/eclipse/openK/core/controller/DispatchController.java
new file mode 100644
index 0000000..1e59b62
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/controller/DispatchController.java
@@ -0,0 +1,76 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
+
+import com.google.common.collect.Lists;
+import org.apache.log4j.Logger;
+import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.api.ServiceDistributionCluster.ServiceDistribution;
+import org.eclipse.openK.api.ServiceRequestEnvelope;
+import org.eclipse.openK.core.communication.RestServiceWrapper;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
+
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+import static java.util.stream.Collectors.toList;
+
+public class DispatchController {
+ private static Logger logger = Logger.getLogger(DispatchController.class);
+
+ public Response dispatch(String clustername, ServiceRequestEnvelope envelope) throws HttpStatusException {
+ RestServiceWrapper rsWrap = createRestServiceWrapper(envelope.isHttps());
+ List<RestServiceWrapper.HttpHeader> transformedList = Lists.newArrayList(envelope.getHeaders()).stream()
+ .map(header ->
+ RestServiceWrapper.createHeader(header.getAttribute(), header.getValue())).collect(toList());
+
+ String url = locateBaseUrl(ServicesConfigCache.getInstance().getCache(),
+ clustername, envelope.getServiceName()) + "/"
+ + envelope.getUriFragment();
+
+ return rsWrap.performHttpRequest(resolveMethod(envelope.getMethod()),
+ url, transformedList, envelope.getPayloadDecode());
+ }
+
+ protected RestServiceWrapper createRestServiceWrapper(boolean useHttps) {
+ return new RestServiceWrapper(useHttps);
+ }
+
+ private String locateBaseUrl(ServiceDistributionCluster[] cluster, String clustername, String servicename) throws HttpStatusException {
+ ServiceDistribution dist = new ServiceResolver(cluster)
+ .resolve(clustername, servicename);
+ if (dist == null) {
+ logger.error("Service [" + clustername + "]/[" + servicename + "] is not resolvable!");
+ throw new HttpStatusException(HttpStatus.NOT_FOUND_404);
+ }
+ return dist.getProtocol() + "://" + dist.getHost() + ":" + dist.getPortApp() + dist.getUrlPath();
+ }
+
+ private RestServiceWrapper.HttpMethod resolveMethod(String method) throws HttpStatusException {
+ switch (method.toUpperCase()) {
+ case "GET":
+ return RestServiceWrapper.HttpMethod.GET;
+ case "POST":
+ return RestServiceWrapper.HttpMethod.POST;
+ case "PUT":
+ return RestServiceWrapper.HttpMethod.PUT;
+ case "DELETE":
+ return RestServiceWrapper.HttpMethod.DELETE;
+ default:
+ logger.error("Invalid Method: " + method);
+ throw new HttpStatusException(HttpStatus.METHOD_NOT_ALLOWED_405);
+ }
+
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/core/controller/InitServicesConfigCacheJob.java b/src/main/java/org/eclipse/openK/core/controller/InitServicesConfigCacheJob.java
new file mode 100644
index 0000000..1b9a088
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/controller/InitServicesConfigCacheJob.java
@@ -0,0 +1,33 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
+
+import org.apache.log4j.Logger;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class InitServicesConfigCacheJob {
+
+ private static final Logger LOGGER = Logger.getLogger(InitServicesConfigCacheJob.class.getName());
+
+ private InitServicesConfigCacheJob() {
+ }
+
+ public static void init( String configFileName ) {
+ LOGGER.info("InitServicesConfigCacheJob called");
+ TimerTask timerTask = new ServicesConfigCacheTimerTask(configFileName);
+ Timer timer = new Timer();
+ timer.scheduleAtFixedRate(timerTask, 100, 5000L);
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/core/controller/ServiceResolver.java b/src/main/java/org/eclipse/openK/core/controller/ServiceResolver.java
new file mode 100644
index 0000000..1bc06f8
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/controller/ServiceResolver.java
@@ -0,0 +1,43 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
+
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.api.ServiceDistributionCluster.ServiceDistribution;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public class ServiceResolver {
+ private final ServiceDistributionCluster[] clusters;
+
+ public ServiceResolver(ServiceDistributionCluster[] clusters) {
+ this.clusters = clusters;
+ }
+
+ public ServiceDistribution resolve(String clustername, String servicename) {
+ Optional<ServiceDistributionCluster> cluster
+ = Arrays.stream(clusters).filter(
+ x -> x.getClustername().equalsIgnoreCase(clustername)).findFirst();
+ if (cluster.isPresent()) {
+ Optional<ServiceDistributionCluster.ServiceDistribution> dist =
+ Arrays.stream(cluster.get().getDistributions())
+ .filter(x -> x.getName().equalsIgnoreCase(servicename))
+ .findFirst();
+ if (dist.isPresent()) {
+ return dist.get();
+ }
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/pta/de/core/controller/ServicesConfigCache.java b/src/main/java/org/eclipse/openK/core/controller/ServicesConfigCache.java
similarity index 78%
rename from src/main/java/pta/de/core/controller/ServicesConfigCache.java
rename to src/main/java/org/eclipse/openK/core/controller/ServicesConfigCache.java
index 47b50b6..2802645 100644
--- a/src/main/java/pta/de/core/controller/ServicesConfigCache.java
+++ b/src/main/java/org/eclipse/openK/core/controller/ServicesConfigCache.java
@@ -1,10 +1,22 @@
-package pta.de.core.controller;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.log4j.Logger;
import org.eclipse.jetty.http.HttpStatus;
-import pta.de.api.ServiceDistributionCluster;
-import pta.de.core.exceptions.HttpStatusException;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
diff --git a/src/main/java/org/eclipse/openK/core/controller/ServicesConfigCacheTimerTask.java b/src/main/java/org/eclipse/openK/core/controller/ServicesConfigCacheTimerTask.java
new file mode 100644
index 0000000..1bc56b0
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/controller/ServicesConfigCacheTimerTask.java
@@ -0,0 +1,41 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
+
+import org.apache.log4j.Logger;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
+
+import java.util.TimerTask;
+
+public class ServicesConfigCacheTimerTask extends TimerTask {
+ private static final Logger logger = Logger.getLogger(ServicesConfigCacheTimerTask.class.getName());
+ private String configFileName;
+
+ public ServicesConfigCacheTimerTask( String configFileName ) {
+ this.configFileName = configFileName;
+ }
+
+
+ @Override
+ public void run() {
+ logger.debug("ServicesConfigCacheTimerTask started");
+
+ try {
+ ServicesConfigCache.getInstance().readServerDistribution(this.configFileName);
+ } catch (HttpStatusException e) {
+ logger.error("Error reading ServerDistributionFile", e);
+ }
+
+ logger.debug("ServicesConfigCacheTimerTask finished");
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/core/exceptions/HttpStatusException.java b/src/main/java/org/eclipse/openK/core/exceptions/HttpStatusException.java
new file mode 100644
index 0000000..c13fd02
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/core/exceptions/HttpStatusException.java
@@ -0,0 +1,25 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.exceptions;
+
+public class HttpStatusException extends Exception {
+ private final int httpStatus;
+
+ public HttpStatusException(int httpStatus ) {
+ this.httpStatus = httpStatus;
+ }
+
+ public int getHttpStatus() {
+ return httpStatus;
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/health/ConfigFilePresentHealthCheck.java b/src/main/java/org/eclipse/openK/health/ConfigFilePresentHealthCheck.java
new file mode 100644
index 0000000..30bad60
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/health/ConfigFilePresentHealthCheck.java
@@ -0,0 +1,31 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.health;
+
+import com.codahale.metrics.health.HealthCheck;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.core.controller.ServicesConfigCache;
+
+public class ConfigFilePresentHealthCheck extends HealthCheck {
+ @Override
+ protected Result check() throws Exception {
+ ServiceDistributionCluster[] sdc = ServicesConfigCache.getInstance().getCache(); // Throws Exception if it fails
+
+ if (sdc != null && sdc.length > 0) {
+ return Result.healthy();
+ }
+ else {
+ return Result.unhealthy("No ServiceDistributionCluster available!");
+ }
+ }
+}
diff --git a/src/main/java/org/eclipse/openK/resources/MicsCentralResource.java b/src/main/java/org/eclipse/openK/resources/MicsCentralResource.java
new file mode 100644
index 0000000..19a7fc2
--- /dev/null
+++ b/src/main/java/org/eclipse/openK/resources/MicsCentralResource.java
@@ -0,0 +1,71 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.resources;
+
+
+import org.apache.log4j.Logger;
+import org.eclipse.openK.core.common.JsonGeneratorBase;
+import org.eclipse.openK.core.controller.DispatchController;
+import org.hibernate.validator.constraints.NotEmpty;
+import org.eclipse.openK.api.ServiceRequestEnvelope;
+import org.eclipse.openK.core.controller.BackendController;
+import org.eclipse.openK.core.controller.BaseWebService;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/mics/central")
+@Produces(MediaType.APPLICATION_JSON)
+public class MicsCentralResource extends BaseWebService{
+ private static Logger logger = Logger.getLogger(MicsCentralResource.class.getName());
+
+ public MicsCentralResource() {
+ super(logger);
+ }
+
+ @GET
+ @Path("/serviceDistribution/{clustername}")
+ public Response getServiceDistribution(@PathParam("clustername") @NotEmpty String clustername) {
+ return invokeRunnable(() -> new BackendController().readServerDistribution(clustername));
+ }
+
+ @GET
+ @Path("/serviceHealthState/{clustername}/{servicename}")
+ public Response getClusterHealthState(@PathParam("clustername") @NotEmpty String clustername,
+ @PathParam("servicename") @NotEmpty String servicename) {
+ return invokeRunnable(() -> new BackendController().getServiceHealthState(clustername, servicename));
+ }
+
+ @POST
+ @Path("/dispatch/{clustername}")
+ public Response dispatch(String envelope,
+ @PathParam("clustername") @NotEmpty String clustername) {
+ ServiceRequestEnvelope envObj = JsonGeneratorBase.getGson().fromJson(envelope, ServiceRequestEnvelope.class);
+
+ try {
+ return new DispatchController().dispatch(clustername, envObj);
+ } catch (HttpStatusException hse) {
+ logger.error(hse);
+ return Response.status(hse.getHttpStatus()).build();
+ }
+ }
+
+
+ @GET
+ @Path("/versionInfo")
+ public Response getVersionInfo() {
+ return invokeRunnable(() -> new BackendController().getVersionInfo(getVersionString()));
+ }
+}
diff --git a/src/main/java/pta/de/MicsCentralConfiguration.java b/src/main/java/pta/de/MicsCentralConfiguration.java
deleted file mode 100644
index 26ae324..0000000
--- a/src/main/java/pta/de/MicsCentralConfiguration.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package pta.de;
-
-import io.dropwizard.Configuration;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.hibernate.validator.constraints.*;
-
-public class MicsCentralConfiguration extends Configuration {
- @NotEmpty
- private String servicesDistributionFileName;
-
- @JsonProperty
- public String getServicesDistributionFileName() {
- return servicesDistributionFileName;
- }
-
- @JsonProperty
- public void setServicesDistributionFileName(String servicesDistributionFileName) {
- this.servicesDistributionFileName = servicesDistributionFileName;
- }
-}
diff --git a/src/main/java/pta/de/api/VersionInfo.java b/src/main/java/pta/de/api/VersionInfo.java
deleted file mode 100644
index 1a95df3..0000000
--- a/src/main/java/pta/de/api/VersionInfo.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package pta.de.api;
-
-public class VersionInfo {
- private String backendVersion;
-
- public String getBackendVersion() {
- return backendVersion;
- }
-
- public void setBackendVersion(String backendVersion) {
- this.backendVersion = backendVersion;
- }
-
-
-}
diff --git a/src/main/java/pta/de/core/common/Globals.java b/src/main/java/pta/de/core/common/Globals.java
deleted file mode 100644
index a2e0d43..0000000
--- a/src/main/java/pta/de/core/common/Globals.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package pta.de.core.common;
-
-
-public final class Globals {
- public static final String HEADER_JSON_UTF8 = "application/json; charset=utf-8";
- public static final String HEALTH_CHECK_ADD_PATH = "healthcheck?pretty=true";
-
- private Globals() {
- }
-}
diff --git a/src/main/java/pta/de/core/common/JsonGeneratorBase.java b/src/main/java/pta/de/core/common/JsonGeneratorBase.java
deleted file mode 100644
index af20a84..0000000
--- a/src/main/java/pta/de/core/common/JsonGeneratorBase.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package pta.de.core.common;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import java.util.Date;
-
-public class JsonGeneratorBase {
- private JsonGeneratorBase() {}
- public static Gson getGson() {
- return new GsonBuilder()
- .registerTypeAdapter(Date.class, new GsonUTCDateAdapter())
- .disableHtmlEscaping()
- .create();
- }
-}
diff --git a/src/main/java/pta/de/core/common/util/ResourceLoaderBase.java b/src/main/java/pta/de/core/common/util/ResourceLoaderBase.java
deleted file mode 100644
index ba3c3e6..0000000
--- a/src/main/java/pta/de/core/common/util/ResourceLoaderBase.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package pta.de.core.common.util;
-
-import org.apache.commons.io.IOUtils;
-
-import java.io.InputStream;
-import java.io.StringWriter;
-
-public class ResourceLoaderBase {
- private String stream2String(InputStream is) {
- StringWriter writer = new StringWriter();
- try {
- IOUtils.copy(is, writer, "UTF-8");
- } catch (Exception e) { // NOSONAR
- return "";
- }
- return writer.toString();
-
-
- }
-
- public String loadStringFromResource(String filename) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- InputStream jsonstream = classLoader.getResourceAsStream(filename);
- return stream2String(jsonstream);
- }
-}
diff --git a/src/main/java/pta/de/core/communication/RestServiceWrapper.java b/src/main/java/pta/de/core/communication/RestServiceWrapper.java
deleted file mode 100644
index dbfdbb8..0000000
--- a/src/main/java/pta/de/core/communication/RestServiceWrapper.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package pta.de.core.communication;
-
-
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.ssl.SSLContextBuilder;
-import org.apache.http.util.EntityUtils;
-import org.apache.log4j.Logger;
-import pta.de.core.common.Globals;
-import pta.de.core.exceptions.HttpStatusException;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-public class RestServiceWrapper {
- private static final Logger LOGGER = Logger.getLogger(RestServiceWrapper.class.getName());
- private boolean useHttps;
-
- public RestServiceWrapper(boolean https) {
- this.useHttps = https;
- }
-
- public String performGetRequest(String restFunctionWithParams) throws HttpStatusException {
- LOGGER.debug("CompleteUrl: " + restFunctionWithParams);
- // create HTTP Client
- CloseableHttpClient httpClient = createHttpsClient();
-
- // create new Request with given URL
- HttpGet getRequest = new HttpGet(restFunctionWithParams);
- getRequest.addHeader("accept", Globals.HEADER_JSON_UTF8);
-
- HttpResponse response;
- // Execute request an catch response
- try {
- response = httpClient.execute(getRequest);
-
- } catch (IOException e) {
- String errtext = "Communication to <" + restFunctionWithParams + "> failed!";
- LOGGER.warn(errtext, e);
- throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE);
- }
-
- return createJson(response);
- }
-
- public String performPostRequest(String restFunctionWithParams, String data) throws HttpStatusException {
-
- // create HTTP Client
- CloseableHttpClient httpClient = createHttpsClient();
-
- // create new Post Request with given URL
- HttpPost postRequest = new HttpPost(restFunctionWithParams);
-
- // add additional header to getRequest which accepts application/JSON data
- postRequest.addHeader("accept", Globals.HEADER_JSON_UTF8);
- postRequest.addHeader("Content-Type", Globals.HEADER_JSON_UTF8);
-
- postRequest.setEntity(new StringEntity(data, StandardCharsets.UTF_8));
-
- HttpResponse response;
- // Execute request an catch response
- try {
- response = httpClient.execute(postRequest);
- } catch (IOException e) {
- String errtext = "Communication to <" + restFunctionWithParams + "> failed!";
- LOGGER.warn(errtext, e);
- throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE);
- }
- return createJson(response);
- }
-
- private CloseableHttpClient createHttpsClient() throws HttpStatusException {
- if (useHttps) {
- try {
- SSLContextBuilder builder = new SSLContextBuilder();
- builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
- SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
-
- return HttpClients.custom().setSSLSocketFactory(sslsf).build();
- } catch (Exception e) {
- LOGGER.error(e);
- throw new HttpStatusException(HttpStatus.SC_INTERNAL_SERVER_ERROR);
- }
- } else {
- return HttpClientBuilder.create().build();
- }
- }
-
- private String createJson(HttpResponse response) throws HttpStatusException {
- String retJson;
- try {
- retJson = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
- } catch (IOException e) {
- LOGGER.error(e);
- throw new HttpStatusException(HttpStatus.SC_INTERNAL_SERVER_ERROR);
- }
-
- return retJson;
- }
-
-}
diff --git a/src/main/java/pta/de/core/controller/InitServicesConfigCacheJob.java b/src/main/java/pta/de/core/controller/InitServicesConfigCacheJob.java
deleted file mode 100644
index 943a7b6..0000000
--- a/src/main/java/pta/de/core/controller/InitServicesConfigCacheJob.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package pta.de.core.controller;
-
-import org.apache.log4j.Logger;
-
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class InitServicesConfigCacheJob {
-
- private static final Logger LOGGER = Logger.getLogger(InitServicesConfigCacheJob.class.getName());
-
- private InitServicesConfigCacheJob() {
- }
-
- public static void init( String configFileName ) {
- LOGGER.info("InitServicesConfigCacheJob called");
- TimerTask timerTask = new ServicesConfigCacheTimerTask(configFileName);
- Timer timer = new Timer();
- timer.scheduleAtFixedRate(timerTask, 100, 5000L);
- }
-}
diff --git a/src/main/java/pta/de/core/controller/ServicesConfigCacheTimerTask.java b/src/main/java/pta/de/core/controller/ServicesConfigCacheTimerTask.java
deleted file mode 100644
index 99ecee6..0000000
--- a/src/main/java/pta/de/core/controller/ServicesConfigCacheTimerTask.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package pta.de.core.controller;
-
-import org.apache.log4j.Logger;
-import pta.de.core.exceptions.HttpStatusException;
-
-import java.util.TimerTask;
-
-public class ServicesConfigCacheTimerTask extends TimerTask {
- private static final Logger logger = Logger.getLogger(ServicesConfigCacheTimerTask.class.getName());
- private String configFileName;
-
- public ServicesConfigCacheTimerTask( String configFileName ) {
- this.configFileName = configFileName;
- }
-
-
- @Override
- public void run() {
- logger.debug("ServicesConfigCacheTimerTask started");
-
- try {
- ServicesConfigCache.getInstance().readServerDistribution(this.configFileName);
- } catch (HttpStatusException e) {
- logger.error("Error reading ServerDistributionFile", e);
- }
-
- logger.debug("ServicesConfigCacheTimerTask finished");
- }
-}
diff --git a/src/main/java/pta/de/core/exceptions/HttpStatusException.java b/src/main/java/pta/de/core/exceptions/HttpStatusException.java
deleted file mode 100644
index 6b2c0cc..0000000
--- a/src/main/java/pta/de/core/exceptions/HttpStatusException.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package pta.de.core.exceptions;
-
-public class HttpStatusException extends Exception {
- private final int httpStatus;
-
- public HttpStatusException(int httpStatus ) {
- this.httpStatus = httpStatus;
- }
-
- public int getHttpStatus() {
- return httpStatus;
- }
-}
diff --git a/src/main/java/pta/de/health/ConfigFilePresentHealthCheck.java b/src/main/java/pta/de/health/ConfigFilePresentHealthCheck.java
deleted file mode 100644
index e8de912..0000000
--- a/src/main/java/pta/de/health/ConfigFilePresentHealthCheck.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package pta.de.health;
-
-import com.codahale.metrics.health.HealthCheck;
-import pta.de.api.ServiceDistributionCluster;
-import pta.de.core.controller.ServicesConfigCache;
-
-public class ConfigFilePresentHealthCheck extends HealthCheck {
- @Override
- protected Result check() throws Exception {
- ServiceDistributionCluster[] sdc = ServicesConfigCache.getInstance().getCache(); // Throws Exception if it fails
-
- if (sdc != null && sdc.length > 0) {
- return Result.healthy();
- }
- else {
- return Result.unhealthy("No ServiceDistributionCluster available!");
- }
- }
-}
diff --git a/src/main/java/pta/de/resources/MicsCentralResource.java b/src/main/java/pta/de/resources/MicsCentralResource.java
deleted file mode 100644
index 15b4253..0000000
--- a/src/main/java/pta/de/resources/MicsCentralResource.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package pta.de.resources;
-
-
-import org.apache.log4j.Logger;
-import org.hibernate.validator.constraints.NotEmpty;
-import pta.de.core.controller.BackendController;
-import pta.de.core.controller.BaseWebService;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-@Path("/mics/central")
-@Produces(MediaType.APPLICATION_JSON)
-public class MicsCentralResource extends BaseWebService{
- private static Logger logger = Logger.getLogger(MicsCentralResource.class.getName());
-
- public MicsCentralResource() {
- super(logger);
- }
-
- @GET
- @Path("/serviceDistribution/{clustername}")
- public Response getServiceDistribution(@PathParam("clustername") @NotEmpty String clustername) {
- return invokeRunnable(() -> new BackendController().readServerDistribution(clustername));
- }
-
- @GET
- @Path("/serviceHealthState/{clustername}/{servicename}")
- public Response getClusterHealthState(@PathParam("clustername") @NotEmpty String clustername,
- @PathParam("servicename") @NotEmpty String servicename) {
- return invokeRunnable(() -> new BackendController().getServiceHealthState(clustername, servicename));
- }
-
-
- @GET
- @Path("/versionInfo")
- public Response getVersionInfo() {
- return invokeRunnable(() -> new BackendController().getVersionInfo(getVersionString()));
- }
-}
diff --git a/src/test/java/pta/de/MicsCentralApplicationTest.java b/src/test/java/org/eclipse/openK/MicsCentralApplicationTest.java
similarity index 85%
rename from src/test/java/pta/de/MicsCentralApplicationTest.java
rename to src/test/java/org/eclipse/openK/MicsCentralApplicationTest.java
index af299ca..9f4df5c 100644
--- a/src/test/java/pta/de/MicsCentralApplicationTest.java
+++ b/src/test/java/org/eclipse/openK/MicsCentralApplicationTest.java
@@ -1,4 +1,16 @@
-package pta.de;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK;
import com.codahale.metrics.health.HealthCheckRegistry;
import io.dropwizard.jersey.setup.JerseyEnvironment;
diff --git a/src/test/java/pta/de/api/ServiceDistributionClusterTest.java b/src/test/java/org/eclipse/openK/api/ServiceDistributionClusterTest.java
similarity index 86%
rename from src/test/java/pta/de/api/ServiceDistributionClusterTest.java
rename to src/test/java/org/eclipse/openK/api/ServiceDistributionClusterTest.java
index 0efe76d..ff0b8f0 100644
--- a/src/test/java/pta/de/api/ServiceDistributionClusterTest.java
+++ b/src/test/java/org/eclipse/openK/api/ServiceDistributionClusterTest.java
@@ -1,4 +1,16 @@
-package pta.de.api;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.api;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
diff --git a/src/test/java/org/eclipse/openK/api/ServiceRequestEnvelopeTest.java b/src/test/java/org/eclipse/openK/api/ServiceRequestEnvelopeTest.java
new file mode 100644
index 0000000..55e3e6f
--- /dev/null
+++ b/src/test/java/org/eclipse/openK/api/ServiceRequestEnvelopeTest.java
@@ -0,0 +1,54 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.api;
+
+import org.glassfish.jersey.internal.util.Base64;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class ServiceRequestEnvelopeTest {
+
+ @Test
+ public void testPojo() {
+ final String payload = "Testme Accurate";
+ final String payloadEncoded = Base64.encodeAsString(payload);
+ ServiceRequestEnvelope env = new ServiceRequestEnvelope();
+ env.setHttps(true);
+ env.setMethod("POST");
+ env.setPayloadEncode(payload);
+ env.setUriFragment("Fraggel");
+ env.setServiceName("Salve");
+
+ ServiceRequestEnvelope.HttpHeader[] headers = new ServiceRequestEnvelope.HttpHeader[2];
+ headers[0] = new ServiceRequestEnvelope.HttpHeader();
+ headers[0].setAttribute("1stAttr");
+ headers[0].setValue("1stValue");
+ headers[1] = new ServiceRequestEnvelope.HttpHeader();
+ headers[1].setAttribute("2ndAttr");
+ headers[1].setValue("2ndValue");
+ env.setHeaders(headers);
+
+ assertEquals(true, env.isHttps());
+ assertEquals("POST", env.getMethod());
+ assertEquals(payload, env.getPayloadDecode());
+ assertEquals(payloadEncoded, env.getPayload());
+ env.setPayload(payload);
+ assertEquals(payload, env.getPayload());
+ assertEquals("Fraggel", env.getUriFragment());
+ assertEquals("Salve", env.getServiceName());
+ assertEquals(2, env.getHeaders().length);
+ assertEquals("2ndAttr", env.getHeaders()[1].getAttribute());
+ assertEquals("1stValue", env.getHeaders()[0].getValue());
+ }
+}
diff --git a/src/test/java/org/eclipse/openK/api/VersionInfoTest.java b/src/test/java/org/eclipse/openK/api/VersionInfoTest.java
new file mode 100644
index 0000000..26517c3
--- /dev/null
+++ b/src/test/java/org/eclipse/openK/api/VersionInfoTest.java
@@ -0,0 +1,36 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.api;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class VersionInfoTest {
+
+ @Test
+ public void testGetVersionInfo() throws IOException {
+ VersionInfo vi = new VersionInfo();
+ vi.setBackendVersion("123");
+
+ ObjectMapper om = new ObjectMapper();
+ String jsonString = om.writeValueAsString(vi);
+
+ VersionInfo vi2 = om.readValue(jsonString, VersionInfo.class);
+
+ assertEquals(vi.getBackendVersion(), vi2.getBackendVersion());
+ }
+}
diff --git a/src/test/java/pta/de/core/common/GsonUTCDateAdapterTest.java b/src/test/java/org/eclipse/openK/core/common/GsonUTCDateAdapterTest.java
similarity index 76%
rename from src/test/java/pta/de/core/common/GsonUTCDateAdapterTest.java
rename to src/test/java/org/eclipse/openK/core/common/GsonUTCDateAdapterTest.java
index a1bb423..efd4d3c 100644
--- a/src/test/java/pta/de/core/common/GsonUTCDateAdapterTest.java
+++ b/src/test/java/org/eclipse/openK/core/common/GsonUTCDateAdapterTest.java
@@ -1,4 +1,16 @@
-package pta.de.core.common;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.common;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
diff --git a/src/test/java/org/eclipse/openK/core/common/util/ResourceLoaderBaseTest.java b/src/test/java/org/eclipse/openK/core/common/util/ResourceLoaderBaseTest.java
new file mode 100644
index 0000000..976ac64
--- /dev/null
+++ b/src/test/java/org/eclipse/openK/core/common/util/ResourceLoaderBaseTest.java
@@ -0,0 +1,27 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.common.util;
+
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ResourceLoaderBaseTest {
+ @Test
+ public void testloadStringFromResourceError() {
+ ResourceLoaderBase rlb = new ResourceLoaderBase();
+ String str = rlb.loadStringFromResource("UNKNOWN_FILE");
+ assertEquals("", str);
+ }
+}
diff --git a/src/test/java/pta/de/core/controller/BackendControllerTest.java b/src/test/java/org/eclipse/openK/core/controller/BackendControllerTest.java
similarity index 78%
rename from src/test/java/pta/de/core/controller/BackendControllerTest.java
rename to src/test/java/org/eclipse/openK/core/controller/BackendControllerTest.java
index e13534f..d97234a 100644
--- a/src/test/java/pta/de/core/controller/BackendControllerTest.java
+++ b/src/test/java/org/eclipse/openK/core/controller/BackendControllerTest.java
@@ -1,11 +1,23 @@
-package pta.de.core.controller;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.openK.core.common.util.ResourceLoaderBase;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
-import pta.de.api.ServiceDistributionCluster;
-import pta.de.core.common.util.ResourceLoaderBase;
-import pta.de.core.exceptions.HttpStatusException;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
diff --git a/src/test/java/pta/de/core/controller/BaseWebServiceTest.java b/src/test/java/org/eclipse/openK/core/controller/BaseWebServiceTest.java
similarity index 72%
rename from src/test/java/pta/de/core/controller/BaseWebServiceTest.java
rename to src/test/java/org/eclipse/openK/core/controller/BaseWebServiceTest.java
index e6899e0..7deef09 100644
--- a/src/test/java/pta/de/core/controller/BaseWebServiceTest.java
+++ b/src/test/java/org/eclipse/openK/core/controller/BaseWebServiceTest.java
@@ -1,10 +1,22 @@
-package pta.de.core.controller;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.openK.core.common.util.ResourceLoaderBase;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
-import pta.de.core.common.util.ResourceLoaderBase;
-import pta.de.core.exceptions.HttpStatusException;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
import javax.ws.rs.core.Response;
diff --git a/src/test/java/org/eclipse/openK/core/controller/DispatchControllerTest.java b/src/test/java/org/eclipse/openK/core/controller/DispatchControllerTest.java
new file mode 100644
index 0000000..9cc5507
--- /dev/null
+++ b/src/test/java/org/eclipse/openK/core/controller/DispatchControllerTest.java
@@ -0,0 +1,114 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
+
+import org.easymock.EasyMock;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Test;
+import org.powermock.reflect.Whitebox;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.api.ServiceRequestEnvelope;
+import org.eclipse.openK.core.common.JsonGeneratorBase;
+import org.eclipse.openK.core.common.util.ResourceLoaderBase;
+import org.eclipse.openK.core.communication.RestServiceWrapper;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
+
+import javax.ws.rs.core.Response;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.junit.Assert.assertEquals;
+
+public class DispatchControllerTest extends ResourceLoaderBase {
+
+ @Before
+ public void init() {
+ String clusterString = this.loadStringFromResource("servicesDistributionTest.json");
+ ServiceDistributionCluster[] cluster = JsonGeneratorBase.getGson()
+ .fromJson(clusterString, ServiceDistributionCluster[].class);
+ ServicesConfigCache cache = ServicesConfigCache.getInstance();
+ Whitebox.setInternalState(cache, "cache", cluster);
+
+
+ }
+
+ @Test
+ public void testDispatch_ok() throws HttpStatusException {
+ Response response = Response.ok().entity("{ret: '111'}").build();
+ final RestServiceWrapper rester = EasyMock.createMock(RestServiceWrapper.class);
+ EasyMock.expect(rester.performHttpRequest(anyObject(),
+ anyString(), anyObject(), anyString())).andReturn(response);
+ EasyMock.replay(rester);
+ ServiceRequestEnvelope envelope = JsonGeneratorBase.getGson().fromJson(
+ loadStringFromResource("serviceRequestEnvelope.json"), ServiceRequestEnvelope.class);
+
+
+ DispatchController controller = new DispatchController() {
+ @Override
+ protected RestServiceWrapper createRestServiceWrapper(boolean b) {
+ return rester;
+ }
+ };
+
+ Response resp2 = controller.dispatch("elogbook.openK", envelope);
+ assertEquals(HttpStatus.OK_200, resp2.getStatus());
+
+ }
+
+ @Test(expected = HttpStatusException.class)
+ public void testDispatch_InvCluster() throws HttpStatusException {
+
+ Response response = Response.ok().entity("{ret: '111'}").build();
+ final RestServiceWrapper rester = EasyMock.createMock(RestServiceWrapper.class);
+ EasyMock.expect(rester.performHttpRequest(anyObject(),
+ anyString(), anyObject(), anyString())).andReturn(response);
+ EasyMock.replay(rester);
+ ServiceRequestEnvelope envelope = JsonGeneratorBase.getGson().fromJson(
+ loadStringFromResource("serviceRequestEnvelope.json"), ServiceRequestEnvelope.class);
+
+
+ DispatchController controller = new DispatchController() {
+ @Override
+ protected RestServiceWrapper createRestServiceWrapper(boolean b) {
+ return rester;
+ }
+ };
+
+ try {
+ controller.dispatch("invalid", envelope);
+ } catch (HttpStatusException hse) {
+ assertEquals(HttpStatus.NOT_FOUND_404, hse.getHttpStatus());
+ throw hse;
+ }
+ }
+
+ @Test(expected = HttpStatusException.class)
+ public void testResolveMethod() throws Exception {
+ DispatchController ctrl = new DispatchController();
+ assertEquals(RestServiceWrapper.HttpMethod.GET, Whitebox.invokeMethod(ctrl, "resolveMethod", "get"));
+ assertEquals(RestServiceWrapper.HttpMethod.POST, Whitebox.invokeMethod(ctrl, "resolveMethod", "Post"));
+ assertEquals(RestServiceWrapper.HttpMethod.DELETE, Whitebox.invokeMethod(ctrl, "resolveMethod", "DELETE"));
+ assertEquals(RestServiceWrapper.HttpMethod.PUT, Whitebox.invokeMethod(ctrl, "resolveMethod", "put"));
+
+ String s;
+ try {
+ s = Whitebox.invokeMethod(ctrl, "resolveMethod", "invalid");
+ } catch (HttpStatusException hse) {
+ // the correct test path goes in here!!!!!!
+ assertEquals(HttpStatus.METHOD_NOT_ALLOWED_405, hse.getHttpStatus());
+ throw hse;
+ }
+ }
+
+}
diff --git a/src/test/java/pta/de/core/controller/ServicesConfigCacheTest.java b/src/test/java/org/eclipse/openK/core/controller/ServicesConfigCacheTest.java
similarity index 74%
rename from src/test/java/pta/de/core/controller/ServicesConfigCacheTest.java
rename to src/test/java/org/eclipse/openK/core/controller/ServicesConfigCacheTest.java
index b1b7772..3cf869b 100644
--- a/src/test/java/pta/de/core/controller/ServicesConfigCacheTest.java
+++ b/src/test/java/org/eclipse/openK/core/controller/ServicesConfigCacheTest.java
@@ -1,11 +1,23 @@
-package pta.de.core.controller;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
-import pta.de.api.ServiceDistributionCluster;
-import pta.de.core.common.util.ResourceLoaderBase;
-import pta.de.core.exceptions.HttpStatusException;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.core.common.util.ResourceLoaderBase;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
import static org.junit.Assert.assertEquals;
diff --git a/src/test/java/pta/de/core/controller/ServicesConfigCacheTimerTaskTest.java b/src/test/java/org/eclipse/openK/core/controller/ServicesConfigCacheTimerTaskTest.java
similarity index 75%
rename from src/test/java/pta/de/core/controller/ServicesConfigCacheTimerTaskTest.java
rename to src/test/java/org/eclipse/openK/core/controller/ServicesConfigCacheTimerTaskTest.java
index ca6e772..31c45c6 100644
--- a/src/test/java/pta/de/core/controller/ServicesConfigCacheTimerTaskTest.java
+++ b/src/test/java/org/eclipse/openK/core/controller/ServicesConfigCacheTimerTaskTest.java
@@ -1,12 +1,24 @@
-package pta.de.core.controller;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.controller;
import org.easymock.EasyMock;
import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
-import pta.de.core.exceptions.HttpStatusException;
import static org.easymock.EasyMock.*;
diff --git a/src/test/java/org/eclipse/openK/core/exceptions/HttpStatusExceptionTest.java b/src/test/java/org/eclipse/openK/core/exceptions/HttpStatusExceptionTest.java
new file mode 100644
index 0000000..19589b2
--- /dev/null
+++ b/src/test/java/org/eclipse/openK/core/exceptions/HttpStatusExceptionTest.java
@@ -0,0 +1,27 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.core.exceptions;
+
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HttpStatusExceptionTest {
+ @Test
+ public void testAll() {
+ HttpStatusException hse = new HttpStatusException( 200 );
+ assertEquals(HttpStatus.OK_200, hse.getHttpStatus());
+ }
+}
diff --git a/src/test/java/pta/de/health/ConfigFilePresentHealthCheckTest.java b/src/test/java/org/eclipse/openK/health/ConfigFilePresentHealthCheckTest.java
similarity index 69%
rename from src/test/java/pta/de/health/ConfigFilePresentHealthCheckTest.java
rename to src/test/java/org/eclipse/openK/health/ConfigFilePresentHealthCheckTest.java
index d8798dc..f33c91e 100644
--- a/src/test/java/pta/de/health/ConfigFilePresentHealthCheckTest.java
+++ b/src/test/java/org/eclipse/openK/health/ConfigFilePresentHealthCheckTest.java
@@ -1,10 +1,22 @@
-package pta.de.health;
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.health;
import com.codahale.metrics.health.HealthCheck;
+import org.eclipse.openK.api.ServiceDistributionCluster;
+import org.eclipse.openK.core.controller.ServicesConfigCache;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
-import pta.de.api.ServiceDistributionCluster;
-import pta.de.core.controller.ServicesConfigCache;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;
diff --git a/src/test/java/org/eclipse/openK/resources/MicsCentralResourceTest.java b/src/test/java/org/eclipse/openK/resources/MicsCentralResourceTest.java
new file mode 100644
index 0000000..ffecb61
--- /dev/null
+++ b/src/test/java/org/eclipse/openK/resources/MicsCentralResourceTest.java
@@ -0,0 +1,39 @@
+/**
+******************************************************************************
+* Copyright © 2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+
+package org.eclipse.openK.resources;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.openK.core.controller.ServicesConfigCache;
+import org.eclipse.openK.core.exceptions.HttpStatusException;
+import org.junit.Test;
+
+import javax.ws.rs.core.Response;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+public class MicsCentralResourceTest {
+ @Test
+ public void testGetVersionInfo() {
+ Response r = new MicsCentralResource().getVersionInfo();
+ assertNotNull( r );
+ }
+
+ @Test
+ public void testGetServiceDistribution() throws HttpStatusException {
+ ServicesConfigCache.getInstance().readServerDistribution("servicesDistributionDevLocal.json");
+ Response r = new MicsCentralResource().getServiceDistribution("elogbook.openK" );
+
+ assertEquals(HttpStatus.OK_200, r.getStatus());
+ }
+}
diff --git a/src/test/java/pta/de/api/VersionInfoTest.java b/src/test/java/pta/de/api/VersionInfoTest.java
deleted file mode 100644
index e537f9f..0000000
--- a/src/test/java/pta/de/api/VersionInfoTest.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package pta.de.api;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
-
-public class VersionInfoTest {
-
- @Test
- public void testGetVersionInfo() throws IOException {
- VersionInfo vi = new VersionInfo();
- vi.setBackendVersion("123");
-
- ObjectMapper om = new ObjectMapper();
- String jsonString = om.writeValueAsString(vi);
-
- VersionInfo vi2 = om.readValue(jsonString, VersionInfo.class);
-
- assertEquals(vi.getBackendVersion(), vi2.getBackendVersion());
- }
-}
diff --git a/src/test/java/pta/de/core/common/util/ResourceLoaderBaseTest.java b/src/test/java/pta/de/core/common/util/ResourceLoaderBaseTest.java
deleted file mode 100644
index c56e0bd..0000000
--- a/src/test/java/pta/de/core/common/util/ResourceLoaderBaseTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package pta.de.core.common.util;
-
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class ResourceLoaderBaseTest {
- @Test
- public void testloadStringFromResourceError() {
- ResourceLoaderBase rlb = new ResourceLoaderBase();
- String str = rlb.loadStringFromResource("UNKNOWN_FILE");
- assertEquals("", str);
- }
-}
diff --git a/src/test/java/pta/de/core/exceptions/HttpStatusExceptionTest.java b/src/test/java/pta/de/core/exceptions/HttpStatusExceptionTest.java
deleted file mode 100644
index 51e5fad..0000000
--- a/src/test/java/pta/de/core/exceptions/HttpStatusExceptionTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package pta.de.core.exceptions;
-
-
-import org.eclipse.jetty.http.HttpStatus;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class HttpStatusExceptionTest {
- @Test
- public void testAll() {
- HttpStatusException hse = new HttpStatusException( 200 );
- assertEquals(HttpStatus.OK_200, hse.getHttpStatus());
- }
-}
diff --git a/src/test/java/pta/de/resources/MicsCentralResourceTest.java b/src/test/java/pta/de/resources/MicsCentralResourceTest.java
deleted file mode 100644
index 3562fd1..0000000
--- a/src/test/java/pta/de/resources/MicsCentralResourceTest.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package pta.de.resources;
-
-import org.eclipse.jetty.http.HttpStatus;
-import org.junit.Test;
-import pta.de.core.controller.ServicesConfigCache;
-import pta.de.core.exceptions.HttpStatusException;
-
-import javax.ws.rs.core.Response;
-
-import static junit.framework.TestCase.assertNotNull;
-import static org.junit.Assert.assertEquals;
-
-public class MicsCentralResourceTest {
- @Test
- public void testGetVersionInfo() {
- Response r = new MicsCentralResource().getVersionInfo();
- assertNotNull( r );
- }
-
- @Test
- public void testGetServiceDistribution() throws HttpStatusException {
- ServicesConfigCache.getInstance().readServerDistribution("servicesDistributionDevLocal.json");
- Response r = new MicsCentralResource().getServiceDistribution("elogbook.openK" );
-
- assertEquals(HttpStatus.OK_200, r.getStatus());
- }
-}
diff --git a/src/test/resources/serviceRequestEnvelope.json b/src/test/resources/serviceRequestEnvelope.json
new file mode 100644
index 0000000..9722f58
--- /dev/null
+++ b/src/test/resources/serviceRequestEnvelope.json
@@ -0,0 +1,17 @@
+{
+ "serviceName": "auth-n-auth.mics",
+ "isHttps": false,
+ "method": "GET",
+ "uriFragment": "versionInfo",
+ "payload": "eyAiYmFja2VuZFZlcnNpb24iOiAiMC4xLjMtU05BUFNIT1QifQ==",
+ "headers": [
+ {
+ "attribute": "Content-Type",
+ "value": "application/json"
+ },
+ {
+ "attribute": "accept",
+ "value": "application/json"
+ }
+ ]
+}
\ No newline at end of file