org.apache.xmlrpc.webserver.WebServer类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中org.apache.xmlrpc.webserver.WebServer类的一些代码示例,展示了WebServer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebServer类的具体详情如下:
包路径:org.apache.xmlrpc.webserver.WebServer
类名称:WebServer

WebServer介绍

[英]The WebServer is a minimal HTTP server, that might be used as an embedded web server.

Use of the WebServer has grown very popular amongst users of Apache XML-RPC. Why this is the case, can hardly be explained, because the WebServer is at best a workaround, compared to full blown servlet engines like Tomcat or Jetty. For example, under heavy load it will almost definitely be slower than a real servlet engine, because it does neither support proper keepalive (multiple requests per physical connection) nor chunked mode (in other words, it cannot stream requests).

If you still insist in using the WebServer, it is recommended to use its subclass, the ServletWebServer instead, which offers a minimal subset of the servlet API. In other words, you keep yourself the option to migrate to a real servlet engine later.

Use of the WebServer goes roughly like this: First of all, create a property file (for example "MyHandlers.properties") and add it to your jar file. The property keys are handler names and the property values are the handler classes. Once that is done, create an instance of WebServer:

final int port = 8088; 
final String propertyFile = "MyHandler.properties"; 
PropertyHandlerMapping mapping = new PropertyHandlerMapping(); 
ClassLoader cl = Thread.currentThread().getContextClassLoader(); 
mapping.load(cl, propertyFile); 
WebServer webServer = new WebServer(port); 
XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl(); 
XmlRpcServer server = webServer.getXmlRpcServer(); 
server.setConfig(config); 
server.setHandlerMapping(mapping); 
webServer.start();

[中]WebServer是一个最小的HTTP服务器,可以用作嵌入式web服务器。
Web服务器的使用在Apache XML-RPC用户中变得非常流行。很难解释为什么会出现这种情况,因为与Tomcat或Jetty等成熟的servlet引擎相比,Web服务器充其量只是一种变通方法。例如,在重载情况下,它几乎肯定会比真正的servlet引擎慢,因为它既不支持正确的keepalive(每个物理连接有多个请求),也不支持分块模式(换句话说,它不能流式处理请求)。
如果仍然坚持使用WebServer,建议使用它的子类ServletWebServer,它提供了ServletAPI的最小子集。换句话说,您可以选择以后迁移到真正的servlet引擎。
Web服务器的使用大致如下:首先,创建一个属性文件(例如“MyHandlers.properties”),并将其添加到jar文件中。属性键是处理程序名称,属性值是处理程序类。完成后,创建一个WebServer实例:

final int port = 8088; 
final String propertyFile = "MyHandler.properties"; 
PropertyHandlerMapping mapping = new PropertyHandlerMapping(); 
ClassLoader cl = Thread.currentThread().getContextClassLoader(); 
mapping.load(cl, propertyFile); 
WebServer webServer = new WebServer(port); 
XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl(); 
XmlRpcServer server = webServer.getXmlRpcServer(); 
server.setConfig(config); 
server.setHandlerMapping(mapping); 
webServer.start();

代码示例

代码示例来源:origin: org.nuiton.topia/topia-soa

/**
 * Constructeur.
 * 
 * Initialise le serveur.
 * 
 * @param port port de lancement du serveur
 */
public XMLRPCServer(int port) {
  webServer = new WebServer(port);
  XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
  xmlRpcServer.setHandlerMapping(this);
}

代码示例来源:origin: org.nuiton.topia/topia-soa

/**
 * lance le serveur
 */
public void launch() {
  if (!alreadyLaunched) {
    try {
      webServer.start();
      logger.info("XML-RPC server running...");
    } catch (IOException e) {
      logger.debug("I/O erreur while launching xml-rpc web serveur",
          e);
    }
    alreadyLaunched = true;
  }
}

代码示例来源:origin: org.apache.xmlrpc/xmlrpc-server

/**
 * Spawns a new thread which binds this server to the port it's
 * configured to accept connections on.
 *
 * @see #run()
 * @throws IOException Binding the server socket failed.
 */
public void start() throws IOException {
  setupServerSocket(50);
  
  // The listener reference is released upon shutdown().
  if (listener == null) {
    listener = new Thread(this, "XML-RPC Weblistener");
    // Not marked as daemon thread since run directly via main().
    listener.start();
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/DatalessClassification

public static void server(String indexDirectory, int port)
    throws IOException, XmlRpcException {
  log.info(
      "Starting descartes server at port {}, with index directory {}",
      Integer.valueOf(port), indexDirectory);
  DescartesServer.indexDirectory = indexDirectory;
  WebServer webServer = new WebServer(port);
  XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
  PropertyHandlerMapping phm = new PropertyHandlerMapping();
  phm.addHandler("DescartesServer", DescartesServer.class);
  xmlRpcServer.setHandlerMapping(phm);
  XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer
      .getConfig();
  serverConfig.setEnabledForExtensions(true);
  serverConfig.setContentLengthOptional(false);
  webServer.start();
  log.info("Descartes is ready!");
}

代码示例来源:origin: rosjava/rosjava_core

pool = newThreadPool();
try {
  while (listener != null) {
        socket.setTcpNoDelay(true);
      } catch (SocketException socketOptEx) {
        log(socketOptEx);
        if (allowConnection(socket)) {
          final ThreadPool.Task task = newTask(this, server, socket);
          if (pool.startTask(task)) {
            socket = null;
          } else {
            log("Maximum load of " + pool.getMaxThreads()
              + " exceeded, rejecting client");
      log(t);
      serverSocket.close();
    } catch (IOException e) {
      log(e);

代码示例来源:origin: rosjava/rosjava_core

org.apache.xmlrpc.server.XmlRpcServer xmlRpcServer = server.getXmlRpcServer();
PropertyHandlerMapping phm = new PropertyHandlerMapping();
phm.setRequestProcessorFactoryFactory(new NodeRequestProcessorFactoryFactory<T>(instance));
serverConfig.setContentLengthOptional(false);
try {
 server.start();
} catch (IOException e) {
 throw new RosRuntimeException(e);

代码示例来源:origin: rosjava/rosjava_core

public XmlRpcServer(BindAddress bindAddress, AdvertiseAddress advertiseAddress) {
 InetSocketAddress address = bindAddress.toInetSocketAddress();
 server = new WebServer(address.getPort(), address.getAddress());
 this.advertiseAddress = advertiseAddress;
 this.advertiseAddress.setPortCallable(new Callable<Integer>() {
  @Override
  public Integer call() throws Exception {
   return server.getPort();
  }
 });
 startLatch = new CountDownLatch(1);
}

代码示例来源:origin: rosjava/rosjava_core

webServer.log(e.getClass().getName() + ": " + e.getMessage());
try {
  writeErrorHeader(e.requestData, e, -1);
  webServer.log(t);

代码示例来源:origin: org.apache.xmlrpc/xmlrpc-server

serverSocket = createServerSocket(port, backlog, address);

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-entity-similarity

public static void main(String[] args) {
    if (args.length != 1)
      System.err.println("Usage: ECServer port");
    int port = (new Integer(args[0])).intValue();
    
    try {
      System.out.println("Attempting to start XML-RPC Server...");
      WebServer server = new WebServer(port);
      XmlRpcServer xmlRpcServer = server.getXmlRpcServer();
      PropertyHandlerMapping phm = new PropertyHandlerMapping();
      phm.addHandler("EntityComparison", EntityComparison.class);
      xmlRpcServer.setHandlerMapping(phm);
      XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl)xmlRpcServer.getConfig();
      serverConfig.setEnabledForExtensions(true);
      serverConfig.setContentLengthOptional(false);
      server.start();
      System.out.println("Started successfully.");
      System.out.println("Accepting requests. (Halt program to stop.)");
    } 
    catch (Exception exception) {
      System.err.println("ECServer: " + exception);
    }
  }
}

代码示例来源:origin: org.apache.xmlrpc/xmlrpc-server

pool = newThreadPool();
try {
  while (listener != null) {
        socket.setTcpNoDelay(true);
      } catch (SocketException socketOptEx) {
        log(socketOptEx);
        if (allowConnection(socket)) {
          final ThreadPool.Task task = newTask(this, server, socket);
          if (pool.startTask(task)) {
            socket = null;
          } else {
            log("Maximum load of " + pool.getMaxThreads()
              + " exceeded, rejecting client");
      log(t);
      serverSocket.close();
    } catch (IOException e) {
      log(e);

代码示例来源:origin: org.apache.xmlrpc/xmlrpc-server

webServer.log(e.getClass().getName() + ": " + e.getMessage());
try {
  writeErrorHeader(e.requestData, e, -1);
  webServer.log(t);

代码示例来源:origin: org.sonatype.sisu/sisu-xmlrpc-server

serverSocket = createServerSocket(port, backlog, address);

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-wnsim

WebServer server = new WebServer( port );
XmlRpcServer xmlRpcServer = server.getXmlRpcServer();
serverConfig.setContentLengthOptional(false);
server.start();

代码示例来源:origin: org.sonatype.sisu/sisu-xmlrpc-server

pool = newThreadPool();
try {
  while (listener != null) {
        socket.setTcpNoDelay(true);
      } catch (SocketException socketOptEx) {
        log(socketOptEx);
        if (allowConnection(socket)) {
          final ThreadPool.Task task = newTask(this, server, socket);
          if (pool.startTask(task)) {
            socket = null;
          } else {
            log("Maximum load of " + pool.getMaxThreads()
              + " exceeded, rejecting client");
      log(t);
      serverSocket.close();
    } catch (IOException e) {
      log(e);

代码示例来源:origin: org.sonatype.sisu/sisu-xmlrpc-server

/**
 * Spawns a new thread which binds this server to the port it's
 * configured to accept connections on.
 *
 * @see #run()
 * @throws IOException Binding the server socket failed.
 */
public void start() throws IOException {
  setupServerSocket(50);
  
  // The listener reference is released upon shutdown().
  if (listener == null) {
    listener = new Thread(this, "XML-RPC Weblistener");
    // Not marked as daemon thread since run directly via main().
    listener.start();
  }
}

代码示例来源:origin: org.sonatype.sisu/sisu-xmlrpc-server

webServer.log(e.getClass().getName() + ": " + e.getMessage());
try {
  writeErrorHeader(e.requestData, e, -1);
  webServer.log(t);

代码示例来源:origin: rosjava/rosjava_core

serverSocket = createServerSocket(port, backlog, address);

代码示例来源:origin: rosjava/rosjava_core

/**
 * Spawns a new thread which binds this server to the port it's
 * configured to accept connections on.
 *
 * @see #run()
 * @throws IOException Binding the server socket failed.
 */
public void start() throws IOException {
  setupServerSocket(50);
  
  // The listener reference is released upon shutdown().
  if (listener == null) {
    listener = new Thread(this, "XML-RPC Weblistener");
    // Not marked as daemon thread since run directly via main().
    listener.start();
  }
}

相关文章