/*******************************************************************************
 * Copyright 2017 University of Stuttgart
 *
 * 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
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *******************************************************************************/
package org.opentosca.container.api.config;

import java.io.IOException;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.ext.Provider;

import org.opentosca.container.api.util.UriUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Provider
public class LogFilter implements ContainerRequestFilter {

    private static final Logger logger = LoggerFactory.getLogger(LogFilter.class.getName());

    @Override
    public void filter(final ContainerRequestContext request) throws IOException {
        logger.debug("LogFilter.filter()");
        logger.debug("Method: {}", request.getMethod());
        logger.debug("URL: {}", UriUtil.encode(request.getUriInfo().getAbsolutePath()));
        for (final String key : request.getHeaders().keySet()) {
            logger.debug(key + " : " + request.getHeaders().get(key));
        }
        // final List<MediaType> mediaTypes =
        // Lists.newArrayList(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE,
        // MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_XML_TYPE, MediaType.TEXT_HTML_TYPE);
        // if (request.getMediaType() != null && mediaTypes.contains(request.getMediaType())) {
        // if (request.hasEntity()) {
        // final String body = IOUtils.toString(request.getEntityStream());
        // request.setEntityStream(IOUtils.toInputStream(body));
        // logger.debug("Body: {}", body);
        // }
        // }
    }
}

@@ -818,16 +818,39 @@
 ception;
+%0Aimport java.util.List;
 %0A%0Aimport
@@ -973,22 +973,95 @@
 .rs.
-ext.Provider;%0A
+core.MediaType;%0Aimport javax.ws.rs.ext.Provider;%0A%0Aimport org.apache.commons.io.IOUtils;
 %0Aimp
@@ -1164,16 +1164,57 @@
 ctory;%0A%0A
+import com.google.common.collect.Lists;%0A%0A
 @Provide
@@ -1466,16 +1466,59 @@
 ption %7B%0A
+        if (logger.isDebugEnabled()) %7B%0A    
         
@@ -1531,16 +1531,20 @@
 .debug(%22
+=== 
 LogFilte
@@ -1548,21 +1548,26 @@
 lter
-.filter()%22);%0A
+ BEGIN ===%22);%0A    
     
@@ -1619,32 +1619,36 @@
 hod());%0A        
+  
+  
 logger.debug(%22UR
@@ -1720,16 +1720,20 @@
         
+    
 for (fin
@@ -1785,32 +1785,36 @@
 ) %7B%0A            
+  
+  
 logger.debug(key
@@ -1864,16 +1864,20 @@
         
+    
 %7D%0A      
@@ -1874,26 +1874,27 @@
   %7D%0A        
-//
+   
  final List%3C
@@ -1925,18 +1925,23 @@
         
-//
+       
  Lists.n
@@ -2025,18 +2025,42 @@
         
-//
+                          
  MediaTy
@@ -2131,34 +2131,35 @@
 _TYPE);%0A        
-//
+   
  if (request.get
@@ -2236,18 +2236,23 @@
         
-//
+       
  if (req
@@ -2279,18 +2279,27 @@
         
-//
+           
  final S
@@ -2364,18 +2364,27 @@
         
-//
+           
  request
@@ -2438,18 +2438,27 @@
         
-//
+           
  logger.
@@ -2486,26 +2486,31 @@
 y);%0A        
-//
+       
  %7D%0A        /
@@ -2508,18 +2508,80 @@
         
-//
+    %7D%0A            logger.debug(%22=== LogFilter END ===%22);%0A       
  %7D%0A    %7D

Enhance LogFilter class