001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.testapp.interactive.testscreen;
031:
032: import nextapp.echo2.app.Alignment;
033: import nextapp.echo2.app.Border;
034: import nextapp.echo2.app.Button;
035: import nextapp.echo2.app.Color;
036: import nextapp.echo2.app.Column;
037: import nextapp.echo2.app.Extent;
038: import nextapp.echo2.app.Grid;
039: import nextapp.echo2.app.Insets;
040: import nextapp.echo2.app.Label;
041: import nextapp.echo2.app.MutableStyle;
042: import nextapp.echo2.app.Style;
043: import nextapp.echo2.app.TextField;
044: import nextapp.echo2.app.event.ActionEvent;
045: import nextapp.echo2.app.event.ActionListener;
046: import nextapp.echo2.app.layout.GridLayoutData;
047: import nextapp.echo2.app.layout.SplitPaneLayoutData;
048: import nextapp.echo2.webcontainer.ContainerContext;
049: import nextapp.echo2.webrender.ClientConfiguration;
050: import nextapp.echo2.webrender.WebRenderServlet;
051:
052: /**
053: * Interactive test for client configuration settings.
054: */
055: public class ClientConfigurationTest extends Column {
056:
057: private static final Style PROMPT_STYLE;
058: static {
059: MutableStyle style = new MutableStyle();
060: GridLayoutData layoutData = new GridLayoutData();
061: layoutData.setAlignment(new Alignment(Alignment.RIGHT,
062: Alignment.TOP));
063: style.setProperty(PROPERTY_LAYOUT_DATA, layoutData);
064: PROMPT_STYLE = style;
065: }
066:
067: private TextField serverErrorUriText, serverErrorMessageText,
068: sessionExpirationUriText, sessionExpirationMessageText;
069:
070: /**
071: * Default constructor.
072: */
073: public ClientConfigurationTest() {
074: super ();
075: SplitPaneLayoutData splitPaneLayoutData = new SplitPaneLayoutData();
076: splitPaneLayoutData.setInsets(new Insets(10));
077: setLayoutData(splitPaneLayoutData);
078: setCellSpacing(new Extent(20));
079:
080: Grid grid = new Grid(2);
081: grid.setBorder(new Border(2, Color.BLUE, Border.STYLE_GROOVE));
082: grid.setInsets(new Insets(10, 5));
083: add(grid);
084:
085: Label label;
086:
087: label = new Label("Server Error URI:");
088: label.setStyle(PROMPT_STYLE);
089: grid.add(label);
090:
091: serverErrorUriText = new TextField();
092: serverErrorUriText.setStyleName("Default");
093: grid.add(serverErrorUriText);
094:
095: label = new Label("Server Error Message:");
096: label.setStyle(PROMPT_STYLE);
097: grid.add(label);
098:
099: serverErrorMessageText = new TextField();
100: serverErrorMessageText.setStyleName("Default");
101: grid.add(serverErrorMessageText);
102:
103: label = new Label("Session Expiration URI:");
104: label.setStyle(PROMPT_STYLE);
105: grid.add(label);
106:
107: sessionExpirationUriText = new TextField();
108: sessionExpirationUriText.setStyleName("Default");
109: grid.add(sessionExpirationUriText);
110:
111: label = new Label("Session Expiration Message:");
112: label.setStyle(PROMPT_STYLE);
113: grid.add(label);
114:
115: sessionExpirationMessageText = new TextField();
116: sessionExpirationMessageText.setStyleName("Default");
117: grid.add(sessionExpirationMessageText);
118:
119: Button updateButton = new Button("Update ClientConfiguration");
120: updateButton.setStyleName("Default");
121: updateButton.addActionListener(new ActionListener() {
122: public void actionPerformed(ActionEvent e) {
123: updateClientConfiguration();
124: }
125: });
126: add(updateButton);
127:
128: Button exceptionButton = new Button("Throw a RuntimeException");
129: exceptionButton.setStyleName("Default");
130: exceptionButton.addActionListener(new ActionListener() {
131: public void actionPerformed(ActionEvent e) {
132: throw new RuntimeException(
133: "Test RuntimeException thrown at user request by ClientConfigurationTest.");
134: }
135: });
136: add(exceptionButton);
137:
138: Button expireSessionButton = new Button("Expire Session");
139: expireSessionButton.setStyleName("Default");
140: expireSessionButton.addActionListener(new ActionListener() {
141: public void actionPerformed(ActionEvent e) {
142: WebRenderServlet.getActiveConnection().getRequest()
143: .getSession().invalidate();
144: }
145: });
146: add(expireSessionButton);
147: }
148:
149: /**
150: * Performs <code>ClientConfigurationUpdate</code>.
151: */
152: private void updateClientConfiguration() {
153: ClientConfiguration clientConfiguration = new ClientConfiguration();
154: if (serverErrorUriText.getText().trim().length() > 0) {
155: clientConfiguration.setProperty(
156: ClientConfiguration.PROPERTY_SERVER_ERROR_URI,
157: serverErrorUriText.getText());
158: }
159: if (serverErrorMessageText.getText().trim().length() > 0) {
160: clientConfiguration.setProperty(
161: ClientConfiguration.PROPERTY_SERVER_ERROR_MESSAGE,
162: serverErrorMessageText.getText());
163: }
164: if (sessionExpirationUriText.getText().trim().length() > 0) {
165: clientConfiguration
166: .setProperty(
167: ClientConfiguration.PROPERTY_SESSION_EXPIRATION_URI,
168: sessionExpirationUriText.getText());
169: }
170: if (sessionExpirationMessageText.getText().trim().length() > 0) {
171: clientConfiguration
172: .setProperty(
173: ClientConfiguration.PROPERTY_SESSION_EXPIRATION_MESSAGE,
174: sessionExpirationMessageText.getText());
175: }
176:
177: ContainerContext containerContext = (ContainerContext) getApplicationInstance()
178: .getContextProperty(
179: ContainerContext.CONTEXT_PROPERTY_NAME);
180: containerContext.setClientConfiguration(clientConfiguration);
181: }
182: }
|