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

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

The newest version!
/**
 * Copyright (c) 2007-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 static org.ow2.petals.binding.soap.SoapConstants.Axis2.OUTGOING_SERVICE_CLIENT_PREFIX;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisService;
import org.ow2.petals.binding.soap.listener.incoming.SoapServerConfig;
import org.ow2.petals.binding.soap.listener.incoming.jetty.IncomingProbes;
import org.ow2.petals.probes.api.exceptions.ProbeNotStartedException;
import org.ow2.petals.probes.api.probes.CounterProbe;
import org.ow2.petals.probes.api.probes.GaugeProbe;

/**
 * Servlet used to display the list of services. 
 * 

* It replaces the Axis2 one. *

* * @author Christophe Hamerling - EBM WebSourcing */ public class ListServicesServlet extends HttpServlet { private static final long serialVersionUID = -4951673084170985493L; /** * The HTML title string */ private static final String HTML_TOP = "petals-bc-soap : Services List

Petals BC SOAP

"; private static final String HTML_BOTTOM = ""; /** * The axis2 configuration context used to get services list */ private transient final ConfigurationContext configContext; /** * The SOAP server configuration */ private transient final SoapServerConfig soapServerConfig; /** * 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; /** * Creates a new instance of ListServicesServlet * * @param configurationContext * @param soapConfig * @param probes * Technical monitoring probes * @param logger * The component logger */ public ListServicesServlet(final ConfigurationContext configurationContext, final SoapServerConfig soapConfig, final IncomingProbes probes, final Logger logger) { this.configContext = configurationContext; this.soapServerConfig = soapConfig; this.logger = logger; this.probeHttpServerThreadPoolActiveThreads = probes.probeHttpServerThreadPoolActiveThreads; this.probeHttpServerThreadPoolIdleThreads = probes.probeHttpServerThreadPoolIdleThreads; this.probeHttpServerThreadPoolQueuedRequests = probes.probeHttpServerThreadPoolQueuedRequests; this.probeInformationServlet = probes.probeInformationServlet; } /** * The list has not been activated in component * * @param out * @throws IOException */ private void listNotAvailable(final ServletOutputStream out) throws IOException { out.write("

The list of services is not available

".getBytes()); out.write("It must be activated in the SOAP component descriptor...".getBytes()); out.write("".getBytes()); } /** * Print the list of services with links to their WSDL description * * @param out * @throws IOException */ private void printServicesList(final ServletOutputStream out, String transport) throws IOException { final Map services = this.configContext.getAxisConfiguration().getServices(); out.write("

Available services

".getBytes()); final Set serviceNames = new TreeSet<>(); for (final AxisService service : services.values()) { if (!service.getName().startsWith(OUTGOING_SERVICE_CLIENT_PREFIX)) { final List exposedTransports = service.getExposedTransports(); if (exposedTransports.contains(transport)) { serviceNames.add(service.getName()); } } } if (serviceNames.isEmpty()) { out.write("No service".getBytes()); } else { for (final String serviceName : serviceNames) { out.write("
  • ".getBytes()); out.write(serviceName.getBytes()); out.write("
  • ".getBytes()); } } } @Override public void service(final ServletRequest request, final ServletResponse response) 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."); } final ServletOutputStream out = response.getOutputStream(); out.write(HTML_TOP.getBytes()); if (this.soapServerConfig.isProvidesList()) { this.printServicesList(out, request.getScheme()); } else { this.listNotAvailable(out); } out.write(("

    - Index -

    ").getBytes()); out.write(HTML_BOTTOM.getBytes()); out.flush(); out.close(); } }




    © 2015 - 2024 Weber Informatics LLC | Privacy Policy