站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 4.0.1 sp1 server API Documentation 英文版文档

WebServer (JBoss Server API) - JBoss 4.0.1 sp1 server API Documentation 英文版文档


org.jboss.web
Class WebServer

java.lang.Object
  extended byorg.jboss.web.WebServer
All Implemented Interfaces:
Runnable

public class WebServer
extends Object
implements Runnable

A mini webserver that should be embedded in another application. It can server any file that is available from classloaders that are registered with it, including class-files. Its primary purpose is to simplify dynamic class-loading in RMI. Create an instance of it, register a classloader with your classes, start it, and you'll be able to let RMI-clients dynamically download classes from it. It is configured by calling any methods programmatically prior to startup.

Version:
$Revision: 1.26.4.3 $ Revisions: 20010806 scott.stark: Allow binding of listening port to a specific IP address 20010619 scott.stark: Use log4j JBossCategory to enable trace level msgs 20010618 scott.stark: Fixed extraction of mime-type from file extension in getMimeType 20010627 scott.stark: Restore ability to download from the server classpath if no loader key is found amd downloadServerClasses is true
Author:
Marc Fleury, Scott Stark.
See Also:
WebClassLoader

Constructor Summary
WebServer()
           
 
Method Summary
 URL addClassLoader(ClassLoader cl)
          Add a class loader to the web server map and return the URL that should be used as the annotated codebase for classes that are to be available via RMI dynamic classloading.
 void addMimeType(String extension, String type)
          Augment the type suffix to mime type mappings
 int getBacklog()
          Get the server sockets listen queue depth
 String getBindAddress()
           
 String getBindHostname()
           
protected  byte[] getBytes(URL url)
          Read the local class/resource contents into a byte array.
protected  String getClassLoaderKey(ClassLoader cl)
          Create the string key used as the key into the loaderMap.
 boolean getDownloadServerClasses()
           
protected  String getMimeType(String path)
          Lookup the mime type for the suffix of the path argument.
protected  String getPath(BufferedReader in)
           
 int getPort()
          Get the http listening port
 org.jboss.util.threadpool.BasicThreadPoolMBean getThreadPool()
           
protected  void listen()
           
 void removeClassLoader(ClassLoader cl)
          Remove a class loader previously added via addClassLoader
 void run()
          Listen threads entry point.
 void setBacklog(int backlog)
          Set the server sockets listen queue depth
 void setBindAddress(String host)
           
 void setDownloadServerClasses(boolean flag)
           
 void setPort(int p)
          Set the http listening port
 void setThreadPool(org.jboss.util.threadpool.BasicThreadPoolMBean threadPool)
           
 void start()
          Start the web server on port and begin listening for requests.
 void stop()
          Close the web server listening socket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebServer

public WebServer()
Method Detail

setPort

public void setPort(int p)
Set the http listening port


getPort

public int getPort()
Get the http listening port

Returns:
the http listening port

getBindAddress

public String getBindAddress()

getBindHostname

public String getBindHostname()

setBindAddress

public void setBindAddress(String host)

getBacklog

public int getBacklog()
Get the server sockets listen queue depth

Returns:
the listen queue depth

setBacklog

public void setBacklog(int backlog)
Set the server sockets listen queue depth


getDownloadServerClasses

public boolean getDownloadServerClasses()

setDownloadServerClasses

public void setDownloadServerClasses(boolean flag)

getThreadPool

public org.jboss.util.threadpool.BasicThreadPoolMBean getThreadPool()

setThreadPool

public void setThreadPool(org.jboss.util.threadpool.BasicThreadPoolMBean threadPool)

addMimeType

public void addMimeType(String extension,
                        String type)
Augment the type suffix to mime type mappings

Parameters:
extension - - the type extension without a period(class, txt)
type - - the mime type string

start

public void start()
           throws IOException
Start the web server on port and begin listening for requests.

Throws:
IOException

stop

public void stop()
Close the web server listening socket


addClassLoader

public URL addClassLoader(ClassLoader cl)
Add a class loader to the web server map and return the URL that should be used as the annotated codebase for classes that are to be available via RMI dynamic classloading. The codebase URL is formed by taking the java.rmi.server.codebase system property and adding a subpath unique for the class loader instance.

Parameters:
cl - - the ClassLoader instance to begin serving download requests for
Returns:
the annotated codebase to use if java.rmi.server.codebase is set, null otherwise.
See Also:
getClassLoaderKey(ClassLoader)

removeClassLoader

public void removeClassLoader(ClassLoader cl)
Remove a class loader previously added via addClassLoader

Parameters:
cl - - the ClassLoader previously added via addClassLoader

run

public void run()
Listen threads entry point. Here we accept a client connection and located requested classes/resources using the class loader specified in the http request.

Specified by:
run in interface Runnable

getClassLoaderKey

protected String getClassLoaderKey(ClassLoader cl)
Create the string key used as the key into the loaderMap.

Returns:
The class loader instance key.

listen

protected void listen()

getPath

protected String getPath(BufferedReader in)
                  throws IOException
Returns:
the path portion of the HTTP request header.
Throws:
IOException

getBytes

protected byte[] getBytes(URL url)
                   throws IOException
Read the local class/resource contents into a byte array.

Throws:
IOException

getMimeType

protected String getMimeType(String path)
Lookup the mime type for the suffix of the path argument.

Returns:
the mime-type string for path.


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.