ce930c9a2a8c43a48d4133c7cc497224ea430f2c
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / scheduler / policy / PolicyRestInt.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.policy;
22
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
26
27 import org.openecomp.portalapp.portal.scheduler.policy.rest.RequestDetails;
28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
29
30 import com.fasterxml.jackson.databind.ObjectMapper;
31
32 public class PolicyRestInt {
33         
34         /** The logger. */
35         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyRestInterface.class);
36         
37         /** The Constant dateFormat. */
38         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
39         
40         /** The request date format. */
41         public DateFormat requestDateFormat = new SimpleDateFormat("EEE, dd MMM YYYY HH:mm:ss z");
42         
43         public PolicyRestInt() {
44                 requestDateFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
45         }
46
47         /**
48          * Log request.
49          *
50          * @param r the r
51          */
52         public void logRequest ( RequestDetails r ) {
53         String methodName = "logRequest";
54             ObjectMapper mapper = new ObjectMapper();
55             String r_json_str = "";
56             if ( r != null ) {
57                 r_json_str = r.toString();
58                     try {
59                         r_json_str = mapper.writeValueAsString(r);
60                     }
61                     catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
62                         logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " +  methodName + " Unable to parse request as json");
63                     }
64             }
65             logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " +  methodName + " Request=(" + r_json_str + ")");  
66     }
67 }