2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.listener.LCM.operation;
28 import com.fasterxml.jackson.databind.JsonNode;
29 import org.json.JSONObject;
30 import org.onap.appc.exceptions.APPCException;
31 import org.onap.appc.listener.LCM.model.InputBody;
32 import org.onap.appc.listener.LCM.model.ResponseStatus;
33 import org.onap.appc.listener.util.Mapper;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
40 public class GenericProviderOperationRequestFormatter implements ProviderOperationRequestFormatter {
42 private final EELFLogger LOG = EELFManager.getInstance().getLogger(GenericProviderOperationRequestFormatter.class);
45 @SuppressWarnings("nls")
46 private final static String TEMPLATE = "{\"input\": %s}";
50 public String buildPath(URL url, String rpcName) {
51 return url.getPath() + ":" + rpcName;
55 public String buildRequest(InputBody msg) {
56 JSONObject jsonObject = Mapper.toJsonObject(msg);
57 return String.format(TEMPLATE, jsonObject.toString());
61 public ResponseStatus getResponseStatus(JsonNode responseBody)throws APPCException{
63 JsonNode status = responseBody.get("output").get("status");
64 return new ResponseStatus(status.get("code").asInt(), status.get("message").asText());
65 } catch (Exception e) {
66 LOG.error("Unknown error processing failed response from provider. Json not in expected format", e);
67 throw new APPCException("APPC has an unknown RPC error");
72 public String getLocked(JSONObject responseBody) throws APPCException {
74 JSONObject outputObject=responseBody.getJSONObject("output");
75 if(outputObject.has("locked")){
76 return outputObject.getString("locked");
80 } catch (Exception e) {
81 LOG.error("Unknown error processing failed response from provider. Json not in expected format", e);
82 throw new APPCException("APPC has an unknown RPC error");