diff --git a/core/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java b/core/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java deleted file mode 100644 index 42a9951a4..000000000 --- a/core/src/main/java/org/apache/struts2/portlet/context/PreparatorServlet.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.struts2.portlet.context; - -import java.io.IOException; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts2.StrutsStatics; - -import com.opensymphony.xwork2.ActionContext; - -/** - * Since a portlet is not dispatched the same way as a servlet, the - * {@link org.apache.struts2.ServletActionContext} is not immediately available, as it - * depends on objects from the servlet API. However, the WW2 view implementations require access - * to the objects in the {@link org.apache.struts2.ServletActionContext}, and this servlet - * makes sure that these are available when the portlet actions are executing the render results. - * - */ -public class PreparatorServlet extends HttpServlet implements StrutsStatics { - - private static final long serialVersionUID = 1853399729352984089L; - - private final static Log LOG = LogFactory.getLog(PreparatorServlet.class); - - /** - * Prepares the {@link org.apache.struts2.ServletActionContext} with the - * {@link ServletContext}, {@link HttpServletRequest} and {@link HttpServletResponse}. - */ - public void service(HttpServletRequest servletRequest, - HttpServletResponse servletResponse) throws ServletException, - IOException { - LOG.debug("Preparing servlet objects for dispatch"); - ServletContext ctx = getServletContext(); - ActionContext.getContext().put(SERVLET_CONTEXT, ctx); - ActionContext.getContext().put(HTTP_REQUEST, servletRequest); - ActionContext.getContext().put(HTTP_RESPONSE, servletResponse); - LOG.debug("Preparation complete"); - } - -} diff --git a/core/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java b/core/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java deleted file mode 100644 index 74e799484..000000000 --- a/core/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.struts2.portlet.context; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -/** - * Some of the factory/managers (e.g. the ObjectFactory) need access to - * the {@link org.apache.struts2.ServletActionContext} object when initializing. - * This {@link javax.servlet.ServletContextListener} keeps a reference to the - * {@link javax.servlet.ServletContext} and exposes it through a public static - * method. - * - */ -public class ServletContextHolderListener implements ServletContextListener { - - private static ServletContext context = null; - - /** - * @return The current servlet context - */ - public static ServletContext getServletContext() { - return context; - } - - /** - * Stores the reference to the {@link ServletContext}. - * - * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) - */ - public void contextInitialized(ServletContextEvent event) { - context = event.getServletContext(); - - } - - /** - * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) - */ - public void contextDestroyed(ServletContextEvent event) { - context = null; - } - -} diff --git a/core/src/main/java/org/apache/struts2/portlet/util/HttpServletRequestMock.java b/core/src/main/java/org/apache/struts2/portlet/util/HttpServletRequestMock.java deleted file mode 100644 index 939756606..000000000 --- a/core/src/main/java/org/apache/struts2/portlet/util/HttpServletRequestMock.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.struts2.portlet.util; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.Enumeration; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletInputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; - -/** - * A simple mock class to interact with Struts 2 API's that require a servlet request - */ -public class HttpServletRequestMock implements HttpServletRequest { - - private String servletPath; - private Map parameterMap; - - public String getAuthType() { - return null; - } - - public String getContextPath() { - return null; - } - - public Cookie[] getCookies() { - return null; - } - - public long getDateHeader(String arg0) { - return 0; - } - - public String getHeader(String arg0) { - return null; - } - - public Enumeration getHeaderNames() { - return null; - } - - public Enumeration getHeaders(String arg0) { - return null; - } - - public int getIntHeader(String arg0) { - return 0; - } - - public String getMethod() { - return null; - } - - public String getPathInfo() { - return null; - } - - public String getPathTranslated() { - return null; - } - - public String getQueryString() { - return null; - } - - public String getRemoteUser() { - return null; - } - - public String getRequestURI() { - return null; - } - - public StringBuffer getRequestURL() { - return null; - } - - public String getRequestedSessionId() { - return null; - } - - public String getServletPath() { - return servletPath; - } - - public HttpSession getSession() { - return null; - } - - public HttpSession getSession(boolean arg0) { - return null; - } - - public Principal getUserPrincipal() { - return null; - } - - public boolean isRequestedSessionIdFromCookie() { - return false; - } - - public boolean isRequestedSessionIdFromURL() { - return false; - } - - public boolean isRequestedSessionIdFromUrl() { - return false; - } - - public boolean isRequestedSessionIdValid() { - return false; - } - - public boolean isUserInRole(String arg0) { - return false; - } - - public Object getAttribute(String arg0) { - return null; - } - - public Enumeration getAttributeNames() { - return null; - } - - public String getCharacterEncoding() { - return null; - } - - public int getContentLength() { - return 0; - } - - public String getContentType() { - return null; - } - - public ServletInputStream getInputStream() throws IOException { - return null; - } - - public String getLocalAddr() { - return null; - } - - public String getLocalName() { - return null; - } - - public int getLocalPort() { - return 0; - } - - public Locale getLocale() { - return null; - } - - public Enumeration getLocales() { - return null; - } - - public String getParameter(String arg0) { - return null; - } - - public Map getParameterMap() { - return parameterMap; - } - - public Enumeration getParameterNames() { - return null; - } - - public String[] getParameterValues(String arg0) { - return null; - } - - public String getProtocol() { - return null; - } - - public BufferedReader getReader() throws IOException { - return null; - } - - public String getRealPath(String arg0) { - return null; - } - - public String getRemoteAddr() { - return null; - } - - public String getRemoteHost() { - return null; - } - - public int getRemotePort() { - return 0; - } - - public RequestDispatcher getRequestDispatcher(String arg0) { - return null; - } - - public String getScheme() { - return null; - } - - public String getServerName() { - return null; - } - - public int getServerPort() { - return 0; - } - - public boolean isSecure() { - return false; - } - - public void removeAttribute(String arg0) { - } - - public void setAttribute(String arg0, Object arg1) { - } - - public void setCharacterEncoding(String arg0) - throws UnsupportedEncodingException { - - } - - /** - * @param parameterMap the parameterMap to set - */ - public HttpServletRequestMock setParameterMap(Map parameterMap) { - this.parameterMap = parameterMap; - return this; - } - - /** - * @param servletPath the servletPath to set - */ - public HttpServletRequestMock setServletPath(String servletPath) { - this.servletPath = servletPath; - return this; - } - - - -} diff --git a/core/src/test/java/org/apache/struts2/portlet/context/PreparatorServletTest.java b/core/src/test/java/org/apache/struts2/portlet/context/PreparatorServletTest.java deleted file mode 100644 index 6aa21eb78..000000000 --- a/core/src/test/java/org/apache/struts2/portlet/context/PreparatorServletTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.struts2.portlet.context; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.StrutsTestCase; -import org.easymock.MockControl; - -/** - * - * Test for the {@link PreparatorServletTest} - * - */ -public class PreparatorServletTest extends StrutsTestCase { - - /** - * Test that the service method stores the request, response and servlet context - * in the {@link com.opensymphony.xwork2.ActionContext} - */ - public void testServiceHttpServletRequestHttpServletResponse() throws Exception { - MockControl mockRequest = MockControl.createNiceControl(HttpServletRequest.class); - MockControl mockResponse = MockControl.createNiceControl(HttpServletResponse.class); - MockControl mockContext = MockControl.createNiceControl(ServletContext.class); - MockControl mockConfig = MockControl.createNiceControl(ServletConfig.class); - - HttpServletRequest req = (HttpServletRequest)mockRequest.getMock(); - HttpServletResponse res = (HttpServletResponse)mockResponse.getMock(); - ServletContext context = (ServletContext)mockContext.getMock(); - ServletConfig config = (ServletConfig)mockConfig.getMock(); - - mockConfig.expectAndDefaultReturn(config.getServletContext(), context); - mockConfig.replay(); - - PreparatorServlet servlet = new PreparatorServlet(); - servlet.init(config); - servlet.service(req, res); - assertSame(req, ServletActionContext.getRequest()); - assertSame(res, ServletActionContext.getResponse()); - assertSame(context, ServletActionContext.getServletContext()); - - mockConfig.verify(); - } - -} diff --git a/core/src/test/java/org/apache/struts2/portlet/context/ServletContextHolderListenerTest.java b/core/src/test/java/org/apache/struts2/portlet/context/ServletContextHolderListenerTest.java deleted file mode 100644 index 23ad49897..000000000 --- a/core/src/test/java/org/apache/struts2/portlet/context/ServletContextHolderListenerTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.struts2.portlet.context; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import junit.framework.TestCase; - -import org.easymock.MockControl; - -/** - */ -public class ServletContextHolderListenerTest extends TestCase { - - public void testContextInitialized() { - MockControl mockContext = MockControl.createNiceControl(ServletContext.class); - ServletContext context = (ServletContext)mockContext.getMock(); - ServletContextEvent event = new ServletContextEvent(context); - ServletContextHolderListener listener = new ServletContextHolderListener(); - listener.contextInitialized(event); - assertSame(ServletContextHolderListener.getServletContext(), context); - - listener.contextDestroyed(event); - assertNull(ServletContextHolderListener.getServletContext()); - } - -}