f0ec2769c1d64d01c11d70273844a2fd5e2bb6fc
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / scheduler / client / HttpBasicClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.portalapp.portal.scheduler.client;
22
23
24 import java.text.DateFormat;
25 import java.text.SimpleDateFormat;
26
27 import javax.servlet.ServletContext;
28 import javax.ws.rs.client.Client;
29 import javax.ws.rs.client.ClientBuilder;
30
31 import org.glassfish.jersey.client.ClientConfig;
32 import org.glassfish.jersey.client.ClientProperties;
33 import org.openecomp.portalapp.portal.scheduler.util.CustomJacksonJaxBJsonProvider;
34 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
35 import org.springframework.beans.factory.annotation.Autowired;
36
37 /**
38  *  General HTTP client.
39  */
40
41 public class HttpBasicClient{
42         
43         /** The servlet context. */
44         @Autowired 
45         private ServletContext servletContext;
46         
47         /** The logger. */
48         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpBasicClient.class);
49         
50         /** The Constant dateFormat. */
51         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
52         
53         /**
54          * Obtain a basic HTTP client .
55          *
56          * @return Client client object
57          * @throws Exception the exception
58          */
59         public static Client getClient() throws Exception {
60                 
61                 ClientConfig config = new ClientConfig();
62                 config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
63                 
64                 return ClientBuilder.newClient(config)
65                                 .register(CustomJacksonJaxBJsonProvider.class);
66         }       
67 }