View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.webapp;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import javax.servlet.http.HttpServletResponse;
26  import javax.servlet.http.HttpServletResponseWrapper;
27  
28  public class DebugContentTypeResponse extends HttpServletResponseWrapper {
29    private static final Logger LOG = LoggerFactory.getLogger(DebugContentTypeResponse.class);
30  
31    public DebugContentTypeResponse(final HttpServletResponse response) {
32      super(response);
33    }
34  
35    @Override
36    public void setContentType(final String type) {
37      if (LOG.isDebugEnabled()) {
38        LOG.debug("Setting Content-Type to '" + type + "'.", new Exception());
39      }
40      super.setContentType(type);
41    }
42  
43    @Override
44    public String getContentType() {
45      final String type = super.getContentType();
46      if (LOG.isDebugEnabled()) {
47        LOG.debug("Getting Content-Type '" + type + "'.", new Exception());
48      }
49      return type;
50    }
51  
52    @Override
53    public void setHeader(final String name, final String value) {
54      if ("Content-Type".equals(name)) {
55        if (LOG.isDebugEnabled()) {
56          LOG.debug("Setting Content-Type to '" + value + "'.", new Exception());
57        }
58      }
59      super.setHeader(name, value);
60    }
61  
62    @Override
63    public void addHeader(final String name, final String value) {
64      if ("Content-Type".equals(name)) {
65        if (LOG.isDebugEnabled()) {
66          LOG.debug("Setting Content-Type to '" + value + "'.", new Exception());
67        }
68      }
69      super.addHeader(name, value);
70    }
71  }