All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.petals.binding.soap.listener.incoming.servlet.WelcomeServlet Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2008-2012 EBM WebSourcing, 2012-2023 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see http://www.gnu.org/licenses/
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.binding.soap.listener.incoming.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Server;
import org.ow2.petals.binding.soap.SoapConstants;
import org.ow2.petals.binding.soap.listener.incoming.SoapServerConfig;
import org.ow2.petals.binding.soap.listener.incoming.jetty.IncomingProbes;
import org.ow2.petals.binding.soap.listener.incoming.jetty.ServerStats;
import org.ow2.petals.probes.api.exceptions.ProbeNotStartedException;
import org.ow2.petals.probes.api.probes.CounterProbe;
import org.ow2.petals.probes.api.probes.GaugeProbe;

/**
 * A servlet which displays basic information. 
 * 

* It replaces the default 404 pages. *

* * @author Christophe HAMERLING - EBM WebSourcing */ public class WelcomeServlet extends HttpServlet { private static final long serialVersionUID = 1614281322239677571L; private transient final SoapServerConfig config; private transient final ServerStats stats; private static final String HTML_TITLE = "Welcome SOAP Binding Component"; /** * The probe counting unknown URLs received by the Jetty server. */ private transient final CounterProbe probeInformationServlet; /** * The probe counting active threads in the thread pool of the HTTP server. */ private transient final GaugeProbe probeHttpServerThreadPoolActiveThreads; /** * The probe counting idle threads in the thread pool of the HTTP server. */ private transient final GaugeProbe probeHttpServerThreadPoolIdleThreads; /** * The probe counting requests in the queue of the thread pool of the HTTP * server. */ private transient final GaugeProbe probeHttpServerThreadPoolQueuedRequests; /** * The component logger */ private transient final Logger logger; /** * * @param config * @param stats * @param probes * The technical monitoring probes * @param logger * The component logger */ public WelcomeServlet(final SoapServerConfig config, final ServerStats stats, final IncomingProbes probes, final Logger logger) { this.config = config; this.stats = stats; this.logger = logger; this.probeHttpServerThreadPoolActiveThreads = probes.probeHttpServerThreadPoolActiveThreads; this.probeHttpServerThreadPoolIdleThreads = probes.probeHttpServerThreadPoolIdleThreads; this.probeHttpServerThreadPoolQueuedRequests = probes.probeHttpServerThreadPoolQueuedRequests; this.probeInformationServlet = probes.probeInformationServlet; } /** * */ @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { this.probeInformationServlet.inc(); this.probeHttpServerThreadPoolActiveThreads.pick(); this.probeHttpServerThreadPoolIdleThreads.pick(); this.probeHttpServerThreadPoolQueuedRequests.pick(); } catch (final ProbeNotStartedException e) { this.logger .warning("HTTP probes are not started. Values of probes could be incorrect."); } // Redirection (forward) requested ? Proceed... String redirect = this.config.getRedirect(req.getRequestURI()); if(redirect != null) { // Example: redirect="/petals/services/myWebService" if (!redirect.startsWith("/")) { redirect = "/" + redirect; } final int pos = redirect.substring(1).indexOf("/"); // The 2nd '/' (in the example, before "services") final String ctxname = redirect.substring(0, pos + 1); // In the example: "/petals" final ServletContext otherContext = getServletContext().getContext(ctxname); // In the example: forward to "/services/myWebService" otherContext.getRequestDispatcher(redirect.substring(pos+1)).forward(req, resp); return; // forward done ! } // No (forward) redirection: display SOAP BC information. final ServletOutputStream out = resp.getOutputStream(); out.write(HTML_TITLE.getBytes()); out.write("

Petals BC SOAP

".getBytes()); out.write("

Component Configuration

".getBytes()); out.write("
    ".getBytes()); out.write(("
  • " + this.config.getHostToDisplay() + "
  • ").getBytes()); out.write(("
  • HTTP Port : " + this.config.getHttpPort() + "
  • ").getBytes()); out.write(("
  • HTTP Acceptors : " + this.config.getHttpAcceptors() + "
  • ").getBytes()); out.write(("
  • HTTP Backlog size : " + this.config.getHttpBacklogSize() + "
  • ").getBytes()); if (this.config.isHttpsEnabled()) { out.write(("
  • HTTPS Port : " + this.config.getHttpsPort() + "
  • ").getBytes()); out.write(("
  • HTTPS Acceptors : " + this.config.getHttpsAcceptors() + "
  • ").getBytes()); out.write(("
  • HTTPS Backlog size : " + this.config.getHttpsBacklogSize() + "
  • ").getBytes()); } out.write(("
  • Jetty Max pool size : " + this.config.getJettyThreadMaxPoolSize() + "
  • ").getBytes()); out.write(("
  • Jetty Min pool size : " + this.config.getJettyThreadMinPoolSize() + "
  • ").getBytes()); out.write(("
  • Services Context : " + this.config.getServicesContext() + "
  • ").getBytes()); out.write("
".getBytes()); out.write("

Web Services information

".getBytes()); out.write("
    ".getBytes()); out.write("
  • Services List : ".getBytes()); final String path = "/" + this.config.getServicesContext() + "/" + this.config.getServicesMapping() + "/" + SoapConstants.Component.MAPPING_NAME; final String link = "" + path + ""; out.write(link.getBytes()); out.write("
  • ".getBytes()); out.write("
".getBytes()); out.write("

Server Stats

".getBytes()); out.write("
    ".getBytes()); out.write(("
  • Start time : " + new SimpleDateFormat().format(new Date(stats.getStartTime())) + "
  • ").getBytes()); out.write(("
  • Jetty Server version : " + Server.getVersion() + "
  • ").getBytes()); out.write(("
  • Incoming WS GET requests : " + stats.getGetRequests() + "
  • ").getBytes()); out.write(("
  • Incoming WS POST requests : " + stats.getPostRequests() + "
  • ").getBytes()); out.write("
".getBytes()); out.write("".getBytes()); out.flush(); out.close(); } @Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy