2 * ============LICENSE_START=============================================================================================================
3 * Copyright (c) 2017 Intel Corp. All rights reserved.
4 * ===================================================================
5 * 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
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * 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
10 * OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
11 * ============LICENSE_END===============================================================================================================
15 package org.onap.appc.adapter.rest;
17 import com.att.eelf.configuration.EELFLogger;
18 import com.att.eelf.configuration.EELFManager;
19 import org.apache.http.client.methods.HttpDelete;
20 import org.apache.http.client.methods.HttpGet;
21 import org.apache.http.client.methods.HttpPost;
22 import org.apache.http.client.methods.HttpPut;
23 import org.apache.http.client.methods.HttpRequestBase;
24 import org.apache.http.client.utils.URIBuilder;
27 import java.net.URISyntaxException;
28 import java.util.HashMap;
30 import java.util.function.Supplier;
32 public class RequestFactory {
33 private final EELFLogger logger = EELFManager.getInstance().getLogger(RequestFactory.class);
35 final static Map<String, Supplier<HttpRequestBase>> map = new HashMap<>();
38 map.put("GET", HttpGet::new);
39 map.put("POST", HttpPost::new);
40 map.put("PUT", HttpPut::new);
41 map.put("DELETE", HttpDelete::new);
44 public HttpRequestBase getHttpRequest(String method, String tUrl) {
45 Supplier<HttpRequestBase> httpRequestSupplier = map.get(method.toUpperCase());
47 if (httpRequestSupplier != null ) {
49 uri = new URIBuilder(tUrl).build();
50 } catch (URISyntaxException ex) {
51 logger.error("URI Syntax Incorrect: " + tUrl, ex);
53 HttpRequestBase httpRequest = httpRequestSupplier.get();
54 httpRequest.setURI(uri);
58 throw new IllegalArgumentException("No method named: " + method.toUpperCase());