Source Code Cross Referenced for ConnectorPortlet.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » webmanager » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.console.webmanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.console.webmanager;
017:
018:        import java.io.IOException;
019:        import java.net.URI;
020:        import java.util.ArrayList;
021:        import java.util.Collections;
022:        import java.util.Comparator;
023:        import java.util.HashMap;
024:        import java.util.List;
025:
026:        import javax.portlet.ActionRequest;
027:        import javax.portlet.ActionResponse;
028:        import javax.portlet.PortletConfig;
029:        import javax.portlet.PortletContext;
030:        import javax.portlet.PortletException;
031:        import javax.portlet.PortletRequest;
032:        import javax.portlet.PortletRequestDispatcher;
033:        import javax.portlet.RenderRequest;
034:        import javax.portlet.RenderResponse;
035:        import javax.portlet.WindowState;
036:
037:        import org.apache.commons.logging.Log;
038:        import org.apache.commons.logging.LogFactory;
039:        import org.apache.geronimo.console.BasePortlet;
040:        import org.apache.geronimo.console.util.PortletManager;
041:        import org.apache.geronimo.gbean.AbstractName;
042:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
043:        import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
044:        import org.apache.geronimo.management.geronimo.KeystoreException;
045:        import org.apache.geronimo.management.geronimo.KeystoreInstance;
046:        import org.apache.geronimo.management.geronimo.KeystoreManager;
047:        import org.apache.geronimo.management.geronimo.NetworkConnector;
048:        import org.apache.geronimo.management.geronimo.SecureConnector;
049:        import org.apache.geronimo.management.geronimo.WebContainer;
050:        import org.apache.geronimo.management.geronimo.WebManager;
051:        import org.apache.geronimo.management.geronimo.WebManager.ConnectorAttribute;
052:        import org.apache.geronimo.management.geronimo.WebManager.ConnectorType;
053:        import org.apache.geronimo.crypto.KeystoreUtil;
054:
055:        /**
056:         * A portlet that lets you list, add, remove, start, stop, restart and edit web
057:         * connectors (currently, either Tomcat or Jetty).
058:         *
059:         * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
060:         */
061:        public class ConnectorPortlet extends BasePortlet {
062:            private final static Log log = LogFactory
063:                    .getLog(ConnectorPortlet.class);
064:
065:            public static final String PARM_CONTAINER_URI = "containerURI";
066:            public static final String PARM_CONNECTOR_URI = "connectorURI";
067:            public static final String PARM_MANAGER_URI = "managerURI";
068:            public static final String PARM_MODE = "mode";
069:            public static final String PARM_CONNECTOR_TYPE = "connectorType";
070:            public static final String PARM_CONNECTOR_ATTRIBUTES = "connectorAttributes";
071:            public static final String PARM_DISPLAY_NAME = "uniqueName";
072:            public static final String PARM_SERVER = "server";
073:
074:            private PortletRequestDispatcher normalView;
075:            private PortletRequestDispatcher maximizedView;
076:            private PortletRequestDispatcher helpView;
077:            private PortletRequestDispatcher editConnectorView;
078:
079:            public void processAction(ActionRequest actionRequest,
080:                    ActionResponse actionResponse) throws PortletException,
081:                    IOException {
082:                String submit = actionRequest.getParameter("submit");
083:                if ("Cancel".equalsIgnoreCase(submit)) {
084:                    // User clicked on "Cancel" button in add/edit connector page
085:                    actionResponse.setRenderParameter(PARM_MODE, "list");
086:                    return;
087:                }
088:
089:                String mode = actionRequest.getParameter(PARM_MODE);
090:                String managerURI = actionRequest
091:                        .getParameter(PARM_MANAGER_URI);
092:                String containerURI = actionRequest
093:                        .getParameter(PARM_CONTAINER_URI);
094:                if (managerURI != null)
095:                    actionResponse.setRenderParameter(PARM_MANAGER_URI,
096:                            managerURI);
097:                if (containerURI != null)
098:                    actionResponse.setRenderParameter(PARM_CONTAINER_URI,
099:                            containerURI);
100:                WebContainer webContainer = null;
101:                String server = null;
102:                if (containerURI != null) {
103:                    webContainer = PortletManager.getWebContainer(
104:                            actionRequest, new AbstractName(URI
105:                                    .create(containerURI)));
106:                    server = getWebServerType(webContainer.getClass());
107:                } else {
108:                    server = "unknown";
109:                }
110:                actionResponse.setRenderParameter(PARM_SERVER, server);
111:                if (mode.equals("new")) {
112:                    // User selected to add a new connector, need to show criteria portlet
113:                    actionResponse.setRenderParameter(PARM_MODE, "new");
114:                    String connectorType = actionRequest
115:                            .getParameter(PARM_CONNECTOR_TYPE);
116:                    actionResponse.setRenderParameter(PARM_CONNECTOR_TYPE,
117:                            connectorType);
118:                } else if (mode.equals("add")) { // User just submitted the form to add a new connector
119:                    // Create and configure the connector
120:                    WebManager manager = PortletManager.getWebManager(
121:                            actionRequest, new AbstractName(URI
122:                                    .create(managerURI)));
123:                    ConnectorType connectorType = new ConnectorType(
124:                            actionRequest.getParameter(PARM_CONNECTOR_TYPE));
125:
126:                    String uniqueName = actionRequest
127:                            .getParameter(PARM_DISPLAY_NAME);
128:                    actionResponse.setRenderParameter(PARM_DISPLAY_NAME,
129:                            uniqueName);
130:                    // set the connector attributes from the form post
131:                    List<ConnectorAttribute> connectorAttributes = manager
132:                            .getConnectorAttributes(connectorType);
133:                    for (ConnectorAttribute attribute : connectorAttributes) {
134:                        String name = attribute.getAttributeName();
135:                        String value = actionRequest.getParameter(name);
136:
137:                        // handle booelan type special
138:                        if (attribute.getAttributeClass().equals(Boolean.class)) {
139:                            // browser sends value of checked checkbox as "on" or "checked"
140:                            if ("on".equalsIgnoreCase(value)
141:                                    || "checked".equalsIgnoreCase(value)) {
142:                                value = Boolean.toString(true);
143:                            } else {
144:                                value = Boolean.toString(false);
145:                            }
146:                        }
147:                        // set the string form of the attribute's value as submitted by the browser
148:                        if (value == null || value.trim().length() < 1) {
149:                            // special case for KeystoreManager gbean
150:                            if ("trustStore".equals(attribute
151:                                    .getAttributeName())) {
152:                                attribute.setValue(null);
153:                            }
154:                        } else {
155:                            attribute.setStringValue(value.trim());
156:                        }
157:                    }
158:                    // create the connector gbean based on the configuration data
159:                    AbstractName newConnectorName = manager
160:                            .getConnectorConfiguration(connectorType,
161:                                    connectorAttributes, webContainer,
162:                                    uniqueName);
163:
164:                    // set the keystore properties if its a secure connector
165:                    setKeystoreProperties(actionRequest, newConnectorName);
166:
167:                    // Start the connector
168:                    try {
169:                        GeronimoManagedBean managedBean = PortletManager
170:                                .getManagedBean(actionRequest, newConnectorName);
171:                        managedBean.startRecursive();
172:                    } catch (Exception e) {
173:                        log.error("Unable to start connector", e); //TODO: get into rendered page
174:                    }
175:                    actionResponse.setRenderParameter(PARM_MODE, "list");
176:                } else if (mode.equals("save")) { // User just submitted the form to update a connector
177:                    // Get submitted values
178:                    //todo: lots of validation
179:                    String connectorURI = actionRequest
180:                            .getParameter(PARM_CONNECTOR_URI);
181:                    // Identify and update the connector
182:                    AbstractName connectorName = new AbstractName(URI
183:                            .create(connectorURI));
184:                    NetworkConnector connector = PortletManager
185:                            .getNetworkConnector(actionRequest, connectorName);
186:                    if (connector != null) {
187:                        WebManager manager = PortletManager.getWebManager(
188:                                actionRequest, new AbstractName(URI
189:                                        .create(managerURI)));
190:                        ConnectorType connectorType = manager
191:                                .getConnectorType(connectorName);
192:
193:                        // set the connector attributes from the form post
194:                        for (ConnectorAttribute attribute : manager
195:                                .getConnectorAttributes(connectorType)) {
196:                            String name = attribute.getAttributeName();
197:                            String value = actionRequest.getParameter(name);
198:
199:                            // handle booelan type special
200:                            if (attribute.getAttributeClass().equals(
201:                                    Boolean.class)) {
202:                                // browser sends value of checked checkbox as "on" or "checked"
203:                                if ("on".equalsIgnoreCase(value)
204:                                        || "checked".equalsIgnoreCase(value)) {
205:                                    value = Boolean.toString(true);
206:                                } else {
207:                                    value = Boolean.toString(false);
208:                                }
209:                            }
210:                            // set the string form of the attribute's value as submitted by the browser
211:                            if (value == null || value.trim().length() < 1) {
212:                                // special case for KeystoreManager gbean
213:                                if ("trustStore".equals(attribute
214:                                        .getAttributeName())) {
215:                                    setProperty(connector, name, null);
216:                                }
217:                            } else {
218:                                // set the string value on the ConnectorAttribute so 
219:                                // it can handle type conversion via getValue()
220:                                try {
221:                                    attribute.setStringValue(value);
222:                                    setProperty(connector, name, attribute
223:                                            .getValue());
224:                                } catch (Exception e) {
225:                                    log.error("Unable to set property "
226:                                            + attribute.getAttributeName(), e);
227:                                }
228:                            }
229:                        }
230:
231:                        // set the keystore properties if its a secure connector
232:                        setKeystoreProperties(actionRequest, connectorName);
233:                    }
234:                    actionResponse.setRenderParameter(PARM_MODE, "list");
235:                } else if (mode.equals("start")) {
236:                    String connectorURI = actionRequest
237:                            .getParameter(PARM_CONNECTOR_URI);
238:                    // work with the current connector to start it.
239:                    NetworkConnector connector = PortletManager
240:                            .getNetworkConnector(actionRequest,
241:                                    new AbstractName(URI.create(connectorURI)));
242:                    if (connector != null) {
243:                        try {
244:                            ((GeronimoManagedBean) connector).startRecursive();
245:                        } catch (Exception e) {
246:                            log.error("Unable to start connector", e); //todo: get into rendered page somehow?
247:                        }
248:                    } else {
249:                        log.error("Incorrect connector reference"); //Replace this with correct error processing
250:                    }
251:                    actionResponse.setRenderParameter(PARM_CONNECTOR_URI,
252:                            connectorURI);
253:                    actionResponse.setRenderParameter(PARM_MODE, "list");
254:                } else if (mode.equals("stop")) {
255:                    String connectorURI = actionRequest
256:                            .getParameter(PARM_CONNECTOR_URI);
257:                    // work with the current connector to stop it.
258:                    NetworkConnector connector = PortletManager
259:                            .getNetworkConnector(actionRequest,
260:                                    new AbstractName(URI.create(connectorURI)));
261:                    if (connector != null) {
262:                        try {
263:                            ((GeronimoManagedBean) connector).stop();
264:                        } catch (Exception e) {
265:                            log.error("Unable to stop connector", e); //todo: get into rendered page somehow?
266:                        }
267:                    } else {
268:                        log.error("Incorrect connector reference"); //Replace this with correct error processing
269:                    }
270:                    actionResponse.setRenderParameter(PARM_CONNECTOR_URI,
271:                            connectorURI);
272:                    actionResponse.setRenderParameter(PARM_MODE, "list");
273:                } else if (mode.equals("restart")) {
274:                    String connectorURI = actionRequest
275:                            .getParameter(PARM_CONNECTOR_URI);
276:                    // work with the current connector to restart it.
277:                    NetworkConnector connector = PortletManager
278:                            .getNetworkConnector(actionRequest,
279:                                    new AbstractName(URI.create(connectorURI)));
280:                    if (connector != null) {
281:                        try {
282:                            ((GeronimoManagedBean) connector).stop();
283:                            ((GeronimoManagedBean) connector).start();
284:                        } catch (Exception e) {
285:                            log.error("Unable to restart connector", e); //todo: get into rendered page somehow?
286:                        }
287:                    } else {
288:                        log.error("Incorrect connector reference"); //Replace this with correct error processing
289:                    }
290:                    actionResponse.setRenderParameter(PARM_CONNECTOR_URI,
291:                            connectorURI);
292:                    actionResponse.setRenderParameter(PARM_MODE, "list");
293:                } else if (mode.equals("edit")) {
294:                    String connectorURI = actionRequest
295:                            .getParameter(PARM_CONNECTOR_URI);
296:                    actionResponse.setRenderParameter(PARM_CONNECTOR_URI,
297:                            connectorURI);
298:                    actionResponse.setRenderParameter(PARM_MODE, "edit");
299:
300:                } else if (mode.equals("delete")) { // User chose to delete a connector
301:                    String connectorURI = actionRequest
302:                            .getParameter(PARM_CONNECTOR_URI);
303:                    PortletManager.getWebManager(actionRequest,
304:                            new AbstractName(URI.create(managerURI)))
305:                            .removeConnector(
306:                                    new AbstractName(URI.create(connectorURI)));
307:                    actionResponse.setRenderParameter(PARM_MODE, "list");
308:                }
309:            }
310:
311:            protected void doView(RenderRequest renderRequest,
312:                    RenderResponse renderResponse) throws IOException,
313:                    PortletException {
314:                if (WindowState.MINIMIZED
315:                        .equals(renderRequest.getWindowState())) {
316:                    return;
317:                }
318:                String mode = renderRequest.getParameter(PARM_MODE);
319:                if (mode == null || mode.equals("")) {
320:                    mode = "list";
321:                }
322:
323:                if (mode.equals("list")) {
324:                    doList(renderRequest, renderResponse);
325:                } else {
326:                    String managerURI = renderRequest
327:                            .getParameter(PARM_MANAGER_URI);
328:                    String containerURI = renderRequest
329:                            .getParameter(PARM_CONTAINER_URI);
330:                    if (managerURI != null)
331:                        renderRequest
332:                                .setAttribute(PARM_MANAGER_URI, managerURI);
333:                    if (containerURI != null)
334:                        renderRequest.setAttribute(PARM_CONTAINER_URI,
335:                                containerURI);
336:
337:                    WebContainer container = PortletManager.getWebContainer(
338:                            renderRequest, new AbstractName(URI
339:                                    .create(containerURI)));
340:                    String server = getWebServerType(container.getClass());
341:                    renderRequest.setAttribute(PARM_SERVER, server);
342:
343:                    if (mode.equals("new")) {
344:                        String connectorType = renderRequest
345:                                .getParameter(PARM_CONNECTOR_TYPE);
346:                        WebManager webManager = PortletManager.getWebManager(
347:                                renderRequest, new AbstractName(URI
348:                                        .create(managerURI)));
349:                        ConnectorType type = new ConnectorType(connectorType);
350:                        List<ConnectorAttribute> connectorAttributes = webManager
351:                                .getConnectorAttributes(type);
352:                        sortConnectorAttributes(connectorAttributes);
353:                        renderRequest.setAttribute(PARM_CONNECTOR_ATTRIBUTES,
354:                                connectorAttributes);
355:                        renderRequest.setAttribute(PARM_CONNECTOR_TYPE,
356:                                connectorType);
357:                        renderRequest.setAttribute(PARM_MODE, "add");
358:                        populateEnumAttributes(renderRequest);
359:                        editConnectorView
360:                                .include(renderRequest, renderResponse);
361:                    } else if (mode.equals("edit")) {
362:                        String connectorURI = renderRequest
363:                                .getParameter(PARM_CONNECTOR_URI);
364:                        NetworkConnector connector = PortletManager
365:                                .getNetworkConnector(renderRequest,
366:                                        new AbstractName(URI
367:                                                .create(connectorURI)));
368:                        if (connector == null) {
369:                            doList(renderRequest, renderResponse);
370:                        } else {
371:                            AbstractName connectorName = new AbstractName(URI
372:                                    .create(connectorURI));
373:                            String uniqueName = connectorName.getName().get(
374:                                    "name").toString();
375:                            renderRequest.setAttribute(PARM_DISPLAY_NAME,
376:                                    uniqueName);
377:                            WebManager webManager = PortletManager
378:                                    .getWebManager(renderRequest,
379:                                            new AbstractName(URI
380:                                                    .create(managerURI)));
381:                            ConnectorType connectorType = webManager
382:                                    .getConnectorType(connectorName);
383:                            List<ConnectorAttribute> connectorAttributes = webManager
384:                                    .getConnectorAttributes(connectorType);
385:                            sortConnectorAttributes(connectorAttributes);
386:
387:                            // populate the connector attributes from the connector
388:                            for (ConnectorAttribute attribute : connectorAttributes) {
389:                                try {
390:                                    Object value = getProperty(connector,
391:                                            attribute.getAttributeName());
392:                                    attribute.setValue(value);
393:                                } catch (IllegalArgumentException e) {
394:                                    log
395:                                            .error(
396:                                                    "Unable to retrieve value of property "
397:                                                            + attribute
398:                                                                    .getAttributeName(),
399:                                                    e);
400:                                }
401:                            }
402:
403:                            renderRequest.setAttribute(
404:                                    PARM_CONNECTOR_ATTRIBUTES,
405:                                    connectorAttributes);
406:                            renderRequest.setAttribute(PARM_CONNECTOR_URI,
407:                                    connectorURI);
408:                            // populate any enum type values.  the browser will render them in a
409:                            // <SELECT> input for the attribute
410:                            populateEnumAttributes(renderRequest);
411:
412:                            renderRequest.setAttribute(PARM_MODE, "save");
413:                            editConnectorView.include(renderRequest,
414:                                    renderResponse);
415:                        }
416:                    }
417:                }
418:
419:            }
420:
421:            // sorts connector attributes alphabetically, required attributes listed first
422:            private void sortConnectorAttributes(
423:                    List<ConnectorAttribute> connectorAttributes) {
424:                Collections.sort(connectorAttributes,
425:                        new Comparator<ConnectorAttribute>() {
426:                            public int compare(ConnectorAttribute o1,
427:                                    ConnectorAttribute o2) {
428:                                if (o1.isRequired()) {
429:                                    if (o2.isRequired()) {
430:                                        return o1.getAttributeName().compareTo(
431:                                                o2.getAttributeName());
432:                                    }
433:                                    return -1;
434:                                }
435:                                if (o2.isRequired()) {
436:                                    return 1;
437:                                }
438:                                return o1.getAttributeName().compareTo(
439:                                        o2.getAttributeName());
440:                            }
441:                        });
442:            }
443:
444:            private void doList(RenderRequest renderRequest,
445:                    RenderResponse renderResponse) throws PortletException,
446:                    IOException {
447:                WebManager[] managers = PortletManager
448:                        .getWebManagers(renderRequest);
449:                List<ContainerInfo> all = new ArrayList<ContainerInfo>();
450:                for (int i = 0; i < managers.length; i++) {
451:                    WebManager manager = managers[i];
452:                    AbstractName webManagerName = PortletManager.getNameFor(
453:                            renderRequest, manager);
454:
455:                    WebContainer[] containers = (WebContainer[]) manager
456:                            .getContainers();
457:                    for (int j = 0; j < containers.length; j++) {
458:                        List<ConnectorInfo> beans = new ArrayList<ConnectorInfo>();
459:                        WebContainer container = containers[j];
460:                        AbstractName containerName = PortletManager.getNameFor(
461:                                renderRequest, container);
462:                        String id;
463:                        if (containers.length == 1) {
464:                            id = manager.getProductName();
465:                        } else {
466:                            id = manager.getProductName()
467:                                    + " ("
468:                                    + containerName.getName().get(
469:                                            NameFactory.J2EE_NAME) + ")";
470:                        }
471:                        ContainerInfo result = new ContainerInfo(id,
472:                                webManagerName.toString(), containerName
473:                                        .toString());
474:
475:                        for (NetworkConnector connector : manager
476:                                .getConnectorsForContainer(container)) {
477:                            ConnectorInfo info = new ConnectorInfo();
478:                            AbstractName connectorName = PortletManager
479:                                    .getNameFor(renderRequest, connector);
480:                            info.setConnectorURI(connectorName.toString());
481:                            info.setDescription(PortletManager
482:                                    .getGBeanDescription(renderRequest,
483:                                            connectorName));
484:                            info.setUniqueName((String) connectorName.getName()
485:                                    .get(NameFactory.J2EE_NAME));
486:                            info.setState(((GeronimoManagedBean) connector)
487:                                    .getState());
488:                            info.setPort(connector.getPort());
489:                            try {
490:                                info.setProtocol(connector.getProtocol());
491:                            } catch (IllegalStateException e) {
492:                                info.setProtocol("unknown");
493:                            }
494:                            beans.add(info);
495:                        }
496:                        result.setConnectors(beans);
497:                        result.setConnectorTypes(manager.getConnectorTypes());
498:                        all.add(result);
499:                    }
500:                }
501:                renderRequest.setAttribute("containers", all);
502:                renderRequest.setAttribute("serverPort", new Integer(
503:                        renderRequest.getServerPort()));
504:
505:                if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
506:                    normalView.include(renderRequest, renderResponse);
507:                } else {
508:                    maximizedView.include(renderRequest, renderResponse);
509:                }
510:            }
511:
512:            public final static class ContainerInfo {
513:                private String name;
514:                private String managerURI;
515:                private String containerURI;
516:                private List connectorTypes;
517:                private List connectors;
518:
519:                public ContainerInfo(String name, String managerURI,
520:                        String containerURI) {
521:                    this .name = name;
522:                    this .managerURI = managerURI;
523:                    this .containerURI = containerURI;
524:                }
525:
526:                public String getName() {
527:                    return name;
528:                }
529:
530:                public List getConnectorTypes() {
531:                    return connectorTypes;
532:                }
533:
534:                public void setConnectorTypes(List connectorTypes) {
535:                    this .connectorTypes = connectorTypes;
536:                }
537:
538:                public List getConnectors() {
539:                    return connectors;
540:                }
541:
542:                public void setConnectors(List connectors) {
543:                    this .connectors = connectors;
544:                }
545:
546:                public String getManagerURI() {
547:                    return managerURI;
548:                }
549:
550:                public String getContainerURI() {
551:                    return containerURI;
552:                }
553:            }
554:
555:            protected void doHelp(RenderRequest renderRequest,
556:                    RenderResponse renderResponse) throws PortletException,
557:                    IOException {
558:                helpView.include(renderRequest, renderResponse);
559:            }
560:
561:            public void init(PortletConfig portletConfig)
562:                    throws PortletException {
563:                super .init(portletConfig);
564:                PortletContext pc = portletConfig.getPortletContext();
565:                normalView = pc
566:                        .getRequestDispatcher("/WEB-INF/view/webmanager/connector/normal.jsp");
567:                maximizedView = pc
568:                        .getRequestDispatcher("/WEB-INF/view/webmanager/connector/maximized.jsp");
569:                helpView = pc
570:                        .getRequestDispatcher("/WEB-INF/view/webmanager/connector/help.jsp");
571:                editConnectorView = pc
572:                        .getRequestDispatcher("/WEB-INF/view/webmanager/connector/editConnector.jsp");
573:            }
574:
575:            public void destroy() {
576:                normalView = null;
577:                maximizedView = null;
578:                helpView = null;
579:                editConnectorView = null;
580:                super .destroy();
581:            }
582:
583:            public static boolean isValid(String s) {
584:                return s != null && !s.equals("");
585:            }
586:
587:            // stash any 'enum' type values for attributes.  right now this is
588:            // hardcoded, need to promote these to the ConnectorAttribute apis
589:            private void populateEnumAttributes(PortletRequest request) {
590:                HashMap<String, String[]> enumValues = new HashMap<String, String[]>();
591:
592:                // provide the two possible values for secure protocol - TLS and SSL
593:                enumValues.put("secureProtocol", new String[] { "TLS", "SSL" }); //jetty
594:                enumValues.put("sslProtocol", new String[] { "TLS", "SSL" }); //tomcat
595:
596:                // keystore and truststore types for tomcat
597:                enumValues.put("keystoreType", KeystoreUtil.keystoreTypes
598:                        .toArray(new String[0]));
599:                enumValues.put("truststoreType", KeystoreUtil.keystoreTypes
600:                        .toArray(new String[0]));
601:
602:                // provide the three possible values for secure algorithm - Default, SunX509, and IbmX509 
603:                enumValues.put("algorithm", new String[] { "Default",
604:                        "SunX509", "IbmX509" });
605:
606:                // provide the possible values for the keystore name
607:                KeystoreManager mgr = PortletManager.getCurrentServer(request)
608:                        .getKeystoreManager();
609:                KeystoreInstance[] stores = mgr.getUnlockedKeyStores();
610:                String[] storeNames = new String[stores.length];
611:                for (int i = 0; i < storeNames.length; i++) {
612:                    storeNames[i] = stores[i].getKeystoreName();
613:                }
614:                enumValues.put("keyStore", storeNames);
615:
616:                // provide the possible values for the trust store name
617:                KeystoreInstance[] trusts = mgr.getUnlockedTrustStores();
618:                String[] trustNames = new String[trusts.length];
619:                for (int i = 0; i < trustNames.length; i++) {
620:                    trustNames[i] = trusts[i].getKeystoreName();
621:                }
622:                enumValues.put("trustStore", trustNames);
623:
624:                request.setAttribute("geronimoConsoleEnumValues", enumValues);
625:            }
626:
627:            // get the special keystore properties from the request and set them on the connector
628:            // TODO: need a more generic way to handle this
629:            private void setKeystoreProperties(PortletRequest request,
630:                    AbstractName connectorName) throws PortletException {
631:                String containerURI = request.getParameter(PARM_CONTAINER_URI);
632:                WebContainer container = PortletManager.getWebContainer(
633:                        request, new AbstractName(URI.create(containerURI)));
634:                String server = getWebServerType(container.getClass());
635:                NetworkConnector connector = PortletManager
636:                        .getNetworkConnector(request, connectorName);
637:
638:                // return if not a secure connector
639:                if (!(connector instanceof  SecureConnector)) {
640:                    return;
641:                }
642:
643:                // right now only jetty supports the KeystoreManager
644:                if (server.equals(WEB_SERVER_JETTY)) {
645:                    String keyStore = request.getParameter("keyStore");
646:
647:                    // get the unlocked keystore object from the keystore managaer
648:                    // gbean and set its keyalias directly on the connector 
649:                    try {
650:                        KeystoreInstance[] keystores = PortletManager
651:                                .getCurrentServer(request).getKeystoreManager()
652:                                .getKeystores();
653:
654:                        String[] keys = null;
655:                        for (int i = 0; i < keystores.length; i++) {
656:                            KeystoreInstance keystore = keystores[i];
657:                            if (keystore.getKeystoreName().equals(keyStore)) {
658:                                keys = keystore.getUnlockedKeys(null);
659:                            }
660:                        }
661:                        if (keys != null && keys.length == 1) {
662:                            setProperty(connector, "keyAlias", keys[0]);
663:                        } else {
664:                            throw new PortletException(
665:                                    "Cannot handle keystores with anything but 1 unlocked private key");
666:                        }
667:                    } catch (KeystoreException e) {
668:                        throw new PortletException(e);
669:                    }
670:                }
671:            }
672:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.