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     */
017    package org.apache.geronimo.console.apache.jk;
018    
019    import java.io.IOException;
020    import javax.portlet.ActionRequest;
021    import javax.portlet.ActionResponse;
022    import javax.portlet.PortletException;
023    import javax.portlet.RenderRequest;
024    import javax.portlet.RenderResponse;
025    import org.apache.geronimo.console.MultiPageModel;
026    import org.apache.geronimo.console.util.PortletManager;
027    import org.apache.geronimo.management.geronimo.NetworkConnector;
028    import org.apache.geronimo.management.geronimo.WebManager;
029    
030    /**
031     * Handler for the screen where you select the webapps to expose through Apache
032     *
033     * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
034     */
035    public class ResultsHandler extends BaseApacheHandler {
036        public ResultsHandler() {
037            super(RESULTS_MODE, "/WEB-INF/view/apache/jk/results.jsp");
038        }
039    
040        public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
041            //todo: Add AJP Connector
042            return getMode();
043        }
044    
045        public void renderView(RenderRequest request, RenderResponse response, MultiPageModel amodel) throws PortletException, IOException {
046            ApacheModel model = (ApacheModel) amodel;
047            String port = "unknown";
048            if(model.getAddAjpPort() != null) {
049                port = model.getAddAjpPort().toString();
050            } else {
051                WebManager[] managers = PortletManager.getWebManagers(request);
052                // See if any AJP listeners are defined
053                for (int i = 0; i < managers.length; i++) {
054                    WebManager manager = managers[i];
055                    NetworkConnector[] connectors = manager.getConnectors(WebManager.PROTOCOL_AJP);
056                    if(connectors.length > 0) {
057                        port = Integer.toString(connectors[0].getPort());
058                        break;
059                    }
060                }
061            }
062            request.setAttribute("ajpPort", port);
063        }
064    
065        public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
066            return getMode()+BEFORE_ACTION;
067        }
068    }