本文整理汇总了Java中org.apache.catalina.Connector类的典型用法代码示例。如果您正苦于以下问题:Java Connector类的具体用法?Java Connector怎么用?Java Connector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connector类属于org.apache.catalina包,在下文中一共展示了Connector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Create, configure, and return a new TCP/IP socket connector
* based on the specified properties.
*
* @param address InetAddress to listen to, or <code>null</code>
* to listen on all address on this server
* @param port Port number to listen to
* @param secure Should this port be SSL-enabled?
*/
public Connector createConnector(InetAddress address, int port,
boolean secure) {
if (debug >= 1)
logger.log("Creating connector for address='" +
((address == null) ? "ALL" : address.getHostAddress()) +
"' port='" + port + "' secure='" + secure + "'");
String protocol = "http";
if (secure) {
protocol = "https";
}
return createConnector(address, port, protocol);
}
示例2: createMBeans
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Create the MBeans for the specified Service and its nested components.
*
* @param service Service for which to create MBeans
*
* @exception Exception if an exception is thrown during MBean creation
*/
protected void createMBeans(Service service) throws Exception {
// Create the MBean for the Service itself
if (debug >= 2)
log("Creating MBean for Service " + service);
MBeanUtils.createMBean(service);
if (service instanceof StandardService) {
((StandardService) service).addPropertyChangeListener(this);
}
// Create the MBeans for the corresponding Connectors
Connector connectors[] = service.findConnectors();
for (int j = 0; j < connectors.length; j++) {
createMBeans(connectors[j]);
}
// Create the MBean for the associated Engine and friends
Engine engine = (Engine) service.getContainer();
if (engine != null) {
createMBeans(engine);
}
}
示例3: destroyMBeans
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Deregister the MBeans for the specified Service and its nested
* components.
*
* @param service Service for which to destroy MBeans
*
* @exception Exception if an exception is thrown during MBean destruction
*/
protected void destroyMBeans(Service service) throws Exception {
// Deregister the MBeans for the associated Engine
Engine engine = (Engine) service.getContainer();
if (engine != null) {
destroyMBeans(engine);
}
// Deregister the MBeans for the corresponding Connectors
Connector connectors[] = service.findConnectors();
for (int j = 0; j < connectors.length; j++) {
destroyMBeans(connectors[j], service);
}
// Deregister the MBean for the Service itself
if (debug >= 2) {
log("Destroying MBean for Service " + service);
}
MBeanUtils.destroyMBean(service);
if (service instanceof StandardService) {
((StandardService) service).removePropertyChangeListener(this);
}
}
示例4: createMBean
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Create, register, and return an MBean for this
* <code>Connector</code> object.
*
* @param connector The Connector to be managed
*
* @exception Exception if an MBean cannot be created or registered
*/
public static ModelMBean createMBean(Connector connector)
throws Exception {
String mname = createManagedName(connector);
ManagedBean managed = registry.findManagedBean(mname);
if (managed == null) {
Exception e = new Exception("ManagedBean is not found with "+mname);
throw new MBeanException(e);
}
String domain = managed.getDomain();
if (domain == null)
domain = mserver.getDefaultDomain();
ModelMBean mbean = managed.createMBean(connector);
ObjectName oname = createObjectName(domain, connector);
mserver.registerMBean(mbean, oname);
return (mbean);
}
示例5: destroyMBean
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Deregister the MBean for this
* <code>Connector</code> object.
*
* @param connector The Connector to be managed
*
* @exception Exception if an MBean cannot be deregistered
*/
public static void destroyMBean(Connector connector, Service service)
throws Exception {
connector.setService(service);
String mname = createManagedName(connector);
ManagedBean managed = registry.findManagedBean(mname);
if (managed == null) {
return;
}
String domain = managed.getDomain();
if (domain == null)
domain = mserver.getDefaultDomain();
ObjectName oname = createObjectName(domain, connector);
connector.setService(null);
mserver.unregisterMBean(oname);
}
示例6: addConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Add a new Connector to the set of defined Connectors. The newly
* added Connector will be associated with the most recently added Engine.
*
* @param connector The connector to be added
*
* @exception IllegalStateException if no engines have been added yet
*/
public synchronized void addConnector(Connector connector) {
if (debug >= 1) {
logger.log("Adding connector (" + connector.getInfo() + ")");
}
// Make sure we have a Container to send requests to
if (engines.length < 1)
throw new IllegalStateException
(sm.getString("embedded.noEngines"));
// Configure this Connector as needed
connector.setContainer(engines[engines.length - 1]);
// Add this Connector to our set of defined Connectors
Connector results[] = new Connector[connectors.length + 1];
for (int i = 0; i < connectors.length; i++)
results[i] = connectors[i];
results[connectors.length] = connector;
connectors = results;
// Start this Connector if necessary
if (started) {
try {
connector.initialize();
if (connector instanceof Lifecycle) {
((Lifecycle) connector).start();
}
} catch (LifecycleException e) {
logger.log("Connector.start", e);
}
}
}
示例7: processServicePropertyChange
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Process a property change event on a Service.
*
* @param service The service on which this event occurred
* @param propertyName The name of the property that changed
* @param oldValue The previous value (may be <code>null</code>)
* @param newValue The new value (may be <code>null</code>)
*
* @exception Exception if an exception is thrown
*/
protected void processServicePropertyChange(Service service,
String propertyName,
Object oldValue,
Object newValue)
throws Exception {
if (debug >= 6) {
log("propertyChange[service=" + service +
",propertyName=" + propertyName +
",oldValue=" + oldValue +
",newValue=" + newValue + "]");
}
if ("connector".equals(propertyName)) {
if (oldValue != null) {
destroyMBeans((Connector) oldValue, service);
}
if (newValue != null) {
createMBeans((Connector) newValue);
}
} else if ("container".equals(propertyName)) {
if (oldValue != null) {
destroyMBeans((Engine) oldValue);
}
if (newValue != null) {
createMBeans((Engine) newValue);
}
}
}
示例8: removeConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Remove an existing Connector.
*
* @param name MBean Name of the comonent to remove
*
* @param serviceName Service name of the connector to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeConnector(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
Server server = ServerFactory.getServer();
String serviceName = oname.getKeyProperty("service");
Service service = server.findService(serviceName);
String port = oname.getKeyProperty("port");
String address = oname.getKeyProperty("address");
Connector conns[] = (Connector[]) service.findConnectors();
for (int i = 0; i < conns.length; i++) {
Class cls = conns[i].getClass();
Method getAddrMeth = cls.getMethod("getAddress", null);
Object addrObj = getAddrMeth.invoke(conns[i], null);
String connAddress = null;
if (addrObj != null) {
connAddress = addrObj.toString();
}
Method getPortMeth = cls.getMethod("getPort", null);
Object portObj = getPortMeth.invoke(conns[i], null);
String connPort = new String();
if (portObj != null) {
connPort = portObj.toString();
}
if (((address.equals("null")) && (connAddress==null)) && port.equals(connPort)) {
service.removeConnector(conns[i]);
break;
} else if (address.equals(connAddress) && port.equals(connPort)) {
// Remove this component from its parent component
service.removeConnector(conns[i]);
break;
}
}
}
示例9: removeConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Remove the specified Connector from the set associated from this
* Service. The removed Connector will also be disassociated from our
* Container.
*
* @param connector The Connector to be removed
*/
public void removeConnector(Connector connector) {
synchronized (connectors) {
int j = -1;
for (int i = 0; i < connectors.length; i++) {
if (connector == connectors[i]) {
j = i;
break;
}
}
if (j < 0)
return;
if (started && (connectors[j] instanceof Lifecycle)) {
try {
((Lifecycle) connectors[j]).stop();
} catch (LifecycleException e) {
;
}
}
connectors[j].setContainer(null);
connector.setService(null);
int k = 0;
Connector results[] = new Connector[connectors.length - 1];
for (int i = 0; i < connectors.length; i++) {
if (i != j)
results[k++] = connectors[i];
}
connectors = results;
// Report this property change to interested listeners
support.firePropertyChange("connector", connector, null);
}
}
示例10: main
import org.apache.catalina.Connector; //导入依赖的package包/类
public static void main(String[] args) {
Connector connector = new HttpConnector();
Wrapper wrapper1 = new SimpleWrapper();
wrapper1.setName("Primitive");
wrapper1.setServletClass("PrimitiveServlet");
Wrapper wrapper2 = new SimpleWrapper();
wrapper2.setName("Modern");
wrapper2.setServletClass("ModernServlet");
Context context = new SimpleContext();
context.addChild(wrapper1);
context.addChild(wrapper2);
Mapper mapper = new SimpleContextMapper();
mapper.setProtocol("http");
LifecycleListener listener = new SimpleContextLifecycleListener();
((Lifecycle) context).addLifecycleListener(listener);
context.addMapper(mapper);
Loader loader = new SimpleLoader();
context.setLoader(loader);
// context.addServletMapping(pattern, name);
context.addServletMapping("/Primitive", "Primitive");
context.addServletMapping("/Modern", "Modern");
connector.setContainer(context);
try {
connector.initialize();
((Lifecycle) connector).start();
((Lifecycle) context).start();
// make the application wait until we press a key.
System.in.read();
((Lifecycle) context).stop();
}
catch (Exception e) {
e.printStackTrace();
}
}
示例11: main
import org.apache.catalina.Connector; //导入依赖的package包/类
public static void main(String[] args) {
System.setProperty("catalina.base", System.getProperty("user.dir"));
Connector connector = new HttpConnector();
Context context = new StandardContext();
// StandardContext's start method adds a default mapper
context.setPath("/app1");
context.setDocBase("app1");
LifecycleListener listener = new ContextConfig();
((Lifecycle) context).addLifecycleListener(listener);
Host host = new StandardHost();
host.addChild(context);
host.setName("localhost");
host.setAppBase("webapps");
Loader loader = new WebappLoader();
context.setLoader(loader);
connector.setContainer(host);
try {
connector.initialize();
((Lifecycle) connector).start();
((Lifecycle) host).start();
Container[] c = context.findChildren();
int length = c.length;
for (int i=0; i<length; i++) {
Container child = c[i];
System.out.println(child.getName());
}
// make the application wait until we press a key.
System.in.read();
((Lifecycle) host).stop();
}
catch (Exception e) {
e.printStackTrace();
}
}
示例12: removeConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Remove the specified Connector from the set of defined Connectors.
*
* @param connector The Connector to be removed
*/
public synchronized void removeConnector(Connector connector) {
if (debug >= 1) {
logger.log("Removing connector (" + connector.getInfo() + ")");
}
// Is the specified Connector actually defined?
int j = -1;
for (int i = 0; i < connectors.length; i++) {
if (connector == connectors[i]) {
j = i;
break;
}
}
if (j < 0)
return;
// Stop this Connector if necessary
if (connector instanceof Lifecycle) {
if (debug >= 1)
logger.log(" Stopping this Connector");
try {
((Lifecycle) connector).stop();
} catch (LifecycleException e) {
logger.log("Connector.stop", e);
}
}
// Remove this Connector from our set of defined Connectors
if (debug >= 1)
logger.log(" Removing this Connector");
int k = 0;
Connector results[] = new Connector[connectors.length - 1];
for (int i = 0; i < connectors.length; i++) {
if (i != j)
results[k++] = connectors[i];
}
connectors = results;
}
示例13: createAjpConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Create a new AjpConnector
*
* @param parent MBean Name of the associated parent component
* @param address The IP address on which to bind
* @param port TCP port number to listen on
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createAjpConnector(String parent, String address, int port)
throws Exception {
Object retobj = null;
try {
// Create a new CoyoteConnector instance for AJP
// use reflection to avoid j-t-c compile-time circular dependencies
Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
Constructor ct = cls.getConstructor(null);
retobj = ct.newInstance(null);
Class partypes1 [] = new Class[1];
// Set address
String str = new String();
partypes1[0] = str.getClass();
Method meth1 = cls.getMethod("setAddress", partypes1);
Object arglist1[] = new Object[1];
arglist1[0] = address;
meth1.invoke(retobj, arglist1);
// Set port number
Class partypes2 [] = new Class[1];
partypes2[0] = Integer.TYPE;
Method meth2 = cls.getMethod("setPort", partypes2);
Object arglist2[] = new Object[1];
arglist2[0] = new Integer(port);
meth2.invoke(retobj, arglist2);
// set protocolHandlerClassName for AJP
Class partypes3 [] = new Class[1];
partypes3[0] = str.getClass();
Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3);
Object arglist3[] = new Object[1];
arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler");
meth3.invoke(retobj, arglist3);
} catch (Exception e) {
throw new MBeanException(e);
}
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
Server server = ServerFactory.getServer();
Service service = server.findService(pname.getKeyProperty("name"));
service.addConnector((Connector)retobj);
// Return the corresponding MBean name
ManagedBean managed = registry.findManagedBean("CoyoteConnector");
ObjectName oname =
MBeanUtils.createObjectName(managed.getDomain(), (Connector)retobj);
return (oname.toString());
}
示例14: createHttpConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Create a new HttpConnector
*
* @param parent MBean Name of the associated parent component
* @param address The IP address on which to bind
* @param port TCP port number to listen on
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createHttpConnector(String parent, String address, int port)
throws Exception {
Object retobj = null;
try {
// Create a new CoyoteConnector instance
// use reflection to avoid j-t-c compile-time circular dependencies
Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
Constructor ct = cls.getConstructor(null);
retobj = ct.newInstance(null);
Class partypes1 [] = new Class[1];
// Set address
String str = new String();
partypes1[0] = str.getClass();
Method meth1 = cls.getMethod("setAddress", partypes1);
Object arglist1[] = new Object[1];
arglist1[0] = address;
meth1.invoke(retobj, arglist1);
// Set port number
Class partypes2 [] = new Class[1];
partypes2[0] = Integer.TYPE;
Method meth2 = cls.getMethod("setPort", partypes2);
Object arglist2[] = new Object[1];
arglist2[0] = new Integer(port);
meth2.invoke(retobj, arglist2);
} catch (Exception e) {
throw new MBeanException(e);
}
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
Server server = ServerFactory.getServer();
Service service = server.findService(pname.getKeyProperty("name"));
service.addConnector((Connector)retobj);
// Return the corresponding MBean name
ManagedBean managed = registry.findManagedBean("CoyoteConnector");
ObjectName oname =
MBeanUtils.createObjectName(managed.getDomain(), (Connector)retobj);
return (oname.toString());
}
示例15: storeConnector
import org.apache.catalina.Connector; //导入依赖的package包/类
/**
* Store the specified Connector properties.
*
* @param writer PrintWriter to which we are storing
* @param indent Number of spaces to indent this element
* @param connector Object whose properties are being stored
*
* @exception Exception if an exception occurs while storing
*/
private void storeConnector(PrintWriter writer, int indent,
Connector connector) throws Exception {
// Store the beginning of this element
for (int i = 0; i < indent; i++) {
writer.print(' ');
}
writer.print("<Connector");
storeAttributes(writer, connector);
writer.println(">");
// Store nested <Factory> element
ServerSocketFactory factory = connector.getFactory();
if (factory != null) {
storeFactory(writer, indent + 2, factory);
}
// Store nested <Listener> elements
if (connector instanceof Lifecycle) {
LifecycleListener listeners[] =
((Lifecycle) connector).findLifecycleListeners();
if (listeners == null) {
listeners = new LifecycleListener[0];
}
for (int i = 0; i < listeners.length; i++) {
if (listeners[i].getClass().getName().equals
(SERVER_LISTENER_CLASS_NAME)) {
continue;
}
storeListener(writer, indent + 2, listeners[i]);
}
}
// Store the ending of this element
for (int i = 0; i < indent; i++) {
writer.print(' ');
}
writer.println("</Connector>");
}