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 com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    
020    import java.io.NotSerializableException;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Igor Spasic
026     */
027    public class NonSerializableObjectRequestWrapper
028            extends PersistentHttpServletRequestWrapper {
029    
030            public static boolean isWrapped(HttpServletRequest request) {
031                    Class<?> clazz = request.getClass();
032    
033                    String className = clazz.getName();
034    
035                    if (className.startsWith("weblogic.")) {
036                            request.removeAttribute(
037                                    NonSerializableObjectRequestWrapper.class.getName());
038    
039                            return false;
040                    }
041    
042                    Boolean wrapped = (Boolean)request.getAttribute(
043                            NonSerializableObjectRequestWrapper.class.getName());
044    
045                    if (wrapped == null) {
046                            return false;
047                    }
048    
049                    return wrapped.booleanValue();
050            }
051    
052            public NonSerializableObjectRequestWrapper(HttpServletRequest request) {
053                    super(request);
054    
055                    request.setAttribute(
056                            NonSerializableObjectRequestWrapper.class.getName(), Boolean.TRUE);
057            }
058    
059            @Override
060            public Object getAttribute(String name) {
061                    Object object = null;
062    
063                    try {
064                            object = super.getAttribute(name);
065                    }
066                    catch (Exception e) {
067                            if (e instanceof NotSerializableException) {
068    
069                                    // LPS-31885
070    
071                                    String message = e.getMessage();
072    
073                                    if ((message == null) || !message.contains("BEA-101362")) {
074                                            _log.error(e, e);
075                                    }
076                            }
077    
078                            return null;
079                    }
080    
081                    object = NonSerializableObjectHandler.getValue(object);
082    
083                    return object;
084            }
085    
086            @Override
087            public void setAttribute(String name, Object object) {
088                    object = new NonSerializableObjectHandler(object);
089    
090                    super.setAttribute(name, object);
091            }
092    
093            private static Log _log = LogFactoryUtil.getLog(
094                    NonSerializableObjectRequestWrapper.class);
095    
096    }