diff options
author | liamfallon <liam.fallon@est.tech> | 2019-10-21 19:59:22 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-10-31 07:54:57 +0000 |
commit | c03a0455e2956e43e425d6f4121ab5d8d20158f1 (patch) | |
tree | 94d9d73731aef727fb83e5e71c8a852fde85e3d4 /examples/examples-onap-vcpe | |
parent | 0f10bb04a9325fe59893c942a5109f353fd1cde1 (diff) |
Use updated APPC model code in apex vcpe example
The APPC implementation was changed in a recent review, this review
fixes the apex vcpe example to use this new model.
Also fixes an an issue in the CLI editor where escape characters are not
now required in example JSON.
Issue-ID: POLICY-2043
Change-Id: Id251948c9de27f73ba48cec498e68a43f71c4062
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'examples/examples-onap-vcpe')
-rw-r--r-- | examples/examples-onap-vcpe/pom.xml | 1 | ||||
-rw-r--r-- | examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java | 53 |
2 files changed, 33 insertions, 21 deletions
diff --git a/examples/examples-onap-vcpe/pom.xml b/examples/examples-onap-vcpe/pom.xml index b9a992e67..f27c7d63e 100644 --- a/examples/examples-onap-vcpe/pom.xml +++ b/examples/examples-onap-vcpe/pom.xml @@ -93,7 +93,6 @@ <dependency> <groupId>org.onap.policy.common</groupId> <artifactId>policy-endpoints</artifactId> - <version>${version.policy.common}</version> <scope>test</scope> </dependency> </dependencies> diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java index 4a12b3baa..10f425302 100644 --- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java +++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java @@ -5,38 +5,39 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ package org.onap.policy.apex.domains.onap.vcpe; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.BlockingQueue; -import org.onap.policy.appclcm.LcmRequest; -import org.onap.policy.appclcm.LcmRequestWrapper; -import org.onap.policy.appclcm.LcmResponse; -import org.onap.policy.appclcm.LcmResponseWrapper; -import org.onap.policy.appclcm.util.Serialization; +import org.onap.policy.appclcm.AppcLcmDmaapWrapper; +import org.onap.policy.appclcm.AppcLcmInput; +import org.onap.policy.appclcm.AppcLcmOutput; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; /** * Respond to an APPC request with a given delay. */ public class AppcResponseCreator { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AppcResponseCreator.class); + // The request from APPC private final String jsonRequestString; @@ -48,7 +49,7 @@ public class AppcResponseCreator { /** * Respond to the given APPC request after the given amount of milliseconds. - * + * * @param appcResponseQueue the queue into which to put the APPC response * @param jsonRequestString the request JSON string * @param milliSecondsToWait the number of milliseconds to wait @@ -68,25 +69,37 @@ public class AppcResponseCreator { */ @Override public void run() { - Gson gson = new GsonBuilder().registerTypeAdapter(LcmRequest.class, new Serialization.RequestAdapter()) - .registerTypeAdapter(LcmResponse.class, new Serialization.ResponseAdapter()) - .setPrettyPrinting().create(); - LcmRequestWrapper requestWrapper = gson.fromJson(jsonRequestString, LcmRequestWrapper.class); + StandardCoder standardCoder = new StandardCoder(); + + AppcLcmDmaapWrapper requestWrapper = null; + try { + requestWrapper = standardCoder.decode(jsonRequestString, AppcLcmDmaapWrapper.class); + } catch (CoderException e) { + LOGGER.warn("decoding of the APPC request message failed", e); + return; + } + + AppcLcmInput request = requestWrapper.getBody().getInput(); - LcmResponse response = new LcmResponse(requestWrapper.getBody()); + AppcLcmOutput response = new AppcLcmOutput(request); response.getStatus().setCode(400); response.getStatus().setMessage("Restart Successful"); - LcmResponseWrapper responseWrapper = new LcmResponseWrapper(); - responseWrapper.setBody(response); + AppcLcmDmaapWrapper responseWrapper = new AppcLcmDmaapWrapper(); + responseWrapper.getBody().setOutput(response); responseWrapper.setVersion(requestWrapper.getVersion()); responseWrapper.setRpcName(requestWrapper.getRpcName()); responseWrapper.setCorrelationId(requestWrapper.getCorrelationId()); responseWrapper.setType(requestWrapper.getType()); - appcResponseQueue.add(gson.toJson(responseWrapper, LcmResponseWrapper.class)); + try { + appcResponseQueue.add(standardCoder.encode(responseWrapper)); + } catch (CoderException e) { + LOGGER.warn("encoding of the APPC request message failed", e); + return; + } } } } |