001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.servlet;
016    
017    import javax.servlet.http.HttpServletRequest;
018    
019    /**
020     * @author Igor Spasic
021     */
022    public class NonSerializableObjectRequestWrapper
023            extends PersistentHttpServletRequestWrapper {
024    
025            public static boolean isWrapped(HttpServletRequest request) {
026                    Class<?> clazz = request.getClass();
027    
028                    String className = clazz.getName();
029    
030                    if (className.startsWith("weblogic.")) {
031                            request.removeAttribute(
032                                    NonSerializableObjectRequestWrapper.class.getName());
033    
034                            return false;
035                    }
036    
037                    Boolean wrapped = (Boolean)request.getAttribute(
038                            NonSerializableObjectRequestWrapper.class.getName());
039    
040                    if (wrapped == null) {
041                            return false;
042                    }
043    
044                    return wrapped.booleanValue();
045            }
046    
047            public NonSerializableObjectRequestWrapper(HttpServletRequest request) {
048                    super(request);
049    
050                    request.setAttribute(
051                            NonSerializableObjectRequestWrapper.class.getName(), Boolean.TRUE);
052            }
053    
054            @Override
055            public Object getAttribute(String name) {
056                    Object object = super.getAttribute(name);
057    
058                    object = NonSerializableObjectHandler.getValue(object);
059    
060                    return object;
061            }
062    
063            @Override
064            public void setAttribute(String name, Object object) {
065                    object = new NonSerializableObjectHandler(object);
066    
067                    super.setAttribute(name, object);
068            }
069    
070    }