Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Bug 346894] support multiple instances of jetty patch

  • Loading branch information...
commit 31e67dc49937dbd612ff7d47c4c45c9c79f82de2 1 parent 5177c14
@jmcc0nn3ll jmcc0nn3ll authored
Showing with 167 additions and 60 deletions.
  1. +7 −0 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/IJettyConfiguration.java
  2. +1 −1  org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/IJettyVersionHandler.java
  3. +12 −1 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/JettyServerBehaviour.java
  4. +1 −1  org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/Messages.properties
  5. +29 −1 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/config/StartIni.java
  6. +80 −37 ...clipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/jetty7/Jetty7Configuration.java
  7. +2 −2 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/jetty7/Jetty7Handler.java
  8. +7 −4 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/util/JettyVersionHelper.java
  9. +18 −11 ...eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/xml/jetty7/ServerInstance.java
  10. +8 −1 ...lipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/xml/jetty7/server/Connector.java
  11. +2 −1  org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/xml/jetty7/server/Server.java
View
7 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/IJettyConfiguration.java
@@ -47,6 +47,13 @@
* @return ServerPort
*/
ServerPort getMainPort();
+
+ /**
+ * Returns the admin port
+ *
+ * @return ServerPort
+ */
+ ServerPort getAdminPort();
/**
*
View
2  org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/IJettyVersionHandler.java
@@ -83,7 +83,7 @@
* test environment flag
* @return array of VM arguments for starting the server
*/
- public String[] getRuntimeVMArguments(IPath installPath, IPath configPath, IPath deployPath, boolean isTestEnv);
+ public String[] getRuntimeVMArguments(IPath installPath, IPath configPath, IPath deployPath, int mainPort, int adminPort, boolean isTestEnv);
/**
* Gets the contents of the Java policy file for the Jetty server.
View
13 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/JettyServerBehaviour.java
@@ -203,7 +203,18 @@ public IPath getRuntimeBaseDirectory()
}
}
}
- return getJettyVersionHandler().getRuntimeVMArguments(installPath,configPath,deployPath,getJettyServer().isTestEnvironment());
+
+ int mainPort = 8080;
+ int adminPort = 8082;
+ try {
+ IJettyConfiguration config = getJettyConfiguration();
+ mainPort = config.getMainPort().getPort();
+ adminPort = config.getAdminPort().getPort();
+ } catch (CoreException ex) {
+ // ignore exception and use the defaults;
+ }
+
+ return getJettyVersionHandler().getRuntimeVMArguments(installPath,configPath,deployPath,mainPort, adminPort, getJettyServer().isTestEnvironment());
}
protected String getRuntimePolicyFile()
View
2  org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/Messages.properties
@@ -27,7 +27,7 @@ configurationEditorActionRemoveWebModule=Web Module Removal
configurationEditorActionModifyPort=Port Number Change
# --------------- General ---------------
-portServer=Jetty port
+portServer=Jetty admin port
# --------------- Errors and Info ---------------
errorVersionEmpty=The Jetty version must be specified.
View
30 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/config/StartIni.java
@@ -37,6 +37,7 @@
private List<PathFileConfig> _otherConfigs = new ArrayList<PathFileConfig>();
private PathFileConfig _startConfig = null;
private PathFileConfig _webdefaultXMLConfig = null;
+ private File _adminPortFile = null;
private File _startIniFile;
private boolean _isStartIniDirty;
@@ -45,12 +46,14 @@ public StartIni(IPath baseDirPath)
{
loadStartIni(baseDirPath,null);
loadOtherConfigs(baseDirPath);
+ loadAdminPortFile (baseDirPath,null);
}
public StartIni(IFolder baseDirFolder)
{
loadStartIni(null,baseDirFolder);
// loadOtherConfigs(null, baseDirFolder);
+ loadAdminPortFile (null,baseDirFolder);
}
private List<String> loadStartIni(IPath baseDirPath, IFolder baseDirFolder)
@@ -159,7 +162,7 @@ private void loadOtherConfigs(IPath baseDirPath)
{
_webdefaultXMLConfig = new PathFileConfig(webdefaultFile,new Path("etc/webdefault.xml"));
}
-
+
IPath startJARPath = baseDirPath.append(__START_JAR);
File startConfigFile = startJARPath.toFile();
if (startConfigFile.exists())
@@ -167,6 +170,26 @@ private void loadOtherConfigs(IPath baseDirPath)
_startConfig = new PathFileConfig(startConfigFile,new Path(__START_JAR));
}
}
+
+ private void loadAdminPortFile (IPath baseDirPath, IFolder baseDirFolder)
+ {
+ if (baseDirPath != null)
+ {
+ IPath adminPortPath = baseDirPath.append("adminPort");
+ this._adminPortFile = adminPortPath.toFile();
+ }
+ else
+ {
+ try
+ {
+ this._adminPortFile = IOUtils.toLocalFile(baseDirFolder.getFile("adminPort"),null);
+ }
+ catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
public List<PathFileConfig> getJettyXMLFiles()
{
@@ -177,6 +200,11 @@ public PathFileConfig getWebdefaultXMLConfig()
{
return _webdefaultXMLConfig;
}
+
+ public File getAdminPortFile()
+ {
+ return _adminPortFile;
+ }
/**
* Saves the Web app document.
View
117 ...pse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/jetty7/Jetty7Configuration.java
@@ -12,9 +12,11 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
@@ -73,13 +75,12 @@ public Jetty7Configuration(IFolder path)
List<ServerPort> ports = new ArrayList<ServerPort>();
// first add server port
- // try {
- // int port = Integer.parseInt(server.getPort());
- // ports.add(new ServerPort("server", Messages.portServer, port,
- // "TCPIP"));
- // } catch (Exception e) {
- // // ignore
- // }
+ try {
+ int port = Integer.parseInt(_serverInstance.getAdminPort());
+ ports.add(new ServerPort("server", Messages.portServer, port, "TCPIP"));
+ } catch (Exception e) {
+ // ignore
+ }
// add connectors
try
@@ -88,6 +89,7 @@ public Jetty7Configuration(IFolder path)
Collection<Connector> connectors = _serverInstance.getConnectors();
if (connectors != null)
{
+ int portId = 0;
for (Connector connector : connectors)
{
int port = -1;
@@ -99,7 +101,22 @@ public Jetty7Configuration(IFolder path)
{
// ignore
}
- ports.add(new ServerPort("server",Messages.portServer,port,__HTTP));
+
+ String id = Integer.toString(portId++);
+ String type = connector.getType();
+ String name = "HTTP";
+ String className = type.substring(type.lastIndexOf('.')+1);
+ if ("SelectChannelConnector".equals(className) ||
+ "SocketConnector".equals(className)) {
+ name = "HTTP";
+ } else if ("SslSelectChannelConnector".equals(className) ||
+ "SslSocketConnector".equals(className)) {
+ name = "SSL";
+ } else if ("Ajp13SocketConnector".equals(className)) {
+ name = "AJP";
+ }
+
+ ports.add(new ServerPort(id,name,port,name));
// TODO : how get HTTP type port???
// ports.add(new ServerPort(portId, name, port, protocol2,
@@ -112,10 +129,7 @@ public Jetty7Configuration(IFolder path)
{
Trace.trace(Trace.SEVERE,"Error getting server ports",e);
}
- if (ports.size() < 1)
- {
- ports.add(new ServerPort("server",Messages.portServer,8080,__HTTP));
- }
+
return ports;
// String instanceServiceName = serverInstance.getService().getName();
@@ -181,6 +195,28 @@ public Jetty7Configuration(IFolder path)
// }
}
+
+ /**
+ * Return the port number.
+ *
+ * @return int
+ */
+ public ServerPort getAdminPort()
+ {
+ Collection<ServerPort> serverPorts = getServerPorts();
+
+ for (ServerPort serverPort : serverPorts)
+ {
+ // Return only an HTTP port from the selected Service
+ if (serverPort.getId().equals("server"))
+ {
+ return serverPort;
+ }
+ }
+
+ return null;
+ }
+
/**
* Return a list of the web modules in this server.
@@ -361,6 +397,15 @@ public void load(IPath path, IPath runtimeBaseDirectory, IProgressMonitor monito
webApp.setFile(webAppFile);
webApp.setPath(webAppPath);
}
+
+ File adminPortFile = _startIniConfig.getAdminPortFile();
+ String adminPort = null;
+ if (adminPortFile != null && adminPortFile.exists())
+ {
+ BufferedReader reader = new BufferedReader(new FileReader(adminPortFile));
+ adminPort = reader.readLine();
+ reader.close();
+ }
// check for catalina.policy to verify that this is a v4.0 config
// InputStream in = new
// FileInputStream(path.append("catalina.policy").toFile());
@@ -371,6 +416,10 @@ public void load(IPath path, IPath runtimeBaseDirectory, IProgressMonitor monito
// server = (Server) serverFactory.loadDocument(new FileInputStream(
// path.append("jetty.xml").toFile()));
_serverInstance = new ServerInstance(servers,webApp,runtimeBaseDirectory);
+ if (adminPort != null)
+ {
+ _serverInstance.setAdminPort(adminPort);
+ }
// monitor.worked(1);
//
// webAppDocument = new
@@ -450,9 +499,21 @@ public void load(IFolder folder, IPath runtimeBaseDirectory, IProgressMonitor mo
webApp.setFile(webAppFile);
webApp.setPath(webAppPath);
}
+ File adminPortFile = _startIniConfig.getAdminPortFile();
+ String adminPort = null;
+ if (adminPortFile != null && adminPortFile.exists())
+ {
+ BufferedReader reader = new BufferedReader(new FileReader(adminPortFile));
+ adminPort = reader.readLine();
+ reader.close();
+ }
// server = (Server) serverFactory.loadDocument(new FileInputStream(
// path.append("jetty.xml").toFile()));
_serverInstance = new ServerInstance(servers,webApp,runtimeBaseDirectory);
+ if (adminPort != null)
+ {
+ _serverInstance.setAdminPort(adminPort);
+ }
// check for catalina.policy to verify that this is a v4.0 config
// IFile file = folder.getFile("catalina.policy");
// if (!file.exists())
@@ -611,36 +672,18 @@ public void modifyServerPort(String id, int port)
{
if ("server".equals(id))
{
- _serverInstance.setPort(port + "");
+ _serverInstance.setAdminPort(port+"");
_isServerDirty = true;
firePropertyChangeEvent(__MODIFY_PORT_PROPERTY,id, Integer.valueOf(port));
return;
}
- // int i = id.indexOf("/");
- // // If a connector in the instance Service
- // if (i < 0) {
- // int connNum = Integer.parseInt(id);
- // Connector connector = serverInstance.getConnector(connNum);
- // if (connector != null) {
- // connector.setPort(port + "");
- // isServerDirty = true;
- // firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new
- // Integer(port));
- // }
- // }
- // // Else a connector in another Service
- // else {
- // int servNum = Integer.parseInt(id.substring(0, i));
- // int connNum = Integer.parseInt(id.substring(i + 1));
- //
- // Service service = server.getService(servNum);
- // Connector connector = service.getConnector(connNum);
- // connector.setPort(port + "");
- // isServerDirty = true;
- // firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new
- // Integer(port));
- // }
+ int connNum = Integer.parseInt(id);
+ List<Connector> connectors = _serverInstance.getConnectors();
+ Connector connector = connectors.get(connNum);
+ connector.setPort(port + "");
+ _isServerDirty = true;
+ firePropertyChangeEvent(__MODIFY_PORT_PROPERTY, id, new Integer(port));
}
catch (Exception e)
{
View
4 org.eclipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/jetty7/Jetty7Handler.java
@@ -73,9 +73,9 @@ public IPath getRuntimeBaseDirectory(JettyServer server)
/**
* @see IJettyVersionHandler#getRuntimeVMArguments(IPath, IPath, IPath, boolean)
*/
- public String[] getRuntimeVMArguments(IPath installPath, IPath configPath, IPath deployPath, boolean isTestEnv)
+ public String[] getRuntimeVMArguments(IPath installPath, IPath configPath, IPath deployPath, int mainPort, int adminPort, boolean isTestEnv)
{
- return JettyVersionHelper.getJettyVMArguments(installPath,configPath,deployPath,getEndorsedDirectories(installPath),isTestEnv);
+ return JettyVersionHelper.getJettyVMArguments(installPath,configPath,deployPath,getEndorsedDirectories(installPath), mainPort, adminPort, isTestEnv);
}
public String getEndorsedDirectories(IPath installPath)
View
11 ...clipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/util/JettyVersionHelper.java
@@ -86,11 +86,15 @@ public static IPath getStandardBaseDirectory(JettyServer ts)
* instance path for the server
* @param deployPath
* deploy path for the server
+ * @param adminPort
+ * port that jetty listens to for admin operations like shutdown
+ * @param mainPort
+ * main jetty port (passed as jetty.port)
* @param isTestEnv
* test environment flag
* @return array of strings containing VM arguments
*/
- public static String[] getJettyVMArguments(IPath installPath, IPath instancePath, IPath deployPath, String endorsedDirs, boolean isTestEnv)
+ public static String[] getJettyVMArguments(IPath installPath, IPath instancePath, IPath deployPath, String endorsedDirs, int mainPort, int adminPort, boolean isTestEnv)
{
List<String> list = new ArrayList<String>();
if (isTestEnv)
@@ -111,9 +115,8 @@ public static IPath getStandardBaseDirectory(JettyServer ts)
// list.add("-Djava.endorsed.dirs=\"" + endorsedDirs + "\"");
list.add("-DVERBOSE");
- // list.add("-Djetty.port=8081");
- // list.add("-Djetty.port=8081");
- list.add("-DSTOP.PORT=8082");
+ list.add("-Djetty.port=" + Integer.toString(mainPort));
+ list.add("-DSTOP.PORT=" + Integer.toString(adminPort));
list.add("-DSTOP.KEY=secret");
String[] s = new String[list.size()];
View
29 ...ipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/xml/jetty7/ServerInstance.java
@@ -41,6 +41,7 @@
private boolean _contextsLoaded = false;
private List<WebAppContext> _webAppContexts = new ArrayList<WebAppContext>();
private WebApp _webApp = null;
+ private String _adminPort = "8082";
public ServerInstance(List<Server> jettyServers, WebApp webApp, IPath runtimeBaseDirectory)
{
@@ -125,6 +126,16 @@ public void save(final IFolder folder, IProgressMonitor monitor) throws IOExcept
else
file.create(in,true,ProgressUtil.getSubMonitorFor(monitor,200));
}
+ IFile adminPortFile = folder.getFile("adminPort");
+ in = new ByteArrayInputStream(_adminPort.getBytes());
+ if (adminPortFile.exists())
+ {
+ adminPortFile.setContents(in,true,true,ProgressUtil.getSubMonitorFor(monitor,200));
+ }
+ else
+ {
+ adminPortFile.create(in, true, ProgressUtil.getSubMonitorFor(monitor,200));
+ }
if (_webApp != null)
{
path = _webApp.getPath();
@@ -261,20 +272,16 @@ private void loadContextsIfNeeded()
return _webAppContexts;
}
- public void setPort(String port)
- {
- List<Connector> connectors = getConnectors();
- if (connectors != null && connectors.size() > 0)
- {
- Connector connector = connectors.get(0);
- connector.setPort(port);
- }
-
- }
-
public WebAppContext getContext(int index)
{
return _webAppContexts.get(index);
}
+ public void setAdminPort(String port) {
+ _adminPort = port;
+ }
+
+ public String getAdminPort () {
+ return _adminPort;
+ }
}
View
9 ...se.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/xml/jetty7/server/Connector.java
@@ -17,10 +17,12 @@
{
private Element _portElement;
+ private Element _typeElement;
- public Connector(Element portElement)
+ public Connector(Element portElement, Element typeElement)
{
this._portElement = portElement;
+ this._typeElement = typeElement;
}
public String getPort()
@@ -37,6 +39,11 @@ public String getPort()
return _portElement.getTextContent();
}
}
+
+ public String getType()
+ {
+ return _typeElement.getAttribute("class");
+ }
public void setPort(String port)
{
View
3  ...lipse.jst.server.jetty.core/src/org/eclipse/jst/server/jetty/core/internal/xml/jetty7/server/Server.java
@@ -37,9 +37,10 @@
if (hasAttribute(node,"addConnector"))
{
Element portElement = super.findElement(node,"Set","port");
+ NodeList typeElements = node.getElementsByTagName("New");
if (portElement != null)
{
- Connector connector = new Connector(portElement);
+ Connector connector = new Connector(portElement, (Element)typeElements.item(0));
if (connectors == null)
{
connectors = new ArrayList<Connector>();
Please sign in to comment.
Something went wrong with that request. Please try again.