use of org.glassfish.grizzly.http.server.util.Mapper in project Payara by payara.
the class Connector method initialize.
/**
* Initialize this connector (create ServerSocket here!)
*/
@Override
public void initialize() throws LifecycleException {
if (initialized) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, LogFacade.CONNECTOR_BEEN_INIT);
}
return;
}
this.initialized = true;
// If the Mapper is null, do not fail and creates one by default.
if (mapper == null) {
mapper = new Mapper();
}
if (oname == null && (container instanceof StandardEngine)) {
try {
// we are loaded directly, via API - and no name was given to us
StandardEngine cb = (StandardEngine) container;
oname = createObjectName(domain, "Connector");
controller = oname;
} catch (Exception e) {
log.log(Level.SEVERE, LogFacade.ERROR_REGISTER_CONNECTOR_EXCEPTION, e);
}
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Creating name for connector " + oname);
}
}
// START SJSAS 6363251
if (handler == null) {
try {
Class<?> clazz = Class.forName(defaultClassName);
Constructor constructor = clazz.getConstructor(new Class<?>[] { Connector.class });
handler = (HttpHandler) constructor.newInstance(new Object[] { this });
} catch (Exception e) {
throw new LifecycleException(rb.getString(LogFacade.FAILED_INSTANCIATE_HTTP_HANDLER_EXCEPTION), e);
}
}
// Instantiate protocol handler
if (protocolHandler == null) {
try {
Class<?> clazz = Class.forName(protocolHandlerClassName);
// use no-arg constructor for JkCoyoteHandler
if (protocolHandlerClassName.equals("org.apache.jk.server.JkCoyoteHandler")) {
protocolHandler = (ProtocolHandler) clazz.newInstance();
if (handler instanceof CoyoteAdapter) {
((CoyoteAdapter) handler).setCompatWithTomcat(true);
} else {
String msg = MessageFormat.format(rb.getString(LogFacade.INVALID_ADAPTER_IMPLEMENTATION_EXCEPTION), handler);
throw new IllegalStateException(msg);
}
// START SJSAS 6439313
} else {
Constructor constructor = clazz.getConstructor(new Class<?>[] { Boolean.TYPE, Boolean.TYPE, String.class });
protocolHandler = (ProtocolHandler) constructor.newInstance(secure, blocking, selectorThreadImpl);
// END SJSAS 6439313
}
} catch (Exception e) {
String msg = MessageFormat.format(rb.getString(LogFacade.PROTOCOL_HANDLER_INIT_FAILED_EXCEPTION), e);
throw new LifecycleException(msg);
}
}
protocolHandler.setHandler(handler);
IntrospectionUtils.setProperty(protocolHandler, "jkHome", System.getProperty("catalina.base"));
// XXX For backwards compatibility only.
if (factory instanceof CoyoteServerSocketFactory) {
IntrospectionUtils.setProperty(protocolHandler, "secure", "" + true);
CoyoteServerSocketFactory ssf = (CoyoteServerSocketFactory) factory;
IntrospectionUtils.setProperty(protocolHandler, "algorithm", ssf.getAlgorithm());
if (ssf.getClientAuth()) {
IntrospectionUtils.setProperty(protocolHandler, "clientauth", "" + ssf.getClientAuth());
}
IntrospectionUtils.setProperty(protocolHandler, "keystore", ssf.getKeystoreFile());
IntrospectionUtils.setProperty(protocolHandler, "randomfile", ssf.getRandomFile());
IntrospectionUtils.setProperty(protocolHandler, "rootfile", ssf.getRootFile());
IntrospectionUtils.setProperty(protocolHandler, "keypass", ssf.getKeystorePass());
IntrospectionUtils.setProperty(protocolHandler, "keytype", ssf.getKeystoreType());
IntrospectionUtils.setProperty(protocolHandler, "protocol", ssf.getProtocol());
IntrospectionUtils.setProperty(protocolHandler, "protocols", ssf.getProtocols());
IntrospectionUtils.setProperty(protocolHandler, "sSLImplementation", ssf.getSSLImplementation());
IntrospectionUtils.setProperty(protocolHandler, "ciphers", ssf.getCiphers());
IntrospectionUtils.setProperty(protocolHandler, "keyAlias", ssf.getKeyAlias());
} else {
IntrospectionUtils.setProperty(protocolHandler, "secure", "" + secure);
}
/* Set the configured properties. This only sets the ones that were
* explicitly configured. Default values are the responsibility of
* the protocolHandler.
*/
Iterator<String> keys = properties.keySet().iterator();
while (keys.hasNext()) {
String name = keys.next();
String value = properties.get(name);
String trnName = translateAttributeName(name);
IntrospectionUtils.setProperty(protocolHandler, trnName, value);
}
try {
protocolHandler.init();
} catch (Exception e) {
String msg = MessageFormat.format(rb.getString(LogFacade.PROTOCOL_HANDLER_INIT_FAILED_EXCEPTION), e);
throw new LifecycleException(msg);
}
}
use of org.glassfish.grizzly.http.server.util.Mapper in project Payara by payara.
the class WebContainer method updateConnector.
/**
* Update an network-listener
*
* @param networkListener
* @param httpService the configuration bean.
* @throws org.apache.catalina.LifecycleException
*/
public void updateConnector(NetworkListener networkListener, HttpService httpService) throws LifecycleException {
synchronized (mapperUpdateSync) {
// admin-related webapps are accessible on http-listener-1.
if (networkListener.findHttpProtocol().getHttp().getDefaultVirtualServer().equals(org.glassfish.api.web.Constants.ADMIN_VS) || "http-listener-1".equals(networkListener.getName()) && connectorMap.get("admin-listener") == null) {
return;
}
WebConnector connector = connectorMap.get(networkListener.getName());
if (connector != null) {
deleteConnector(connector);
}
if (!Boolean.valueOf(networkListener.getEnabled())) {
return;
}
connector = addConnector(networkListener, httpService, false);
// Update the list of listener names of all associated virtual servers with
// the listener's new listener name , so that the associated virtual
// servers will be registered with the listener's request mapper when
// the listener is started
List<VirtualServer> virtualServers = getVirtualServersForHttpListenerId(httpService, networkListener.getName());
if (virtualServers != null) {
for (VirtualServer vs : virtualServers) {
boolean found = false;
String[] listenerNames = vs.getNetworkListenerNames();
String name = connector.getName();
for (String listenerName : listenerNames) {
if (listenerName.equals(name)) {
found = true;
break;
}
}
if (!found) {
String[] newListenerNames = new String[listenerNames.length + 1];
System.arraycopy(listenerNames, 0, newListenerNames, 0, listenerNames.length);
newListenerNames[listenerNames.length] = connector.getName();
vs.setNetworkListenerNames(newListenerNames);
}
}
}
connector.start();
// information
if (virtualServers != null) {
Mapper mapper = connector.getMapper();
for (VirtualServer vs : virtualServers) {
String defaultWebModulePath = vs.getDefaultContextPath(domain, appRegistry);
if (defaultWebModulePath != null) {
try {
mapper.setDefaultContextPath(vs.getName(), defaultWebModulePath);
vs.setDefaultContextPath(defaultWebModulePath);
} catch (Exception e) {
throw new LifecycleException(e);
}
}
}
}
}
}
use of org.glassfish.grizzly.http.server.util.Mapper in project Payara by payara.
the class ApplicationDispatcher method computeNamedDispatchHttpServletMapping.
private HttpServletMapping computeNamedDispatchHttpServletMapping(Context context, HttpServletRequest hcurrent) {
HttpServletMapping result = null;
Mapper mapper = context.getMapper();
if (null == mapper) {
return null;
}
MessageBytes uriMB = MessageBytes.newInstance();
CharChunk cc = uriMB.getCharChunk();
MappingData mappingData = new MappingData();
String requestURI = hcurrent.getRequestURI();
if (null == requestURI) {
return null;
}
try {
cc.append(requestURI, 0, requestURI.length());
mapper.map(uriMB, mappingData);
} catch (Exception ex) {
return null;
}
result = new MappingImpl(mappingData);
return result;
}
use of org.glassfish.grizzly.http.server.util.Mapper in project Payara by payara.
the class WebContainer method createJKConnector.
/**
* Starts the AJP connector that will listen to call from Apache using mod_jk, mod_jk2 or mod_ajp.
*
* @param listener
* @param httpService
* @return
*/
protected WebConnector createJKConnector(NetworkListener listener, HttpService httpService) {
int port = 8009;
boolean isSecure = false;
String address = null;
if (listener == null) {
String portString = System.getProperty("com.sun.enterprise.web.connector.enableJK");
if (portString == null) {
// do not create JK Connector if property is not set
return null;
} else {
try {
port = Integer.parseInt(portString);
} catch (NumberFormatException ex) {
// use default port 8009
port = 8009;
}
}
} else {
port = Integer.parseInt(listener.getPort());
isSecure = Boolean.valueOf(listener.findHttpProtocol().getSecurityEnabled());
address = listener.getAddress();
}
if (isSecure && defaultRedirectPort == -1) {
defaultRedirectPort = port;
}
if ("any".equals(address) || "ANY".equals(address) || "INADDR_ANY".equals(address)) {
address = null;
/*
* Setting 'address' to NULL will cause Tomcat to pass a NULL InetAddress argument to the java.net.ServerSocket
* constructor, meaning that the server socket will accept connections on any/all local addresses.
*/
}
jkConnector = (WebConnector) _embedded.createConnector(address, port, "ajp");
jkConnector.configureJKProperties(listener);
jkConnector.setDomain(_serverContext.getDefaultDomainName());
jkConnector.setInstanceName(instanceName);
String defaultHost = "server";
String jkConnectorName = "jk-connector";
if (listener != null) {
defaultHost = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
jkConnectorName = listener.getName();
jkConnector.configure(listener, isSecure, httpService);
connectorMap.put(listener.getName(), jkConnector);
if (logger.isLoggable(INFO)) {
logger.log(INFO, JK_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), listener.getPort() });
}
for (Mapper mapper : serviceLocator.getAllServices(Mapper.class)) {
if (mapper.getPort() == port && mapper instanceof ContextMapper) {
ContextMapper contextMapper = (ContextMapper) mapper;
if (listener.getName().equals(contextMapper.getId())) {
jkConnector.setMapper(mapper);
break;
}
}
}
}
jkConnector.setDefaultHost(defaultHost);
jkConnector.setName(jkConnectorName);
_embedded.addConnector(jkConnector);
return jkConnector;
}
use of org.glassfish.grizzly.http.server.util.Mapper in project Payara by payara.
the class WebContainer method createHttpListener.
protected WebConnector createHttpListener(NetworkListener listener, HttpService httpService, Mapper mapper) {
if (!Boolean.valueOf(listener.getEnabled())) {
return null;
}
int port = grizzlyService.getRealPort(listener);
WebConnector connector;
checkHostnameUniqueness(listener.getName(), httpService);
if (mapper == null) {
for (Mapper m : serviceLocator.getAllServices(Mapper.class)) {
if (m.getPort() == port && m instanceof ContextMapper) {
ContextMapper contextMapper = (ContextMapper) m;
if (listener.getName().equals(contextMapper.getId())) {
mapper = m;
break;
}
}
}
}
String defaultVirtualServer = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
if (!defaultVirtualServer.equals(ADMIN_VS)) {
// Before we start a WebConnector, let's makes sure there is
// not another Container already listening on that port
DataChunk host = DataChunk.newInstance();
char[] defaultVirtualServerAsChars = defaultVirtualServer.toCharArray();
host.setChars(defaultVirtualServerAsChars, 0, defaultVirtualServerAsChars.length);
DataChunk dataChunk = DataChunk.newInstance();
dataChunk.setChars(new char[] { '/' }, 0, 1);
MappingData mappingData = new MappingData();
try {
mapper.map(host, dataChunk, mappingData);
} catch (Exception e) {
logger.log(FINE, "", e);
}
if (mappingData.context != null && mappingData.context instanceof ContextRootInfo) {
ContextRootInfo rootInfo = (ContextRootInfo) mappingData.context;
if (!(rootInfo.getHttpHandler() instanceof ContainerMapper)) {
new BindException("Port " + port + " is already used by Container: " + rootInfo.getHttpHandler() + " and will not get started.").printStackTrace();
return null;
}
}
}
/*
* Create Connector. Connector is SSL-enabled if 'security-enabled' attribute in <http-listener> element is set to TRUE.
*/
boolean isSecure = Boolean.valueOf(listener.findHttpProtocol().getSecurityEnabled());
if (isSecure && defaultRedirectPort == -1) {
defaultRedirectPort = port;
}
String address = listener.getAddress();
if ("any".equals(address) || "ANY".equals(address) || "INADDR_ANY".equals(address)) {
address = null;
/*
* Setting 'address' to NULL will cause Tomcat to pass a NULL InetAddress argument to the java.net.ServerSocket
* constructor, meaning that the server socket will accept connections on any/all local addresses.
*/
}
connector = (WebConnector) _embedded.createConnector(address, port, isSecure);
connector.setMapper(mapper);
connector.setJvmRoute(engine.getJvmRoute());
logger.log(INFO, HTTP_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), Integer.toString(port) });
connector.setDefaultHost(listener.findHttpProtocol().getHttp().getDefaultVirtualServer());
connector.setName(listener.getName());
connector.setInstanceName(instanceName);
connector.configure(listener, isSecure, httpService);
_embedded.addConnector(connector);
connectorMap.put(listener.getName(), connector);
// If we already know the redirect port, then set it now
// This situation will occurs when dynamic reconfiguration occurs
String redirectPort = listener.findHttpProtocol().getHttp().getRedirectPort();
if (redirectPort != null) {
connector.setRedirectPort(Integer.parseInt(redirectPort));
} else if (defaultRedirectPort != -1) {
connector.setRedirectPort(defaultRedirectPort);
}
ObservableBean httpListenerBean = (ObservableBean) ConfigSupport.getImpl(listener);
httpListenerBean.addListener(configListener);
return connector;
}
Aggregations