1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.common.database.requests;
20 import java.io.UnsupportedEncodingException;
21 import java.net.URLEncoder;
22 import java.nio.charset.StandardCharsets;
24 import org.elasticsearch.client.Request;
25 import org.json.JSONObject;
26 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public abstract class BaseRequest {
32 private static final Logger LOG = LoggerFactory.getLogger(BaseRequest.class);
34 protected final Request request;
36 public BaseRequest(String method, String endpoint) {
37 LOG.debug("create request {} {}", method, endpoint);
38 this.request = new Request(method, endpoint);
42 public Request getInner() {
47 public static String urlEncodeValue(String value) {
51 return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()).replace("+", "%20");
52 } catch (UnsupportedEncodingException ex) {
53 LOG.warn("encoding problem: {}", ex.getMessage());
58 public String toString() {
59 return this.request.getMethod() + " "+this.request.getEndpoint()+ " : "+(this.query!=null?this.query:"no query");
62 protected void setQuery(QueryBuilder query) {
63 this.setQuery(query.toJSON());
66 public void setQuery(JSONObject o) {
67 this.setQuery(o.toString());
70 public void setQuery(String content) {
72 LOG.trace("query={}",content);
73 this.request.setJsonEntity(this.query);