diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java')
-rw-r--r-- | bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java new file mode 100644 index 000000000..28689fd01 --- /dev/null +++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2014 Raymond Augé and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Raymond Augé <raymond.auge@liferay.com> - Bug 436698 + ******************************************************************************/ + +package org.eclipse.equinox.http.servlet.tests.tb1; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.Filter; +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.equinox.http.servlet.ExtendedHttpService; +import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet; +import org.eclipse.equinox.http.servlet.tests.util.BaseFilter; + +import org.osgi.service.component.ComponentContext; +import org.osgi.service.http.NamespaceException; + +/* + * This servlet is registered with the HttpService via the immediate DS + * component OSGI-INF/testServlet1_component.xml. + */ +public class TestErrorPage2 extends AbstractTestServlet { + private static final long serialVersionUID = 1L; + + @Override + public void activate(ComponentContext componentContext) throws ServletException, NamespaceException { + ExtendedHttpService service = (ExtendedHttpService)getHttpService(); + service.registerServlet(this, "S1", new String[] {regexAlias()}, null, false, null, null); + service.registerServlet(errorServlet, "E1", null, new String[] {MyException.class.getName()}, false, null, null); + } + + @Override + public void deactivate() { + ExtendedHttpService service = (ExtendedHttpService)getHttpService(); + service.unregisterServlet(this, null); + service.unregisterServlet(errorServlet, null); + } + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException ,IOException { + + throw new MyException(); + } + + Filter f1 = new BaseFilter('b'); + Servlet errorServlet = new HttpServlet() { + + @Override + protected void service( + HttpServletRequest request, HttpServletResponse response) + throws ServletException ,IOException { + + if (response.isCommitted()) { + System.out.println("Problem?"); + + return; + } + + PrintWriter writer = response.getWriter(); + + String requestURI = (String)request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI); + String exception = (String)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE); + + writer.print(exception + " ERROR : " + requestURI); + } + + }; + + public class MyException extends ServletException { + } + +} |