init
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
public abstract class AbstractCatalinaCommandTask extends AbstractCatalinaTask {
|
||||
|
||||
/**
|
||||
* The context path of the web application we are managing.
|
||||
*/
|
||||
protected String path = null;
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* The context version of the web application we are managing.
|
||||
*/
|
||||
protected String version = null;
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Create query string for the specified command.
|
||||
*
|
||||
* @param command Command to be executed
|
||||
*
|
||||
* @return The generated query string
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
public StringBuilder createQueryString(String command) throws BuildException {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
try {
|
||||
buffer.append(command);
|
||||
if (path == null) {
|
||||
throw new BuildException("Must specify 'path' attribute");
|
||||
} else {
|
||||
buffer.append("?path=");
|
||||
buffer.append(URLEncoder.encode(this.path, getCharset()));
|
||||
if (this.version != null) {
|
||||
buffer.append("&version=");
|
||||
buffer.append(URLEncoder.encode(this.version, getCharset()));
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new BuildException("Invalid 'charset' attribute: " + getCharset());
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
341
java/org/apache/catalina/ant/AbstractCatalinaTask.java
Normal file
341
java/org/apache/catalina/ant/AbstractCatalinaTask.java
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Authenticator;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.apache.catalina.util.IOTools;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
|
||||
/**
|
||||
* Abstract base class for Ant tasks that interact with the <em>Manager</em> web
|
||||
* application for dynamically deploying and undeploying applications. These
|
||||
* tasks require Ant 1.4 or later.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* manager webapp's encoding.
|
||||
*/
|
||||
private static final String CHARSET = "utf-8";
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* The charset used during URL encoding.
|
||||
*/
|
||||
protected String charset = "ISO-8859-1";
|
||||
|
||||
public String getCharset() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
public void setCharset(String charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The login password for the <code>Manager</code> application.
|
||||
*/
|
||||
protected String password = null;
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The URL of the <code>Manager</code> application to be used.
|
||||
*/
|
||||
protected String url = "http://localhost:8080/manager/text";
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The login username for the <code>Manager</code> application.
|
||||
*/
|
||||
protected String username = null;
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true - ignore the constraint of the first line of the response
|
||||
* message that must be "OK -".
|
||||
* <p>
|
||||
* When this attribute is set to {@code false} (the default), the first line
|
||||
* of server response is expected to start with "OK -". If it does not then
|
||||
* the task is considered as failed and the first line is treated as an
|
||||
* error message.
|
||||
* <p>
|
||||
* When this attribute is set to {@code true}, the first line of the
|
||||
* response is treated like any other, regardless of its text.
|
||||
*/
|
||||
protected boolean ignoreResponseConstraint = false;
|
||||
|
||||
public boolean isIgnoreResponseConstraint() {
|
||||
return ignoreResponseConstraint;
|
||||
}
|
||||
|
||||
public void setIgnoreResponseConstraint(boolean ignoreResponseConstraint) {
|
||||
this.ignoreResponseConstraint = ignoreResponseConstraint;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Execute the specified command. This logic only performs the common
|
||||
* attribute validation required by all subclasses; it does not perform any
|
||||
* functional logic directly.
|
||||
*
|
||||
* @exception BuildException if a validation error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
if ((username == null) || (password == null) || (url == null)) {
|
||||
throw new BuildException("Must specify all of 'username', 'password', and 'url'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the specified command, based on the configured properties.
|
||||
*
|
||||
* @param command Command to be executed
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
public void execute(String command) throws BuildException {
|
||||
execute(command, null, null, -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the specified command, based on the configured properties. The
|
||||
* input stream will be closed upon completion of this task, whether it was
|
||||
* executed successfully or not.
|
||||
*
|
||||
* @param command Command to be executed
|
||||
* @param istream InputStream to include in an HTTP PUT, if any
|
||||
* @param contentType Content type to specify for the input, if any
|
||||
* @param contentLength Content length to specify for the input, if any
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
public void execute(String command, InputStream istream, String contentType, long contentLength)
|
||||
throws BuildException {
|
||||
|
||||
URLConnection conn = null;
|
||||
InputStreamReader reader = null;
|
||||
try {
|
||||
// Set up authorization with our credentials
|
||||
Authenticator.setDefault(new TaskAuthenticator(username, password));
|
||||
|
||||
// Create a connection for this command
|
||||
conn = (new URL(url + command)).openConnection();
|
||||
HttpURLConnection hconn = (HttpURLConnection) conn;
|
||||
|
||||
// Set up standard connection characteristics
|
||||
hconn.setAllowUserInteraction(false);
|
||||
hconn.setDoInput(true);
|
||||
hconn.setUseCaches(false);
|
||||
if (istream != null) {
|
||||
preAuthenticate();
|
||||
|
||||
hconn.setDoOutput(true);
|
||||
hconn.setRequestMethod("PUT");
|
||||
if (contentType != null) {
|
||||
hconn.setRequestProperty("Content-Type", contentType);
|
||||
}
|
||||
if (contentLength >= 0) {
|
||||
hconn.setRequestProperty("Content-Length", "" + contentLength);
|
||||
|
||||
hconn.setFixedLengthStreamingMode(contentLength);
|
||||
}
|
||||
} else {
|
||||
hconn.setDoOutput(false);
|
||||
hconn.setRequestMethod("GET");
|
||||
}
|
||||
hconn.setRequestProperty("User-Agent", "Catalina-Ant-Task/1.0");
|
||||
|
||||
// Establish the connection with the server
|
||||
hconn.connect();
|
||||
|
||||
// Send the request data (if any)
|
||||
if (istream != null) {
|
||||
try (OutputStream ostream = hconn.getOutputStream()) {
|
||||
IOTools.flow(istream, ostream);
|
||||
} finally {
|
||||
try {
|
||||
istream.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process the response message
|
||||
reader = new InputStreamReader(hconn.getInputStream(), CHARSET);
|
||||
StringBuilder buff = new StringBuilder();
|
||||
String error = null;
|
||||
int msgPriority = Project.MSG_INFO;
|
||||
boolean first = true;
|
||||
while (true) {
|
||||
int ch = reader.read();
|
||||
if (ch < 0) {
|
||||
break;
|
||||
} else if ((ch == '\r') || (ch == '\n')) {
|
||||
// in Win \r\n would cause handleOutput() to be called
|
||||
// twice, the second time with an empty string,
|
||||
// producing blank lines
|
||||
if (buff.length() > 0) {
|
||||
String line = buff.toString();
|
||||
buff.setLength(0);
|
||||
if (!ignoreResponseConstraint && first) {
|
||||
if (!line.startsWith("OK -")) {
|
||||
error = line;
|
||||
msgPriority = Project.MSG_ERR;
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
handleOutput(line, msgPriority);
|
||||
}
|
||||
} else {
|
||||
buff.append((char) ch);
|
||||
}
|
||||
}
|
||||
if (buff.length() > 0) {
|
||||
handleOutput(buff.toString(), msgPriority);
|
||||
}
|
||||
if (error != null && isFailOnError()) {
|
||||
// exception should be thrown only if failOnError == true
|
||||
// or error line will be logged twice
|
||||
throw new BuildException(error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (isFailOnError()) {
|
||||
throw new BuildException(e);
|
||||
} else {
|
||||
handleErrorOutput(e.getMessage());
|
||||
}
|
||||
} finally {
|
||||
closeRedirector();
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ioe) {
|
||||
// Ignore
|
||||
}
|
||||
reader = null;
|
||||
}
|
||||
if (istream != null) {
|
||||
try {
|
||||
istream.close();
|
||||
} catch (IOException ioe) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This is a hack.
|
||||
* We need to use streaming to avoid OOME on large uploads.
|
||||
* We'd like to use Authenticator.setDefault() for authentication as the JRE
|
||||
* then provides the DIGEST client implementation.
|
||||
* However, the above two are not compatible. When the request is made, the
|
||||
* resulting 401 triggers an exception because, when using streams, the
|
||||
* InputStream is no longer available to send with the repeated request that
|
||||
* now includes the appropriate Authorization header.
|
||||
* The hack is to make a simple OPTIONS request- i.e. without a request
|
||||
* body.
|
||||
* This triggers authentication and the requirement to authenticate for this
|
||||
* host is cached and used to provide an appropriate Authorization when the
|
||||
* next request is made (that includes a request body).
|
||||
*/
|
||||
private void preAuthenticate() throws IOException {
|
||||
URLConnection conn = null;
|
||||
|
||||
// Create a connection for this command
|
||||
conn = (new URL(url)).openConnection();
|
||||
HttpURLConnection hconn = (HttpURLConnection) conn;
|
||||
|
||||
// Set up standard connection characteristics
|
||||
hconn.setAllowUserInteraction(false);
|
||||
hconn.setDoInput(true);
|
||||
hconn.setUseCaches(false);
|
||||
hconn.setDoOutput(false);
|
||||
hconn.setRequestMethod("OPTIONS");
|
||||
hconn.setRequestProperty("User-Agent", "Catalina-Ant-Task/1.0");
|
||||
|
||||
// Establish the connection with the server
|
||||
hconn.connect();
|
||||
|
||||
// Swallow response message
|
||||
IOTools.flow(hconn.getInputStream(), null);
|
||||
}
|
||||
|
||||
|
||||
private static class TaskAuthenticator extends Authenticator {
|
||||
|
||||
private final String user;
|
||||
private final String password;
|
||||
|
||||
private TaskAuthenticator(String user, String password) {
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(user, password.toCharArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
373
java/org/apache/catalina/ant/BaseRedirectorHelperTask.java
Normal file
373
java/org/apache/catalina/ant/BaseRedirectorHelperTask.java
Normal file
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.taskdefs.Redirector;
|
||||
import org.apache.tools.ant.types.RedirectorElement;
|
||||
|
||||
/**
|
||||
* Abstract base class to add output redirection support for Catalina Ant tasks.
|
||||
* These tasks require Ant 1.5 or later.
|
||||
* <br>
|
||||
* <strong>WARNING:</strong> due to depends chain, Ant could call a Task more
|
||||
* than once and this can affect the output redirection when configured. If you
|
||||
* are collecting the output in a property, it will collect the output of only
|
||||
* the first run, since Ant properties are immutable and once created they
|
||||
* cannot be changed. <br>
|
||||
* If you are collecting output in a file the file will be overwritten with the
|
||||
* output of the last run, unless you set append="true", in which case each run
|
||||
* will append it's output to the file.
|
||||
*
|
||||
*
|
||||
* @author Gabriele Garuglieri
|
||||
* @since 5.5
|
||||
*/
|
||||
public abstract class BaseRedirectorHelperTask extends Task {
|
||||
|
||||
/** Redirector helper */
|
||||
protected final Redirector redirector = new Redirector(this);
|
||||
|
||||
/** Redirector element for this task */
|
||||
protected RedirectorElement redirectorElement = null;
|
||||
|
||||
/** The stream for info output */
|
||||
protected OutputStream redirectOutStream = null;
|
||||
|
||||
/** The stream for error output */
|
||||
protected OutputStream redirectErrStream = null;
|
||||
|
||||
/** The print stream for info output */
|
||||
PrintStream redirectOutPrintStream = null;
|
||||
|
||||
/** The print stream for error output */
|
||||
PrintStream redirectErrPrintStream = null;
|
||||
|
||||
/**
|
||||
* Whether to fail (with a BuildException) if ManagerServlet returns an
|
||||
* error. The default behavior is to do so. <b> This flag does not control
|
||||
* parameters checking. If the task is called with wrong or invalid
|
||||
* parameters, it will throw BuildException independently from the setting
|
||||
* of this flag. </b>
|
||||
*/
|
||||
protected boolean failOnError = true;
|
||||
|
||||
/**
|
||||
* <code>true</code> true when output redirection is requested for this task.
|
||||
* Default is to log on Ant log.
|
||||
*/
|
||||
protected boolean redirectOutput = false;
|
||||
|
||||
/**
|
||||
* will be set to <code>true</code> when the configuration of the Redirector
|
||||
* is complete.
|
||||
*/
|
||||
protected boolean redirectorConfigured = false;
|
||||
|
||||
/**
|
||||
* Flag which indicates that, if redirected, output should also be always
|
||||
* sent to the log. Default is that output is sent only to redirected
|
||||
* streams.
|
||||
*/
|
||||
protected boolean alwaysLog = false;
|
||||
|
||||
|
||||
/**
|
||||
* Whether to fail (with a BuildException) if ManagerServlet returns an
|
||||
* error. The default behavior is to do so.
|
||||
*
|
||||
* @param fail The new value of failonerror
|
||||
*/
|
||||
public void setFailonerror(boolean fail) {
|
||||
failOnError = fail;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of the failOnError property.
|
||||
*
|
||||
* @return <code>true</code> if the task should will if an error occurs,
|
||||
* otherwise <code>false</code>
|
||||
*/
|
||||
public boolean isFailOnError() {
|
||||
return failOnError;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* File the output of the task is redirected to.
|
||||
*
|
||||
* @param out name of the output file
|
||||
*/
|
||||
public void setOutput(File out) {
|
||||
redirector.setOutput(out);
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* File the error output of the task is redirected to.
|
||||
*
|
||||
* @param error name of the error file
|
||||
*
|
||||
*/
|
||||
public void setError(File error) {
|
||||
redirector.setError(error);
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Controls whether error output is logged. This is only useful when output
|
||||
* is being redirected and error output is desired in the Ant log
|
||||
*
|
||||
* @param logError if true the standard error is sent to the Ant log system
|
||||
* and not sent to output stream.
|
||||
*/
|
||||
public void setLogError(boolean logError) {
|
||||
redirector.setLogError(logError);
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Property name whose value should be set to the output of the task.
|
||||
*
|
||||
* @param outputProperty property name
|
||||
*
|
||||
*/
|
||||
public void setOutputproperty(String outputProperty) {
|
||||
redirector.setOutputProperty(outputProperty);
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Property name whose value should be set to the error of the task.
|
||||
*
|
||||
* @param errorProperty property name
|
||||
*
|
||||
*/
|
||||
public void setErrorProperty(String errorProperty) {
|
||||
redirector.setErrorProperty(errorProperty);
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If true, append output to existing file.
|
||||
*
|
||||
* @param append if true, append output to existing file
|
||||
*
|
||||
*/
|
||||
public void setAppend(boolean append) {
|
||||
redirector.setAppend(append);
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If true, (error and non-error) output will be redirected as specified
|
||||
* while being sent to Ant's logging mechanism as if no redirection had
|
||||
* taken place. Defaults to false.
|
||||
* <br>
|
||||
* Actually handled internally, with Ant 1.6.3 it will be handled by the
|
||||
* <code>Redirector</code> itself.
|
||||
*
|
||||
* @param alwaysLog <code>boolean</code>
|
||||
*/
|
||||
public void setAlwaysLog(boolean alwaysLog) {
|
||||
this.alwaysLog = alwaysLog;
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether output and error files should be created even when empty.
|
||||
* Defaults to true.
|
||||
*
|
||||
* @param createEmptyFiles <CODE>boolean</CODE>.
|
||||
*/
|
||||
public void setCreateEmptyFiles(boolean createEmptyFiles) {
|
||||
redirector.setCreateEmptyFiles(createEmptyFiles);
|
||||
redirectOutput = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a <CODE>RedirectorElement</CODE> to this task.
|
||||
*
|
||||
* @param redirectorElement <CODE>RedirectorElement</CODE>.
|
||||
*/
|
||||
public void addConfiguredRedirector(RedirectorElement redirectorElement) {
|
||||
if (this.redirectorElement != null) {
|
||||
throw new BuildException("Cannot have > 1 nested <redirector>s");
|
||||
} else {
|
||||
this.redirectorElement = redirectorElement;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set up properties on the Redirector from RedirectorElement if present.
|
||||
*/
|
||||
private void configureRedirector() {
|
||||
if (redirectorElement != null) {
|
||||
redirectorElement.configure(redirector);
|
||||
redirectOutput = true;
|
||||
}
|
||||
/*
|
||||
* Due to depends chain, Ant could call the Task more than once, this is
|
||||
* to prevent that we attempt to configure uselessly more than once the
|
||||
* Redirector.
|
||||
*/
|
||||
redirectorConfigured = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set up properties on the Redirector and create output streams.
|
||||
*/
|
||||
protected void openRedirector() {
|
||||
if (!redirectorConfigured) {
|
||||
configureRedirector();
|
||||
}
|
||||
if (redirectOutput) {
|
||||
redirector.createStreams();
|
||||
redirectOutStream = redirector.getOutputStream();
|
||||
redirectOutPrintStream = new PrintStream(redirectOutStream);
|
||||
redirectErrStream = redirector.getErrorStream();
|
||||
redirectErrPrintStream = new PrintStream(redirectErrStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ask redirector to close all the streams. It is necessary to call this
|
||||
* method before leaving the Task to have the Streams flush their contents.
|
||||
* If you are collecting output in a property, it will be created only if
|
||||
* this method is called, otherwise you'll find it unset.
|
||||
*/
|
||||
protected void closeRedirector() {
|
||||
try {
|
||||
if (redirectOutput && redirectOutPrintStream != null) {
|
||||
redirector.complete();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
log("Error closing redirector: " + ioe.getMessage(), Project.MSG_ERR);
|
||||
}
|
||||
/*
|
||||
* Due to depends chain, Ant could call the Task more than once, this is
|
||||
* to prevent that we attempt to reuse the previously closed Streams.
|
||||
*/
|
||||
redirectOutStream = null;
|
||||
redirectOutPrintStream = null;
|
||||
redirectErrStream = null;
|
||||
redirectErrPrintStream = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles output with the INFO priority.
|
||||
*
|
||||
* @param output The output to log. Should not be <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
protected void handleOutput(String output) {
|
||||
if (redirectOutput) {
|
||||
if (redirectOutPrintStream == null) {
|
||||
openRedirector();
|
||||
}
|
||||
redirectOutPrintStream.println(output);
|
||||
if (alwaysLog) {
|
||||
log(output, Project.MSG_INFO);
|
||||
}
|
||||
} else {
|
||||
log(output, Project.MSG_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles output with the INFO priority and flushes the stream.
|
||||
*
|
||||
* @param output The output to log. Should not be <code>null</code>.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected void handleFlush(String output) {
|
||||
handleOutput(output);
|
||||
redirectOutPrintStream.flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles error output with the ERR priority.
|
||||
*
|
||||
* @param output The error output to log. Should not be <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
protected void handleErrorOutput(String output) {
|
||||
if (redirectOutput) {
|
||||
if (redirectErrPrintStream == null) {
|
||||
openRedirector();
|
||||
}
|
||||
redirectErrPrintStream.println(output);
|
||||
if (alwaysLog) {
|
||||
log(output, Project.MSG_ERR);
|
||||
}
|
||||
} else {
|
||||
log(output, Project.MSG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles error output with the ERR priority and flushes the stream.
|
||||
*
|
||||
* @param output The error output to log. Should not be <code>null</code>.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected void handleErrorFlush(String output) {
|
||||
handleErrorOutput(output);
|
||||
redirectErrPrintStream.flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles output with ERR priority to error stream and all other priorities
|
||||
* to output stream.
|
||||
*
|
||||
* @param output The output to log. Should not be <code>null</code>.
|
||||
* @param priority The priority level that should be used
|
||||
*/
|
||||
protected void handleOutput(String output, int priority) {
|
||||
if (priority == Project.MSG_ERR) {
|
||||
handleErrorOutput(output);
|
||||
} else {
|
||||
handleOutput(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
191
java/org/apache/catalina/ant/DeployTask.java
Normal file
191
java/org/apache/catalina/ant/DeployTask.java
Normal file
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/deploy</code> command, supported by the
|
||||
* Tomcat manager application.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class DeployTask extends AbstractCatalinaCommandTask {
|
||||
|
||||
private static final Pattern PROTOCOL_PATTERN = Pattern.compile("\\w{3,5}\\:");
|
||||
|
||||
/**
|
||||
* URL of the context configuration file for this application, if any.
|
||||
*/
|
||||
protected String config = null;
|
||||
|
||||
public String getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public void setConfig(String config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* URL of the server local web application archive (WAR) file to be
|
||||
* deployed.
|
||||
*/
|
||||
protected String localWar = null;
|
||||
|
||||
public String getLocalWar() {
|
||||
return this.localWar;
|
||||
}
|
||||
|
||||
public void setLocalWar(String localWar) {
|
||||
this.localWar = localWar;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tag to associate with this to be deployed webapp.
|
||||
*/
|
||||
protected String tag = null;
|
||||
|
||||
public String getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update existing webapps.
|
||||
*/
|
||||
protected boolean update = false;
|
||||
|
||||
public boolean getUpdate() {
|
||||
return this.update;
|
||||
}
|
||||
|
||||
public void setUpdate(boolean update) {
|
||||
this.update = update;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* URL of the web application archive (WAR) file to be deployed.
|
||||
*/
|
||||
protected String war = null;
|
||||
|
||||
public String getWar() {
|
||||
return this.war;
|
||||
}
|
||||
|
||||
public void setWar(String war) {
|
||||
this.war = war;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
super.execute();
|
||||
if (path == null) {
|
||||
throw new BuildException("Must specify 'path' attribute");
|
||||
}
|
||||
if ((war == null) && (localWar == null) && (config == null) && (tag == null)) {
|
||||
throw new BuildException(
|
||||
"Must specify either 'war', 'localWar', 'config', or 'tag' attribute");
|
||||
}
|
||||
// Building an input stream on the WAR to upload, if any
|
||||
BufferedInputStream stream = null;
|
||||
String contentType = null;
|
||||
long contentLength = -1;
|
||||
if (war != null) {
|
||||
if (PROTOCOL_PATTERN.matcher(war).lookingAt()) {
|
||||
try {
|
||||
URL url = new URL(war);
|
||||
URLConnection conn = url.openConnection();
|
||||
contentLength = conn.getContentLengthLong();
|
||||
stream = new BufferedInputStream(conn.getInputStream(), 1024);
|
||||
} catch (IOException e) {
|
||||
throw new BuildException(e);
|
||||
}
|
||||
} else {
|
||||
FileInputStream fsInput = null;
|
||||
try {
|
||||
fsInput = new FileInputStream(war);
|
||||
contentLength = fsInput.getChannel().size();
|
||||
stream = new BufferedInputStream(fsInput, 1024);
|
||||
} catch (IOException e) {
|
||||
if (fsInput != null) {
|
||||
try {
|
||||
fsInput.close();
|
||||
} catch (IOException ioe) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
// Building URL
|
||||
StringBuilder sb = createQueryString("/deploy");
|
||||
try {
|
||||
if ((war == null) && (config != null)) {
|
||||
sb.append("&config=");
|
||||
sb.append(URLEncoder.encode(config, getCharset()));
|
||||
}
|
||||
if ((war == null) && (localWar != null)) {
|
||||
sb.append("&war=");
|
||||
sb.append(URLEncoder.encode(localWar, getCharset()));
|
||||
}
|
||||
if (update) {
|
||||
sb.append("&update=true");
|
||||
}
|
||||
if (tag != null) {
|
||||
sb.append("&tag=");
|
||||
sb.append(URLEncoder.encode(tag, getCharset()));
|
||||
}
|
||||
execute(sb.toString(), stream, contentType, contentLength);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new BuildException("Invalid 'charset' attribute: " + getCharset());
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ioe) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
java/org/apache/catalina/ant/FindLeaksTask.java
Normal file
61
java/org/apache/catalina/ant/FindLeaksTask.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/findleaks</code> command, supported by
|
||||
* the Tomcat manager application.
|
||||
*/
|
||||
public class FindLeaksTask extends AbstractCatalinaTask {
|
||||
|
||||
private boolean statusLine = true;
|
||||
|
||||
/**
|
||||
* Sets the statusLine parameter that controls if the response includes a
|
||||
* status line or not.
|
||||
*
|
||||
* @param statusLine <code>true</code> if the status line should be included
|
||||
*/
|
||||
public void setStatusLine(boolean statusLine) {
|
||||
this.statusLine = statusLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the statusLine parameter that controls if the response includes a
|
||||
* status line or not.
|
||||
*
|
||||
* @return <code>true</code> if the status line should be included,
|
||||
* otherwise <code>false</code>
|
||||
*/
|
||||
public boolean getStatusLine() {
|
||||
return statusLine;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
super.execute();
|
||||
execute("/findleaks?statusLine=" + Boolean.toString(statusLine));
|
||||
}
|
||||
}
|
||||
416
java/org/apache/catalina/ant/JKStatusUpdateTask.java
Normal file
416
java/org/apache/catalina/ant/JKStatusUpdateTask.java
Normal file
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/status</code> command, supported by the
|
||||
* mod_jk status (1.2.9) application.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.9
|
||||
*/
|
||||
public class JKStatusUpdateTask extends AbstractCatalinaTask {
|
||||
|
||||
private String worker = "lb";
|
||||
|
||||
private String workerType = "lb";
|
||||
|
||||
private int internalid = 0;
|
||||
|
||||
private Integer lbRetries;
|
||||
|
||||
private Integer lbRecovertime;
|
||||
|
||||
private Boolean lbStickySession = Boolean.TRUE;
|
||||
|
||||
private Boolean lbForceSession = Boolean.FALSE;
|
||||
|
||||
private Integer workerLoadFactor;
|
||||
|
||||
private String workerRedirect;
|
||||
|
||||
private String workerClusterDomain;
|
||||
|
||||
private Boolean workerDisabled = Boolean.FALSE;
|
||||
|
||||
private Boolean workerStopped = Boolean.FALSE;
|
||||
|
||||
private boolean isLBMode = true;
|
||||
|
||||
private String workerLb;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JKStatusUpdateTask() {
|
||||
super();
|
||||
setUrl("http://localhost/status");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the internalid.
|
||||
*/
|
||||
public int getInternalid() {
|
||||
return internalid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param internalid
|
||||
* The internalid to set.
|
||||
*/
|
||||
public void setInternalid(int internalid) {
|
||||
this.internalid = internalid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the lbForceSession.
|
||||
*/
|
||||
public Boolean getLbForceSession() {
|
||||
return lbForceSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lbForceSession
|
||||
* The lbForceSession to set.
|
||||
*/
|
||||
public void setLbForceSession(Boolean lbForceSession) {
|
||||
this.lbForceSession = lbForceSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the lbRecovertime.
|
||||
*/
|
||||
public Integer getLbRecovertime() {
|
||||
return lbRecovertime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lbRecovertime
|
||||
* The lbRecovertime to set.
|
||||
*/
|
||||
public void setLbRecovertime(Integer lbRecovertime) {
|
||||
this.lbRecovertime = lbRecovertime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the lbRetries.
|
||||
*/
|
||||
public Integer getLbRetries() {
|
||||
return lbRetries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lbRetries
|
||||
* The lbRetries to set.
|
||||
*/
|
||||
public void setLbRetries(Integer lbRetries) {
|
||||
this.lbRetries = lbRetries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the lbStickySession.
|
||||
*/
|
||||
public Boolean getLbStickySession() {
|
||||
return lbStickySession;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lbStickySession
|
||||
* The lbStickySession to set.
|
||||
*/
|
||||
public void setLbStickySession(Boolean lbStickySession) {
|
||||
this.lbStickySession = lbStickySession;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the worker.
|
||||
*/
|
||||
public String getWorker() {
|
||||
return worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worker
|
||||
* The worker to set.
|
||||
*/
|
||||
public void setWorker(String worker) {
|
||||
this.worker = worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the workerType.
|
||||
*/
|
||||
public String getWorkerType() {
|
||||
return workerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workerType
|
||||
* The workerType to set.
|
||||
*/
|
||||
public void setWorkerType(String workerType) {
|
||||
this.workerType = workerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the workerLb.
|
||||
*/
|
||||
public String getWorkerLb() {
|
||||
return workerLb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workerLb
|
||||
* The workerLb to set.
|
||||
*/
|
||||
public void setWorkerLb(String workerLb) {
|
||||
this.workerLb = workerLb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the workerClusterDomain.
|
||||
*/
|
||||
public String getWorkerClusterDomain() {
|
||||
return workerClusterDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workerClusterDomain
|
||||
* The workerClusterDomain to set.
|
||||
*/
|
||||
public void setWorkerClusterDomain(String workerClusterDomain) {
|
||||
this.workerClusterDomain = workerClusterDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the workerDisabled.
|
||||
*/
|
||||
public Boolean getWorkerDisabled() {
|
||||
return workerDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workerDisabled
|
||||
* The workerDisabled to set.
|
||||
*/
|
||||
public void setWorkerDisabled(Boolean workerDisabled) {
|
||||
this.workerDisabled = workerDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the workerStopped.
|
||||
*/
|
||||
public Boolean getWorkerStopped() {
|
||||
return workerStopped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workerStopped The workerStopped to set.
|
||||
*/
|
||||
public void setWorkerStopped(Boolean workerStopped) {
|
||||
this.workerStopped = workerStopped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the workerLoadFactor.
|
||||
*/
|
||||
public Integer getWorkerLoadFactor() {
|
||||
return workerLoadFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workerLoadFactor
|
||||
* The workerLoadFactor to set.
|
||||
*/
|
||||
public void setWorkerLoadFactor(Integer workerLoadFactor) {
|
||||
this.workerLoadFactor = workerLoadFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the workerRedirect.
|
||||
*/
|
||||
public String getWorkerRedirect() {
|
||||
return workerRedirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workerRedirect
|
||||
* The workerRedirect to set.
|
||||
*/
|
||||
public void setWorkerRedirect(String workerRedirect) {
|
||||
this.workerRedirect = workerRedirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException
|
||||
* if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
checkParameter();
|
||||
StringBuilder sb = createLink();
|
||||
execute(sb.toString(), null, null, -1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create JkStatus link
|
||||
* <ul>
|
||||
* <li><b>load balance example:
|
||||
* </b>http://localhost/status?cmd=update&mime=txt&w=lb&lf=false&ls=true</li>
|
||||
* <li><b>worker example:
|
||||
* </b>http://localhost/status?cmd=update&mime=txt&w=node1&l=lb&wf=1&wd=false&ws=false
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @return create jkstatus link
|
||||
*/
|
||||
private StringBuilder createLink() {
|
||||
// Building URL
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try {
|
||||
sb.append("?cmd=update&mime=txt");
|
||||
sb.append("&w=");
|
||||
sb.append(URLEncoder.encode(worker, getCharset()));
|
||||
|
||||
if (isLBMode) {
|
||||
//http://localhost/status?cmd=update&mime=txt&w=lb&lf=false&ls=true
|
||||
if ((lbRetries != null)) { // > 0
|
||||
sb.append("&lr=");
|
||||
sb.append(lbRetries);
|
||||
}
|
||||
if ((lbRecovertime != null)) { // > 59
|
||||
sb.append("<=");
|
||||
sb.append(lbRecovertime);
|
||||
}
|
||||
if ((lbStickySession != null)) {
|
||||
sb.append("&ls=");
|
||||
sb.append(lbStickySession);
|
||||
}
|
||||
if ((lbForceSession != null)) {
|
||||
sb.append("&lf=");
|
||||
sb.append(lbForceSession);
|
||||
}
|
||||
} else {
|
||||
//http://localhost/status?cmd=update&mime=txt&w=node1&l=lb&wf=1&wd=false&ws=false
|
||||
if ((workerLb != null)) { // must be configured
|
||||
sb.append("&l=");
|
||||
sb.append(URLEncoder.encode(workerLb, getCharset()));
|
||||
}
|
||||
if ((workerLoadFactor != null)) { // >= 1
|
||||
sb.append("&wf=");
|
||||
sb.append(workerLoadFactor);
|
||||
}
|
||||
if ((workerDisabled != null)) {
|
||||
sb.append("&wd=");
|
||||
sb.append(workerDisabled);
|
||||
}
|
||||
if ((workerStopped != null)) {
|
||||
sb.append("&ws=");
|
||||
sb.append(workerStopped);
|
||||
}
|
||||
if ((workerRedirect != null)) { // other worker conrecte lb's
|
||||
sb.append("&wr=");
|
||||
}
|
||||
if ((workerClusterDomain != null)) {
|
||||
sb.append("&wc=");
|
||||
sb.append(URLEncoder.encode(workerClusterDomain,
|
||||
getCharset()));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new BuildException("Invalid 'charset' attribute: "
|
||||
+ getCharset());
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
/**
|
||||
* check correct lb and worker parameter
|
||||
*/
|
||||
protected void checkParameter() {
|
||||
if (worker == null) {
|
||||
throw new BuildException("Must specify 'worker' attribute");
|
||||
}
|
||||
if (workerType == null) {
|
||||
throw new BuildException("Must specify 'workerType' attribute");
|
||||
}
|
||||
if ("lb".equals(workerType)) {
|
||||
if (lbRecovertime == null && lbRetries == null) {
|
||||
throw new BuildException(
|
||||
"Must specify at a lb worker either 'lbRecovertime' or"
|
||||
+ "'lbRetries' attribute");
|
||||
}
|
||||
if (lbStickySession == null || lbForceSession == null) {
|
||||
throw new BuildException("Must specify at a lb worker either"
|
||||
+ "'lbStickySession' and 'lbForceSession' attribute");
|
||||
}
|
||||
if (null != lbRecovertime && 60 < lbRecovertime.intValue()) {
|
||||
throw new BuildException(
|
||||
"The 'lbRecovertime' must be greater than 59");
|
||||
}
|
||||
if (null != lbRetries && 1 < lbRetries.intValue()) {
|
||||
throw new BuildException(
|
||||
"The 'lbRetries' must be greater than 1");
|
||||
}
|
||||
isLBMode = true;
|
||||
} else if ("worker".equals(workerType)) {
|
||||
if (workerDisabled == null) {
|
||||
throw new BuildException(
|
||||
"Must specify at a node worker 'workerDisabled' attribute");
|
||||
}
|
||||
if (workerStopped == null) {
|
||||
throw new BuildException(
|
||||
"Must specify at a node worker 'workerStopped' attribute");
|
||||
}
|
||||
if (workerLoadFactor == null ) {
|
||||
throw new BuildException(
|
||||
"Must specify at a node worker 'workerLoadFactor' attribute");
|
||||
}
|
||||
if (workerClusterDomain == null) {
|
||||
throw new BuildException(
|
||||
"Must specify at a node worker 'workerClusterDomain' attribute");
|
||||
}
|
||||
if (workerRedirect == null) {
|
||||
throw new BuildException(
|
||||
"Must specify at a node worker 'workerRedirect' attribute");
|
||||
}
|
||||
if (workerLb == null) {
|
||||
throw new BuildException("Must specify 'workerLb' attribute");
|
||||
}
|
||||
if (workerLoadFactor.intValue() < 1) {
|
||||
throw new BuildException(
|
||||
"The 'workerLoadFactor' must be greater or equal 1");
|
||||
}
|
||||
isLBMode = false;
|
||||
} else {
|
||||
throw new BuildException(
|
||||
"Only 'lb' and 'worker' supported as workerType attribute");
|
||||
}
|
||||
}
|
||||
}
|
||||
104
java/org/apache/catalina/ant/JMXGetTask.java
Normal file
104
java/org/apache/catalina/ant/JMXGetTask.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the JMX Get command (<code>/jmxproxy/?get</code>)
|
||||
* supported by the Tomcat manager application.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
*/
|
||||
public class JMXGetTask extends AbstractCatalinaTask {
|
||||
|
||||
// Properties
|
||||
|
||||
/**
|
||||
* The full bean name
|
||||
*/
|
||||
protected String bean = null;
|
||||
|
||||
/**
|
||||
* The attribute you wish to alter
|
||||
*/
|
||||
protected String attribute = null;
|
||||
|
||||
// Public Methods
|
||||
|
||||
/**
|
||||
* Get method for the bean name
|
||||
* @return Bean name
|
||||
*/
|
||||
public String getBean () {
|
||||
return this.bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method for the bean name
|
||||
* @param bean Bean name
|
||||
*/
|
||||
public void setBean (String bean) {
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get method for the attribute name
|
||||
* @return Attribute name
|
||||
*/
|
||||
public String getAttribute () {
|
||||
return this.attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method for the attribute name
|
||||
* @param attribute Attribute name
|
||||
*/
|
||||
public void setAttribute (String attribute) {
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
super.execute();
|
||||
if (bean == null || attribute == null) {
|
||||
throw new BuildException
|
||||
("Must specify 'bean' and 'attribute' attributes");
|
||||
}
|
||||
log("Getting attribute " + attribute +
|
||||
" in bean " + bean );
|
||||
try {
|
||||
execute("/jmxproxy/?get=" + URLEncoder.encode(bean, getCharset())
|
||||
+ "&att=" + URLEncoder.encode(attribute, getCharset()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new BuildException
|
||||
("Invalid 'charset' attribute: " + getCharset());
|
||||
}
|
||||
}
|
||||
}
|
||||
91
java/org/apache/catalina/ant/JMXQueryTask.java
Normal file
91
java/org/apache/catalina/ant/JMXQueryTask.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the JMX Query command
|
||||
* (<code>/jmxproxy/?qry</code>) supported by the Tomcat manager application.
|
||||
*
|
||||
* @author Vivek Chopra
|
||||
*/
|
||||
public class JMXQueryTask extends AbstractCatalinaTask {
|
||||
|
||||
// Properties
|
||||
|
||||
/**
|
||||
* The JMX query string
|
||||
* @see #setQuery(String)
|
||||
*/
|
||||
protected String query = null;
|
||||
|
||||
// Public Methods
|
||||
|
||||
/**
|
||||
* Get method for the JMX query string
|
||||
* @return Query string
|
||||
*/
|
||||
public String getQuery () {
|
||||
return this.query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method for the JMX query string.
|
||||
* <p>Examples of query format:</p>
|
||||
* <UL>
|
||||
* <LI>*:*</LI>
|
||||
* <LI>*:type=RequestProcessor,*</LI>
|
||||
* <LI>*:j2eeType=Servlet,*</LI>
|
||||
* <LI>Catalina:type=Environment,resourcetype=Global,name=simpleValue</LI>
|
||||
* </UL>
|
||||
* @param query JMX Query string
|
||||
*/
|
||||
public void setQuery (String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
super.execute();
|
||||
String queryString;
|
||||
if (query == null) {
|
||||
queryString = "";
|
||||
} else {
|
||||
try {
|
||||
queryString = "?qry=" + URLEncoder.encode(query, getCharset());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new BuildException
|
||||
("Invalid 'charset' attribute: " + getCharset());
|
||||
}
|
||||
}
|
||||
log("Query string is " + queryString);
|
||||
execute ("/jmxproxy/" + queryString);
|
||||
}
|
||||
}
|
||||
127
java/org/apache/catalina/ant/JMXSetTask.java
Normal file
127
java/org/apache/catalina/ant/JMXSetTask.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the JMX Set command (<code>/jmxproxy/?set</code>)
|
||||
* supported by the Tomcat manager application.
|
||||
*
|
||||
* @author Vivek Chopra
|
||||
*/
|
||||
public class JMXSetTask extends AbstractCatalinaTask {
|
||||
|
||||
// Properties
|
||||
|
||||
/**
|
||||
* The full bean name
|
||||
*/
|
||||
protected String bean = null;
|
||||
|
||||
/**
|
||||
* The attribute you wish to alter
|
||||
*/
|
||||
protected String attribute = null;
|
||||
|
||||
/**
|
||||
* The new value for the attribute
|
||||
*/
|
||||
protected String value = null;
|
||||
|
||||
// Public Methods
|
||||
|
||||
/**
|
||||
* Get method for the bean name
|
||||
* @return Bean name
|
||||
*/
|
||||
public String getBean () {
|
||||
return this.bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method for the bean name
|
||||
* @param bean Bean name
|
||||
*/
|
||||
public void setBean (String bean) {
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get method for the attribute name
|
||||
* @return Attribute name
|
||||
*/
|
||||
public String getAttribute () {
|
||||
return this.attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method for the attribute name
|
||||
* @param attribute Attribute name
|
||||
*/
|
||||
public void setAttribute (String attribute) {
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get method for the attribute value
|
||||
* @return Attribute value
|
||||
*/
|
||||
public String getValue () {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method for the attribute value.
|
||||
* @param value Attribute value
|
||||
*/
|
||||
public void setValue (String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
super.execute();
|
||||
if (bean == null || attribute == null || value == null) {
|
||||
throw new BuildException
|
||||
("Must specify 'bean', 'attribute' and 'value' attributes");
|
||||
}
|
||||
log("Setting attribute " + attribute +
|
||||
" in bean " + bean +
|
||||
" to " + value);
|
||||
try {
|
||||
execute("/jmxproxy/?set=" + URLEncoder.encode(bean, getCharset())
|
||||
+ "&att=" + URLEncoder.encode(attribute, getCharset())
|
||||
+ "&val=" + URLEncoder.encode(value, getCharset()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new BuildException
|
||||
("Invalid 'charset' attribute: " + getCharset());
|
||||
}
|
||||
}
|
||||
}
|
||||
55
java/org/apache/catalina/ant/ListTask.java
Normal file
55
java/org/apache/catalina/ant/ListTask.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/list</code> command, supported by the
|
||||
* Tomcat manager application.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class ListTask extends AbstractCatalinaTask {
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute("/list");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
49
java/org/apache/catalina/ant/ReloadTask.java
Normal file
49
java/org/apache/catalina/ant/ReloadTask.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/reload</code> command, supported by the
|
||||
* Tomcat manager application.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class ReloadTask extends AbstractCatalinaCommandTask {
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute(createQueryString("/reload").toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
83
java/org/apache/catalina/ant/ResourcesTask.java
Normal file
83
java/org/apache/catalina/ant/ResourcesTask.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/resources</code> command, supported by
|
||||
* the Tomcat manager application.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class ResourcesTask extends AbstractCatalinaTask {
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
|
||||
/**
|
||||
* The fully qualified class name of the resource type being requested
|
||||
* (if any).
|
||||
*/
|
||||
protected String type = null;
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
if (type != null) {
|
||||
try {
|
||||
execute("/resources?type=" +
|
||||
URLEncoder.encode(type, getCharset()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new BuildException
|
||||
("Invalid 'charset' attribute: " + getCharset());
|
||||
}
|
||||
} else {
|
||||
execute("/resources");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
45
java/org/apache/catalina/ant/ServerinfoTask.java
Normal file
45
java/org/apache/catalina/ant/ServerinfoTask.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/serverinfo</code> command
|
||||
* supported by the Tomcat manager application.
|
||||
*
|
||||
* @author Vivek Chopra
|
||||
*/
|
||||
public class ServerinfoTask extends AbstractCatalinaTask {
|
||||
|
||||
// Public Methods
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute("/serverinfo");
|
||||
|
||||
}
|
||||
}
|
||||
67
java/org/apache/catalina/ant/SessionsTask.java
Normal file
67
java/org/apache/catalina/ant/SessionsTask.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/sessions</code> command
|
||||
* supported by the Tomcat manager application.
|
||||
*
|
||||
* @author Vivek Chopra
|
||||
*/
|
||||
public class SessionsTask extends AbstractCatalinaCommandTask {
|
||||
|
||||
|
||||
protected String idle = null;
|
||||
|
||||
public String getIdle() {
|
||||
return this.idle;
|
||||
}
|
||||
|
||||
public void setIdle(String idle) {
|
||||
this.idle = idle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuilder createQueryString(String command) {
|
||||
StringBuilder buffer = super.createQueryString(command);
|
||||
if (path != null && idle != null) {
|
||||
buffer.append("&idle=");
|
||||
buffer.append(this.idle);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute(createQueryString("/sessions").toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
java/org/apache/catalina/ant/SslConnectorCiphersTask.java
Normal file
47
java/org/apache/catalina/ant/SslConnectorCiphersTask.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/sslConnectorCiphers</code> command
|
||||
* supported by the Tomcat manager application.
|
||||
*
|
||||
*/
|
||||
public class SslConnectorCiphersTask extends AbstractCatalinaTask {
|
||||
|
||||
// Public Methods
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute("/sslConnectorCiphers");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
48
java/org/apache/catalina/ant/StartTask.java
Normal file
48
java/org/apache/catalina/ant/StartTask.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/start</code> command, supported by the
|
||||
* Tomcat manager application.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class StartTask extends AbstractCatalinaCommandTask {
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute(createQueryString("/start").toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
48
java/org/apache/catalina/ant/StopTask.java
Normal file
48
java/org/apache/catalina/ant/StopTask.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/stop</code> command, supported by the
|
||||
* Tomcat manager application.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class StopTask extends AbstractCatalinaCommandTask {
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute(createQueryString("/stop").toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
47
java/org/apache/catalina/ant/ThreaddumpTask.java
Normal file
47
java/org/apache/catalina/ant/ThreaddumpTask.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/threaddump</code> command
|
||||
* supported by the Tomcat manager application.
|
||||
*
|
||||
*/
|
||||
public class ThreaddumpTask extends AbstractCatalinaTask {
|
||||
|
||||
// Public Methods
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute("/threaddump");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
48
java/org/apache/catalina/ant/UndeployTask.java
Normal file
48
java/org/apache/catalina/ant/UndeployTask.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/undeploy</code> command, supported by
|
||||
* the Tomcat manager application.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class UndeployTask extends AbstractCatalinaCommandTask {
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute(createQueryString("/undeploy").toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
113
java/org/apache/catalina/ant/ValidatorTask.java
Normal file
113
java/org/apache/catalina/ant/ValidatorTask.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.catalina.Globals;
|
||||
import org.apache.tomcat.util.descriptor.DigesterFactory;
|
||||
import org.apache.tomcat.util.digester.Digester;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
/**
|
||||
* Task for validating a web application deployment descriptor, using XML
|
||||
* schema validation.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
* @since 5.0
|
||||
*/
|
||||
public class ValidatorTask extends BaseRedirectorHelperTask {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
|
||||
/**
|
||||
* The path to the webapp directory.
|
||||
*/
|
||||
protected String path = null;
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Execute the specified command. This logic only performs the common
|
||||
* attribute validation required by all subclasses; it does not perform
|
||||
* any functional logic directly.
|
||||
*
|
||||
* @exception BuildException if a validation error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
if (path == null) {
|
||||
throw new BuildException("Must specify 'path'");
|
||||
}
|
||||
|
||||
File file = new File(path, "WEB-INF/web.xml");
|
||||
if (!file.canRead()) {
|
||||
throw new BuildException("Cannot find web.xml");
|
||||
}
|
||||
|
||||
// Commons-logging likes having the context classloader set
|
||||
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader
|
||||
(ValidatorTask.class.getClassLoader());
|
||||
|
||||
// Called through trusted manager interface. If running under a
|
||||
// SecurityManager assume that untrusted applications may be deployed.
|
||||
Digester digester = DigesterFactory.newDigester(
|
||||
true, true, null, Globals.IS_SECURITY_ENABLED);
|
||||
try (InputStream stream = new BufferedInputStream(new FileInputStream(file.getCanonicalFile()))) {
|
||||
InputSource is = new InputSource(file.toURI().toURL().toExternalForm());
|
||||
is.setByteStream(stream);
|
||||
digester.parse(is);
|
||||
handleOutput("web.xml validated");
|
||||
} catch (Exception e) {
|
||||
if (isFailOnError()) {
|
||||
throw new BuildException("Validation failure", e);
|
||||
} else {
|
||||
handleErrorOutput("Validation failure: " + e);
|
||||
}
|
||||
} finally {
|
||||
Thread.currentThread().setContextClassLoader(oldCL);
|
||||
closeRedirector();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
47
java/org/apache/catalina/ant/VminfoTask.java
Normal file
47
java/org/apache/catalina/ant/VminfoTask.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant;
|
||||
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Ant task that implements the <code>/vminfo</code> command
|
||||
* supported by the Tomcat manager application.
|
||||
*
|
||||
*/
|
||||
public class VminfoTask extends AbstractCatalinaTask {
|
||||
|
||||
// Public Methods
|
||||
|
||||
/**
|
||||
* Execute the requested operation.
|
||||
*
|
||||
* @exception BuildException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
super.execute();
|
||||
execute("/vminfo");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
81
java/org/apache/catalina/ant/antlib.xml
Normal file
81
java/org/apache/catalina/ant/antlib.xml
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<antlib>
|
||||
<!-- Pure Catalina tasks -->
|
||||
<typedef
|
||||
name="list"
|
||||
classname="org.apache.catalina.ant.ListTask" />
|
||||
<typedef
|
||||
name="deploy"
|
||||
classname="org.apache.catalina.ant.DeployTask" />
|
||||
<typedef
|
||||
name="start"
|
||||
classname="org.apache.catalina.ant.StartTask" />
|
||||
<typedef
|
||||
name="reload"
|
||||
classname="org.apache.catalina.ant.ReloadTask" />
|
||||
<typedef
|
||||
name="stop"
|
||||
classname="org.apache.catalina.ant.StopTask" />
|
||||
<typedef
|
||||
name="undeploy"
|
||||
classname="org.apache.catalina.ant.UndeployTask" />
|
||||
<typedef
|
||||
name="resources"
|
||||
classname="org.apache.catalina.ant.ResourcesTask" />
|
||||
<typedef
|
||||
name="sessions"
|
||||
classname="org.apache.catalina.ant.SessionsTask" />
|
||||
<typedef
|
||||
name="findleaks"
|
||||
classname="org.apache.catalina.ant.FindLeaksTask" />
|
||||
<typedef
|
||||
name="vminfo"
|
||||
classname="org.apache.catalina.ant.VminfoTask" />
|
||||
<typedef
|
||||
name="threaddump"
|
||||
classname="org.apache.catalina.ant.ThreaddumpTask" />
|
||||
<typedef
|
||||
name="sslConnectorCiphers"
|
||||
classname="org.apache.catalina.ant.SslConnectorCiphersTask" />
|
||||
<!-- Jk Task -->
|
||||
<typedef
|
||||
name="jkupdate"
|
||||
classname="org.apache.catalina.ant.JKStatusUpdateTask" />
|
||||
<!-- Manager JMX -->
|
||||
<typedef
|
||||
name="jmxManagerSet"
|
||||
classname="org.apache.catalina.ant.JMXSetTask" />
|
||||
<typedef
|
||||
name="jmxManagerGet"
|
||||
classname="org.apache.catalina.ant.JMXGetTask" />
|
||||
<typedef
|
||||
name="jmxManagerQuery"
|
||||
classname="org.apache.catalina.ant.JMXQueryTask" />
|
||||
<!-- Other -->
|
||||
<!-- These tasks are deliberately omitted here,
|
||||
because they depend on other Tomcat components besides catalina-ant.jar
|
||||
and thus are hard to use with antlib.
|
||||
<typedef
|
||||
name="validator"
|
||||
classname="org.apache.catalina.ant.ValidatorTask" />
|
||||
<typedef
|
||||
name="jasper"
|
||||
classname="org.apache.jasper.JspC" />
|
||||
-->
|
||||
</antlib>
|
||||
40
java/org/apache/catalina/ant/catalina.tasks
Normal file
40
java/org/apache/catalina/ant/catalina.tasks
Normal file
@@ -0,0 +1,40 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Pure catalina tasks
|
||||
list=org.apache.catalina.ant.ListTask
|
||||
deploy=org.apache.catalina.ant.DeployTask
|
||||
start=org.apache.catalina.ant.StartTask
|
||||
reload=org.apache.catalina.ant.ReloadTask
|
||||
stop=org.apache.catalina.ant.StopTask
|
||||
undeploy=org.apache.catalina.ant.UndeployTask
|
||||
resources=org.apache.catalina.ant.ResourcesTask
|
||||
sessions=org.apache.catalina.ant.SessionsTask
|
||||
validator=org.apache.catalina.ant.ValidatorTask
|
||||
findleaks=org.apache.catalina.ant.FindLeaksTask
|
||||
vminfo=org.apache.catalina.ant.VminfoTask
|
||||
threaddump=org.apache.catalina.ant.ThreaddumpTask
|
||||
sslConnectorCiphers=org.apache.catalina.ant.SslConnectorCiphersTask
|
||||
|
||||
#Jk Task
|
||||
jkupdate=org.apache.catalina.ant.JKStatusUpdateTask
|
||||
|
||||
# Manager JMX
|
||||
jmxManagerSet=org.apache.catalina.ant.JMXSetTask
|
||||
jmxManagerGet=org.apache.catalina.ant.JMXGetTask
|
||||
jmxManagerQuery=org.apache.catalina.ant.JMXQueryTask
|
||||
|
||||
# Jasper tasks
|
||||
jasper=org.apache.jasper.JspC
|
||||
44
java/org/apache/catalina/ant/jmx/Arg.java
Normal file
44
java/org/apache/catalina/ant/jmx/Arg.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class Arg {
|
||||
|
||||
private String type;
|
||||
private String value;
|
||||
|
||||
public void setType( String type) {
|
||||
this.type=type;
|
||||
}
|
||||
|
||||
public void setValue( String value ) {
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
229
java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
Normal file
229
java/org/apache/catalina/ant/jmx/JMXAccessorCondition.java
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* <b>Definition</b>:
|
||||
* <pre>
|
||||
* <path id="catalina_ant">
|
||||
* <fileset dir="${catalina.home}/server/lib">
|
||||
* <include name="catalina-ant.jar"/>
|
||||
* </fileset>
|
||||
* </path>
|
||||
*
|
||||
* <typedef
|
||||
* name="jmxCondition"
|
||||
* classname="org.apache.catalina.ant.jmx.JMXAccessorCondition"
|
||||
* classpathref="catalina_ant"/>
|
||||
* <taskdef
|
||||
* name="jmxOpen"
|
||||
* classname="org.apache.catalina.ant.jmx.JMXAccessorTask"
|
||||
* classpathref="catalina_ant"/>
|
||||
* </pre>
|
||||
*
|
||||
* <b>Usage</b>: Wait for start backup node
|
||||
* <pre>
|
||||
* <target name="wait">
|
||||
* <jmxOpen
|
||||
* host="${jmx.host}" port="${jmx.port}" username="${jmx.username}" password="${jmx.password}" />
|
||||
* <waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" >
|
||||
* <and>
|
||||
* <socket server="${server.name}" port="${server.port}"/>
|
||||
* <http url="${url}"/>
|
||||
* <jmxCondition
|
||||
* name="Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025"
|
||||
* operation="=="
|
||||
* attribute="connected" value="true"
|
||||
* />
|
||||
* <jmxCondition
|
||||
* operation="&lt;"
|
||||
* name="Catalina:j2eeType=WebModule,name=//${tomcat.application.host}${tomcat.application.path},J2EEApplication=none,J2EEServer=none"
|
||||
* attribute="startupTime" value="250"
|
||||
* />
|
||||
* </and>
|
||||
* </waitfor>
|
||||
* <fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" />
|
||||
* <echo message="Server ${url} alive" />
|
||||
* </target>
|
||||
*
|
||||
* </pre>
|
||||
* Allowed operation between jmx attribute and reference value:
|
||||
* <ul>
|
||||
* <li>== equals</li>
|
||||
* <li>!= not equals</li>
|
||||
* <li>> greater than (&gt;)</li>
|
||||
* <li>>= greater than or equals (&gt;=)</li>
|
||||
* <li>< lesser than (&lt;)</li>
|
||||
* <li><= lesser than or equals (&lt;=)</li>
|
||||
* </ul>
|
||||
* <b>NOTE</b>: For numeric expressions the type must be set and use xml entities as operations.<br>
|
||||
* As type we currently support <em>long</em> and <em>double</em>.
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class JMXAccessorCondition extends JMXAccessorConditionBase {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
private String operation = "==" ;
|
||||
private String type = "long" ;
|
||||
private String unlessCondition;
|
||||
private String ifCondition;
|
||||
|
||||
|
||||
// ----------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* @return Returns the operation.
|
||||
*/
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
/**
|
||||
* @param operation The operation to set.
|
||||
*/
|
||||
public void setOperation(String operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the type.
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* @param type The type to set.
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ifCondition.
|
||||
*/
|
||||
public String getIf() {
|
||||
return ifCondition;
|
||||
}
|
||||
/**
|
||||
* Only execute if a property of the given name exists in the current project.
|
||||
* @param c property name
|
||||
*/
|
||||
public void setIf(String c) {
|
||||
ifCondition = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the unlessCondition.
|
||||
*/
|
||||
public String getUnless() {
|
||||
return unlessCondition;
|
||||
}
|
||||
/**
|
||||
* Only execute if a property of the given name does not
|
||||
* exist in the current project.
|
||||
* @param c property name
|
||||
*/
|
||||
public void setUnless(String c) {
|
||||
unlessCondition = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* test the if condition
|
||||
* @return true if there is no if condition, or the named property exists
|
||||
*/
|
||||
protected boolean testIfCondition() {
|
||||
if (ifCondition == null || "".equals(ifCondition)) {
|
||||
return true;
|
||||
}
|
||||
return getProject().getProperty(ifCondition) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* test the unless condition
|
||||
* @return true if there is no unless condition,
|
||||
* or there is a named property but it doesn't exist
|
||||
*/
|
||||
protected boolean testUnlessCondition() {
|
||||
if (unlessCondition == null || "".equals(unlessCondition)) {
|
||||
return true;
|
||||
}
|
||||
return getProject().getProperty(unlessCondition) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method evaluates the condition
|
||||
* It support for operation ">,>=,<,<=" the types <code>long</code> and <code>double</code>.
|
||||
* @return expression <em>jmxValue</em> <em>operation</em> <em>value</em>
|
||||
*/
|
||||
@Override
|
||||
public boolean eval() {
|
||||
String value = getValue();
|
||||
if (operation == null) {
|
||||
throw new BuildException("operation attribute is not set");
|
||||
}
|
||||
if (value == null) {
|
||||
throw new BuildException("value attribute is not set");
|
||||
}
|
||||
if ((getName() == null || getAttribute() == null)) {
|
||||
throw new BuildException(
|
||||
"Must specify an MBean name and attribute for condition");
|
||||
}
|
||||
if (testIfCondition() && testUnlessCondition()) {
|
||||
String jmxValue = accessJMXValue();
|
||||
if (jmxValue != null) {
|
||||
String op = getOperation();
|
||||
if ("==".equals(op)) {
|
||||
return jmxValue.equals(value);
|
||||
} else if ("!=".equals(op)) {
|
||||
return !jmxValue.equals(value);
|
||||
} else {
|
||||
if ("long".equals(type)) {
|
||||
long jvalue = Long.parseLong(jmxValue);
|
||||
long lvalue = Long.parseLong(value);
|
||||
if (">".equals(op)) {
|
||||
return jvalue > lvalue;
|
||||
} else if (">=".equals(op)) {
|
||||
return jvalue >= lvalue;
|
||||
} else if ("<".equals(op)) {
|
||||
return jvalue < lvalue;
|
||||
} else if ("<=".equals(op)) {
|
||||
return jvalue <= lvalue;
|
||||
}
|
||||
} else if ("double".equals(type)) {
|
||||
double jvalue = Double.parseDouble(jmxValue);
|
||||
double dvalue = Double.parseDouble(value);
|
||||
if (">".equals(op)) {
|
||||
return jvalue > dvalue;
|
||||
} else if (">=".equals(op)) {
|
||||
return jvalue >= dvalue;
|
||||
} else if ("<".equals(op)) {
|
||||
return jvalue < dvalue;
|
||||
} else if ("<=".equals(op)) {
|
||||
return jvalue <= dvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
181
java/org/apache/catalina/ant/jmx/JMXAccessorConditionBase.java
Normal file
181
java/org/apache/catalina/ant/jmx/JMXAccessorConditionBase.java
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.tools.ant.ProjectComponent;
|
||||
import org.apache.tools.ant.taskdefs.condition.Condition;
|
||||
|
||||
public abstract class JMXAccessorConditionBase extends ProjectComponent implements Condition {
|
||||
|
||||
private String url = null;
|
||||
private String host = "localhost";
|
||||
private String port = "8050";
|
||||
private String password = null;
|
||||
private String username = null;
|
||||
private String name = null;
|
||||
private String attribute;
|
||||
private String value;
|
||||
private String ref = "jmx.server" ;
|
||||
|
||||
/**
|
||||
* @return Returns the attribute.
|
||||
*/
|
||||
public String getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
/**
|
||||
* @param attribute The attribute to set.
|
||||
*/
|
||||
public void setAttribute(String attribute) {
|
||||
this.attribute = attribute;
|
||||
}
|
||||
/**
|
||||
* @return Returns the host.
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
/**
|
||||
* @param host The host to set.
|
||||
*/
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @param objectName The name to set.
|
||||
*/
|
||||
public void setName(String objectName) {
|
||||
this.name = objectName;
|
||||
}
|
||||
/**
|
||||
* @return Returns the password.
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
/**
|
||||
* @param password The password to set.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
/**
|
||||
* @return Returns the port.
|
||||
*/
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
/**
|
||||
* @param port The port to set.
|
||||
*/
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
/**
|
||||
* @return Returns the url.
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
* @param url The url to set.
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
/**
|
||||
* @return Returns the username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* @param username The username to set.
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
/**
|
||||
* @return Returns the value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
// The setter for the "value" attribute
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ref.
|
||||
*/
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
/**
|
||||
* @param refId The ref to set.
|
||||
*/
|
||||
public void setRef(String refId) {
|
||||
this.ref = refId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get JMXConnection (default look at <em>jmx.server</em> project reference
|
||||
* from jmxOpen Task).
|
||||
*
|
||||
* @return active JMXConnection
|
||||
* @throws MalformedURLException Invalid URL for JMX server
|
||||
* @throws IOException Connection error
|
||||
*/
|
||||
protected MBeanServerConnection getJMXConnection()
|
||||
throws MalformedURLException, IOException {
|
||||
return JMXAccessorTask.accessJMXConnection(
|
||||
getProject(),
|
||||
getUrl(), getHost(),
|
||||
getPort(), getUsername(), getPassword(), ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value from MBeans attribute.
|
||||
*
|
||||
* @return The value
|
||||
*/
|
||||
protected String accessJMXValue() {
|
||||
try {
|
||||
Object result = getJMXConnection().getAttribute(
|
||||
new ObjectName(name), attribute);
|
||||
if(result != null)
|
||||
return result.toString();
|
||||
} catch (Exception e) {
|
||||
// ignore access or connection open errors
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
179
java/org/apache/catalina/ant/jmx/JMXAccessorCreateTask.java
Normal file
179
java/org/apache/catalina/ant/jmx/JMXAccessorCreateTask.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* Create new MBean at <em>JMX</em> JSR 160 MBeans Server.
|
||||
* <ul>
|
||||
* <li>Create Mbeans</li>
|
||||
* <li>Create Mbeans with parameter</li>
|
||||
* <li>Create remote Mbeans with different classloader</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Examples:
|
||||
* <br>
|
||||
* create a new Mbean at jmx.server connection
|
||||
* </p>
|
||||
* <pre>
|
||||
* <jmx:create
|
||||
* ref="jmx.server"
|
||||
* name="Catalina:type=MBeanFactory"
|
||||
* className="org.apache.catalina.mbeans.MBeanFactory"
|
||||
* classLoader="Catalina:type=ServerClassLoader,name=server">
|
||||
* <Arg value="org.apache.catalina.mbeans.MBeanFactory" />
|
||||
* </jmxCreate/>
|
||||
* </pre>
|
||||
* <p>
|
||||
* <b>WARNING</b>Not all Tomcat MBeans can create remotely and autoregister by its parents!
|
||||
* Please, use the MBeanFactory operation to generate valves and realms.
|
||||
* </p>
|
||||
* <p>
|
||||
* First call to a remote MBeanserver save the JMXConnection a reference <em>jmx.server</em>
|
||||
* </p>
|
||||
* These tasks require Ant 1.6 or later interface.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.12
|
||||
*/
|
||||
public class JMXAccessorCreateTask extends JMXAccessorTask {
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
private String className;
|
||||
private String classLoader;
|
||||
private List<Arg> args=new ArrayList<>();
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* @return Returns the classLoader.
|
||||
*/
|
||||
public String getClassLoader() {
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param classLoaderName The classLoader to set.
|
||||
*/
|
||||
public void setClassLoader(String classLoaderName) {
|
||||
this.classLoader = classLoaderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the className.
|
||||
*/
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className The className to set.
|
||||
*/
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public void addArg(Arg arg ) {
|
||||
args.add(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the args.
|
||||
*/
|
||||
public List<Arg> getArgs() {
|
||||
return args;
|
||||
}
|
||||
/**
|
||||
* @param args The args to set.
|
||||
*/
|
||||
public void setArgs(List<Arg> args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ protected Methods
|
||||
|
||||
@Override
|
||||
public String jmxExecute(MBeanServerConnection jmxServerConnection)
|
||||
throws Exception {
|
||||
|
||||
if (getName() == null) {
|
||||
throw new BuildException("Must specify a 'name'");
|
||||
}
|
||||
if ((className == null)) {
|
||||
throw new BuildException(
|
||||
"Must specify a 'className' for get");
|
||||
}
|
||||
jmxCreate(jmxServerConnection, getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new MBean from ClassLoader identified by an ObjectName.
|
||||
*
|
||||
* @param jmxServerConnection Connection to the JMX server
|
||||
* @param name MBean name
|
||||
* @throws Exception Error creating MBean
|
||||
*/
|
||||
protected void jmxCreate(MBeanServerConnection jmxServerConnection,
|
||||
String name) throws Exception {
|
||||
Object argsA[] = null;
|
||||
String sigA[] = null;
|
||||
if (args != null) {
|
||||
argsA = new Object[ args.size()];
|
||||
sigA = new String[args.size()];
|
||||
for( int i=0; i<args.size(); i++ ) {
|
||||
Arg arg=args.get(i);
|
||||
if (arg.getType() == null) {
|
||||
arg.setType("java.lang.String");
|
||||
sigA[i]=arg.getType();
|
||||
argsA[i]=arg.getValue();
|
||||
} else {
|
||||
sigA[i]=arg.getType();
|
||||
argsA[i]=convertStringToType(arg.getValue(),arg.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (classLoader != null && !"".equals(classLoader)) {
|
||||
if (isEcho()) {
|
||||
handleOutput("create MBean " + name + " from class "
|
||||
+ className + " with classLoader " + classLoader);
|
||||
}
|
||||
if(args == null)
|
||||
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader));
|
||||
else
|
||||
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader),argsA,sigA);
|
||||
|
||||
} else {
|
||||
if (isEcho()) {
|
||||
handleOutput("create MBean " + name + " from class "
|
||||
+ className);
|
||||
}
|
||||
if(args == null)
|
||||
jmxServerConnection.createMBean(className, new ObjectName(name));
|
||||
else
|
||||
jmxServerConnection.createMBean(className, new ObjectName(name),argsA,sigA);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Definition
|
||||
* <pre>
|
||||
* <path id="catalina_ant">
|
||||
* <fileset dir="${catalina.home}/server/lib">
|
||||
* <include name="catalina-ant.jar"/>
|
||||
* </fileset>
|
||||
* </path>
|
||||
*
|
||||
* <typedef
|
||||
* name="jmxEquals"
|
||||
* classname="org.apache.catalina.ant.jmx.JMXAccessorEqualsCondition"
|
||||
* classpathref="catalina_ant"/>
|
||||
* </pre>
|
||||
*
|
||||
* usage: Wait for start backup node
|
||||
* <pre>
|
||||
* <target name="wait">
|
||||
* <waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" >
|
||||
* <and>
|
||||
* <socket server="${server.name}" port="${server.port}"/>
|
||||
* <http url="${url}"/>
|
||||
* <jmxEquals
|
||||
* host="localhost" port="9014" username="controlRole" password="tomcat"
|
||||
* name="Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025"
|
||||
* attribute="connected" value="true"
|
||||
* />
|
||||
* </and>
|
||||
* </waitfor>
|
||||
* <fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" />
|
||||
* <echo message="Server ${url} alive" />
|
||||
* </target>
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class JMXAccessorEqualsCondition extends JMXAccessorConditionBase {
|
||||
|
||||
@Override
|
||||
public boolean eval() {
|
||||
String value = getValue();
|
||||
|
||||
if (value == null) {
|
||||
throw new BuildException("value attribute is not set");
|
||||
}
|
||||
if (getName() == null || getAttribute() == null) {
|
||||
throw new BuildException(
|
||||
"Must specify an MBean name and attribute for equals condition");
|
||||
}
|
||||
//FIXME check url or host/parameter
|
||||
String jmxValue = accessJMXValue();
|
||||
if (jmxValue != null) {
|
||||
return jmxValue.equals(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
120
java/org/apache/catalina/ant/jmx/JMXAccessorGetTask.java
Normal file
120
java/org/apache/catalina/ant/jmx/JMXAccessorGetTask.java
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Access <em>JMX</em> JSR 160 MBeans Server.
|
||||
* <ul>
|
||||
* <li>Get Mbeans attributes</li>
|
||||
* <li>Show Get result as Ant console log</li>
|
||||
* <li>Bind Get result as Ant properties</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Examples:
|
||||
* <br>
|
||||
* Get an Mbean IDataSender attribute nrOfRequests and create a new ant property <em>IDataSender.9025.nrOfRequests</em>
|
||||
* </p>
|
||||
* <pre>
|
||||
* <jmx:get
|
||||
* ref="jmx.server"
|
||||
* name="Catalina:type=IDataSender,host=localhost,senderAddress=192.168.1.2,senderPort=9025"
|
||||
* attribute="nrOfRequests"
|
||||
* resultproperty="IDataSender.9025.nrOfRequests"
|
||||
* echo="false">
|
||||
* />
|
||||
* </pre>
|
||||
* <p>
|
||||
* First call to a remote MBeanserver save the JMXConnection a referenz <em>jmx.server</em>
|
||||
* </p>
|
||||
* These tasks require Ant 1.6 or later interface.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class JMXAccessorGetTask extends JMXAccessorTask {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
private String attribute;
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* @return Returns the attribute.
|
||||
*/
|
||||
public String getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attribute The attribute to set.
|
||||
*/
|
||||
public void setAttribute(String attribute) {
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------ protected Methods
|
||||
|
||||
@Override
|
||||
public String jmxExecute(MBeanServerConnection jmxServerConnection)
|
||||
throws Exception {
|
||||
|
||||
if (getName() == null) {
|
||||
throw new BuildException("Must specify a 'name'");
|
||||
}
|
||||
if ((attribute == null)) {
|
||||
throw new BuildException(
|
||||
"Must specify a 'attribute' for get");
|
||||
}
|
||||
return jmxGet(jmxServerConnection, getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get property value.
|
||||
*
|
||||
* @param jmxServerConnection Connection to the JMX server
|
||||
* @param name The MBean name
|
||||
* @return The error message if any
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
protected String jmxGet(MBeanServerConnection jmxServerConnection, String name) throws Exception {
|
||||
String error = null;
|
||||
if(isEcho()) {
|
||||
handleOutput("MBean " + name + " get attribute " + attribute );
|
||||
}
|
||||
Object result = jmxServerConnection.getAttribute(
|
||||
new ObjectName(name), attribute);
|
||||
if (result != null) {
|
||||
echoResult(attribute,result);
|
||||
createProperty(result);
|
||||
} else
|
||||
error = "Attribute " + attribute + " is empty";
|
||||
return error;
|
||||
}
|
||||
}
|
||||
184
java/org/apache/catalina/ant/jmx/JMXAccessorInvokeTask.java
Normal file
184
java/org/apache/catalina/ant/jmx/JMXAccessorInvokeTask.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Access <em>JMX</em> JSR 160 MBeans Server.
|
||||
* <ul>
|
||||
* <li>open more then one JSR 160 rmi connection</li>
|
||||
* <li>Get/Set Mbeans attributes</li>
|
||||
* <li>Call Mbean Operation with arguments</li>
|
||||
* <li>Argument values can be converted from string to int,long,float,double,boolean,ObjectName or InetAddress </li>
|
||||
* <li>Query Mbeans</li>
|
||||
* <li>Show Get, Call, Query result at Ant console log</li>
|
||||
* <li>Bind Get, Call, Query result at Ant properties</li>
|
||||
* </ul>
|
||||
*
|
||||
* Examples:
|
||||
* <ul>
|
||||
* <li>
|
||||
* Get a session attribute hello from session with ref <em>${sessionid.0}</em> form
|
||||
* app <em>Catalina:type=Manager,context=/ClusterTest,host=localhost</em>
|
||||
* <pre>
|
||||
* <jmx:invoke
|
||||
* name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
|
||||
* operation="getSessionAttribute"
|
||||
* resultproperty="hello">
|
||||
* <arg value="${sessionid.0}"/>
|
||||
* <arg value="Hello"/>
|
||||
* </jmx:invoke>
|
||||
* </pre>
|
||||
* </li>
|
||||
* <li>
|
||||
* Create new AccessLogger at localhost
|
||||
* <code>
|
||||
* <jmx:invoke
|
||||
* name="Catalina:type=MBeanFactory"
|
||||
* operation="createAccessLoggerValve"
|
||||
* resultproperty="accessLoggerObjectName"
|
||||
* >
|
||||
* <arg value="Catalina:type=Host,host=localhost"/>
|
||||
* </jmx:invoke>
|
||||
*
|
||||
* </code>
|
||||
* </li>
|
||||
* <li>
|
||||
* Remove existing AccessLogger at localhost
|
||||
* <code>
|
||||
* <jmx:invoke
|
||||
* name="Catalina:type=MBeanFactory"
|
||||
* operation="removeValve"
|
||||
* >
|
||||
* <arg value="Catalina:type=Valve,name=AccessLogValve,host=localhost"/>
|
||||
* </jmx:invoke>
|
||||
*
|
||||
* </code>
|
||||
* </li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* First call to a remote MBeanserver save the JMXConnection a referenz <em>jmx.server</em>
|
||||
* </p>
|
||||
* These tasks require Ant 1.6 or later interface.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class JMXAccessorInvokeTask extends JMXAccessorTask {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
private String operation ;
|
||||
private List<Arg> args=new ArrayList<>();
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* @return Returns the operation.
|
||||
*/
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
/**
|
||||
* @param operation The operation to set.
|
||||
*/
|
||||
public void setOperation(String operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public void addArg(Arg arg ) {
|
||||
args.add(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the args.
|
||||
*/
|
||||
public List<Arg> getArgs() {
|
||||
return args;
|
||||
}
|
||||
/**
|
||||
* @param args The args to set.
|
||||
*/
|
||||
public void setArgs(List<Arg> args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ protected Methods
|
||||
|
||||
@Override
|
||||
public String jmxExecute(MBeanServerConnection jmxServerConnection)
|
||||
throws Exception {
|
||||
|
||||
if (getName() == null) {
|
||||
throw new BuildException("Must specify a 'name'");
|
||||
}
|
||||
if ((operation == null)) {
|
||||
throw new BuildException(
|
||||
"Must specify a 'operation' for call");
|
||||
}
|
||||
return jmxInvoke(jmxServerConnection, getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke specified operation.
|
||||
*
|
||||
* @param jmxServerConnection Connection to the JMX server
|
||||
* @param name The MBean name
|
||||
* @return null (no error message to report other than exception)
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
protected String jmxInvoke(MBeanServerConnection jmxServerConnection, String name) throws Exception {
|
||||
Object result ;
|
||||
if (args == null) {
|
||||
result = jmxServerConnection.invoke(new ObjectName(name),
|
||||
operation, null, null);
|
||||
} else {
|
||||
Object argsA[]=new Object[ args.size()];
|
||||
String sigA[]=new String[args.size()];
|
||||
for( int i=0; i<args.size(); i++ ) {
|
||||
Arg arg=args.get(i);
|
||||
if (arg.getType() == null) {
|
||||
arg.setType("java.lang.String");
|
||||
sigA[i]=arg.getType();
|
||||
argsA[i]=arg.getValue();
|
||||
} else {
|
||||
sigA[i]=arg.getType();
|
||||
argsA[i]=convertStringToType(arg.getValue(),arg.getType());
|
||||
}
|
||||
}
|
||||
result = jmxServerConnection.invoke(new ObjectName(name), operation, argsA, sigA);
|
||||
}
|
||||
if(result != null) {
|
||||
echoResult(operation,result);
|
||||
createProperty(result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
173
java/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java
Normal file
173
java/org/apache/catalina/ant/jmx/JMXAccessorQueryTask.java
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Query for Mbeans.
|
||||
* <ul>
|
||||
* <li>open no existing JSR 160 rmi jmx connection</li>
|
||||
* <li>Get all Mbeans attributes</li>
|
||||
* <li>Get only the Query Mbeans ObjectNames</li>
|
||||
* <li>Show query result as Ant console log</li>
|
||||
* <li>Bind query result as Ant properties</li>
|
||||
* </ul>
|
||||
* <br>
|
||||
* Query a list of Mbeans.
|
||||
* <pre>
|
||||
* <jmxQuery
|
||||
* host="127.0.0.1"
|
||||
* port="9014"
|
||||
* name="Catalina:type=Manager,*
|
||||
* resultproperty="manager" />
|
||||
* </pre>
|
||||
* with attribute <em>attributebinding="true"</em> you can get
|
||||
* all attributes also from result objects.<br>
|
||||
* The property manager.length show the size of the result
|
||||
* and with manager.[0..length].name the
|
||||
* resulted ObjectNames are saved.
|
||||
* These tasks require Ant 1.6 or later interface.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class JMXAccessorQueryTask extends JMXAccessorTask {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
private boolean attributebinding = false;
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* @return Returns the attributebinding.
|
||||
*/
|
||||
public boolean isAttributebinding() {
|
||||
return attributebinding;
|
||||
}
|
||||
/**
|
||||
* @param attributeBinding The attributebinding to set.
|
||||
*/
|
||||
public void setAttributebinding(boolean attributeBinding) {
|
||||
this.attributebinding = attributeBinding;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ protected Methods
|
||||
|
||||
|
||||
@Override
|
||||
public String jmxExecute(MBeanServerConnection jmxServerConnection)
|
||||
throws Exception {
|
||||
|
||||
if (getName() == null) {
|
||||
throw new BuildException("Must specify a 'name'");
|
||||
}
|
||||
return jmxQuery(jmxServerConnection, getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call Mbean server for some mbeans with same domain, attributes.
|
||||
* with <em>attributebinding=true</em> you can save all attributes from all found objects
|
||||
*
|
||||
* @param jmxServerConnection Connection to the JMX server
|
||||
* @param qry The query
|
||||
* @return null (no error message to report other than exception)
|
||||
*/
|
||||
protected String jmxQuery(MBeanServerConnection jmxServerConnection,
|
||||
String qry) {
|
||||
String isError = null;
|
||||
Set<ObjectName> names = null;
|
||||
String resultproperty = getResultproperty();
|
||||
try {
|
||||
names = jmxServerConnection.queryNames(new ObjectName(qry), null);
|
||||
if (resultproperty != null) {
|
||||
setProperty(resultproperty + ".Length",Integer.toString(names.size()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (isEcho())
|
||||
handleErrorOutput(e.getMessage());
|
||||
return "Can't query mbeans " + qry;
|
||||
}
|
||||
|
||||
if (resultproperty != null) {
|
||||
Iterator<ObjectName> it = names.iterator();
|
||||
int oindex = 0;
|
||||
String pname = null;
|
||||
while (it.hasNext()) {
|
||||
ObjectName oname = it.next();
|
||||
pname = resultproperty + "." + Integer.toString(oindex) + ".";
|
||||
oindex++;
|
||||
setProperty(pname + "Name", oname.toString());
|
||||
if (isAttributebinding()) {
|
||||
bindAttributes(jmxServerConnection, pname, oname);
|
||||
}
|
||||
}
|
||||
}
|
||||
return isError;
|
||||
}
|
||||
|
||||
protected void bindAttributes(MBeanServerConnection jmxServerConnection, String pname, ObjectName oname) {
|
||||
try {
|
||||
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
|
||||
MBeanAttributeInfo attrs[] = minfo.getAttributes();
|
||||
Object value = null;
|
||||
|
||||
for (int i = 0; i < attrs.length; i++) {
|
||||
if (!attrs[i].isReadable())
|
||||
continue;
|
||||
String attName = attrs[i].getName();
|
||||
if (attName.indexOf('=') >= 0 || attName.indexOf(':') >= 0
|
||||
|| attName.indexOf(' ') >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
value = jmxServerConnection
|
||||
.getAttribute(oname, attName);
|
||||
} catch (Exception e) {
|
||||
if (isEcho())
|
||||
handleErrorOutput("Error getting attribute "
|
||||
+ oname + " " + pname + attName + " "
|
||||
+ e.toString());
|
||||
continue;
|
||||
}
|
||||
if (value == null)
|
||||
continue;
|
||||
if ("modelerType".equals(attName))
|
||||
continue;
|
||||
createProperty(pname + attName, value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
195
java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
Normal file
195
java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
|
||||
/**
|
||||
* Access <em>JMX</em> JSR 160 MBeans Server.
|
||||
* <ul>
|
||||
* <li>Get Mbeans attributes</li>
|
||||
* <li>Show Get result as Ant console log</li>
|
||||
* <li>Bind Get result as Ant properties</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Examples:
|
||||
* Set an Mbean Manager attribute maxActiveSessions.
|
||||
* Set this attribute with fresh jmx connection without save reference
|
||||
* </p>
|
||||
* <pre>
|
||||
* <jmx:set
|
||||
* host="127.0.0.1"
|
||||
* port="9014"
|
||||
* ref=""
|
||||
* name="Catalina:type=Manager,context="/ClusterTest",host=localhost"
|
||||
* attribute="maxActiveSessions"
|
||||
* value="100"
|
||||
* type="int"
|
||||
* echo="false">
|
||||
* />
|
||||
* </pre>
|
||||
* <p>
|
||||
* First call to a remote MBeanserver save the JMXConnection a referenz <em>jmx.server</em>
|
||||
* </p>
|
||||
* These tasks require Ant 1.6 or later interface.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class JMXAccessorSetTask extends JMXAccessorTask {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
private String attribute;
|
||||
private String value;
|
||||
private String type;
|
||||
private boolean convert = false ;
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* @return Returns the attribute.
|
||||
*/
|
||||
public String getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attribute The attribute to set.
|
||||
*/
|
||||
public void setAttribute(String attribute) {
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* @param value The value to set.
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the type.
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueType The type to set.
|
||||
*/
|
||||
public void setType(String valueType) {
|
||||
this.type = valueType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the convert.
|
||||
*/
|
||||
public boolean isConvert() {
|
||||
return convert;
|
||||
}
|
||||
/**
|
||||
* @param convert The convert to set.
|
||||
*/
|
||||
public void setConvert(boolean convert) {
|
||||
this.convert = convert;
|
||||
}
|
||||
// ------------------------------------------------------ protected Methods
|
||||
|
||||
@Override
|
||||
public String jmxExecute(MBeanServerConnection jmxServerConnection)
|
||||
throws Exception {
|
||||
|
||||
if (getName() == null) {
|
||||
throw new BuildException("Must specify a 'name'");
|
||||
}
|
||||
if ((attribute == null || value == null)) {
|
||||
throw new BuildException(
|
||||
"Must specify a 'attribute' and 'value' for set");
|
||||
}
|
||||
return jmxSet(jmxServerConnection, getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property value.
|
||||
*
|
||||
* @param jmxServerConnection Connection to the JMX server
|
||||
* @param name The MBean name
|
||||
* @return null (no error message to report other than exception)
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
protected String jmxSet(MBeanServerConnection jmxServerConnection,
|
||||
String name) throws Exception {
|
||||
Object realValue;
|
||||
if (type != null) {
|
||||
realValue = convertStringToType(value, type);
|
||||
} else {
|
||||
if (isConvert()) {
|
||||
String mType = getMBeanAttributeType(jmxServerConnection, name,
|
||||
attribute);
|
||||
realValue = convertStringToType(value, mType);
|
||||
} else
|
||||
realValue = value;
|
||||
}
|
||||
jmxServerConnection.setAttribute(new ObjectName(name), new Attribute(
|
||||
attribute, realValue));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get MBean Attribute from Mbean Server
|
||||
*
|
||||
* @param jmxServerConnection The JMX connection name
|
||||
* @param name The MBean name
|
||||
* @param attribute The attribute name
|
||||
* @return The type of the attribute
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
protected String getMBeanAttributeType(
|
||||
MBeanServerConnection jmxServerConnection,
|
||||
String name,
|
||||
String attribute) throws Exception {
|
||||
ObjectName oname = new ObjectName(name);
|
||||
String mattrType = null;
|
||||
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
|
||||
MBeanAttributeInfo attrs[] = minfo.getAttributes();
|
||||
for (int i = 0; mattrType == null && i < attrs.length; i++) {
|
||||
if (attribute.equals(attrs[i].getName()))
|
||||
mattrType = attrs[i].getType();
|
||||
}
|
||||
return mattrType;
|
||||
}
|
||||
}
|
||||
714
java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
Normal file
714
java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
Normal file
@@ -0,0 +1,714 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.CompositeDataSupport;
|
||||
import javax.management.openmbean.CompositeType;
|
||||
import javax.management.openmbean.OpenType;
|
||||
import javax.management.openmbean.SimpleType;
|
||||
import javax.management.openmbean.TabularDataSupport;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
|
||||
import org.apache.catalina.ant.BaseRedirectorHelperTask;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
|
||||
/**
|
||||
* Access <em>JMX</em> JSR 160 MBeans Server.
|
||||
* <ul>
|
||||
* <li>open more then one JSR 160 rmi connection</li>
|
||||
* <li>Get/Set Mbeans attributes</li>
|
||||
* <li>Call Mbean Operation with arguments</li>
|
||||
* <li>Argument values can be converted from string to
|
||||
* int,long,float,double,boolean,ObjectName or InetAddress</li>
|
||||
* <li>Query Mbeans</li>
|
||||
* <li>Show Get, Call, Query result at Ant console log</li>
|
||||
* <li>Bind Get, Call, Query result at Ant properties</li>
|
||||
* </ul>
|
||||
*
|
||||
* Examples: open server with reference and authorisation
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* <jmxOpen
|
||||
* host="127.0.0.1"
|
||||
* port="9014"
|
||||
* username="monitorRole"
|
||||
* password="mysecret"
|
||||
* ref="jmx.myserver"
|
||||
* />
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* All calls after opening with same refid reuse the connection.
|
||||
* <p>
|
||||
* First call to a remote MBeanserver save the JMXConnection a referenz
|
||||
* <em>jmx.server</em>
|
||||
* </p>
|
||||
* All JMXAccessorXXXTask support the attribute <em>if</em> and
|
||||
* <em>unless</em>. With <em>if</em> the task is only execute when property
|
||||
* exist and with <em>unless</em> when property not exists. <br><b>NOTE
|
||||
* </b>: These tasks require Ant 1.6 or later interface.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.10
|
||||
*/
|
||||
public class JMXAccessorTask extends BaseRedirectorHelperTask {
|
||||
|
||||
public static final String JMX_SERVICE_PREFIX = "service:jmx:rmi:///jndi/rmi://";
|
||||
|
||||
public static final String JMX_SERVICE_SUFFIX = "/jmxrmi";
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
private String name = null;
|
||||
|
||||
private String resultproperty;
|
||||
|
||||
private String url = null;
|
||||
|
||||
private String host = "localhost";
|
||||
|
||||
private String port = "8050";
|
||||
|
||||
private String password = null;
|
||||
|
||||
private String username = null;
|
||||
|
||||
private String ref = "jmx.server";
|
||||
|
||||
private boolean echo = false;
|
||||
|
||||
private boolean separatearrayresults = true;
|
||||
|
||||
private String delimiter;
|
||||
|
||||
private String unlessCondition;
|
||||
|
||||
private String ifCondition;
|
||||
|
||||
private final Properties properties = new Properties();
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* Get the name used at remote MbeanServer.
|
||||
*
|
||||
* @return the name used at remote MbeanServer
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String objectName) {
|
||||
this.name = objectName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the resultproperty.
|
||||
*/
|
||||
public String getResultproperty() {
|
||||
return resultproperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param propertyName The resultproperty to set.
|
||||
*/
|
||||
public void setResultproperty(String propertyName) {
|
||||
this.resultproperty = propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the delimiter.
|
||||
*/
|
||||
public String getDelimiter() {
|
||||
return delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param separator The delimiter to set.
|
||||
*/
|
||||
public void setDelimiter(String separator) {
|
||||
this.delimiter = separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the echo.
|
||||
*/
|
||||
public boolean isEcho() {
|
||||
return echo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param echo
|
||||
* The echo to set.
|
||||
*/
|
||||
public void setEcho(boolean echo) {
|
||||
this.echo = echo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the separatearrayresults.
|
||||
*/
|
||||
public boolean isSeparatearrayresults() {
|
||||
return separatearrayresults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param separateArrayResults
|
||||
* The separatearrayresults to set.
|
||||
*/
|
||||
public void setSeparatearrayresults(boolean separateArrayResults) {
|
||||
this.separatearrayresults = separateArrayResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The login password for the <code>Manager</code> application.
|
||||
*/
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The login username for the <code>JMX</code> MBeanServer.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The URL of the <code>JMX JSR 160</code> MBeanServer to be used.
|
||||
*/
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Host of the <code>JMX JSR 160</code> MBeanServer to be used.
|
||||
*/
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Port of the <code>JMX JSR 160</code> MBeanServer to be used.
|
||||
*/
|
||||
public String getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the useRef.
|
||||
*/
|
||||
public boolean isUseRef() {
|
||||
return ref != null && !"".equals(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ref.
|
||||
*/
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param refId The ref to set.
|
||||
*/
|
||||
public void setRef(String refId) {
|
||||
this.ref = refId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ifCondition.
|
||||
*/
|
||||
public String getIf() {
|
||||
return ifCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only execute if a property of the given name exists in the current
|
||||
* project.
|
||||
*
|
||||
* @param c property name
|
||||
*/
|
||||
public void setIf(String c) {
|
||||
ifCondition = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the unlessCondition.
|
||||
*/
|
||||
public String getUnless() {
|
||||
return unlessCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only execute if a property of the given name does not exist in the
|
||||
* current project.
|
||||
*
|
||||
* @param c property name
|
||||
*/
|
||||
public void setUnless(String c) {
|
||||
unlessCondition = c;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Execute the specified command. This logic only performs the common
|
||||
* attribute validation required by all subclasses; it does not perform any
|
||||
* functional logic directly.
|
||||
*
|
||||
* @exception BuildException
|
||||
* if a validation error occurs
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
if (testIfCondition() && testUnlessCondition()) {
|
||||
try {
|
||||
String error = null;
|
||||
|
||||
MBeanServerConnection jmxServerConnection = getJMXConnection();
|
||||
error = jmxExecute(jmxServerConnection);
|
||||
if (error != null && isFailOnError()) {
|
||||
// exception should be thrown only if failOnError == true
|
||||
// or error line will be logged twice
|
||||
throw new BuildException(error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (isFailOnError()) {
|
||||
throw new BuildException(e);
|
||||
} else {
|
||||
handleErrorOutput(e.getMessage());
|
||||
}
|
||||
} finally {
|
||||
closeRedirector();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new JMX Connection with auth when username and password is set.
|
||||
*
|
||||
* @param url URL to be used for the JMX connection
|
||||
* (if specified, it is a complete URL so host and port will not
|
||||
* be used)
|
||||
* @param host Host name of the JMX server
|
||||
* @param port Port number for the JMX server
|
||||
* @param username User name for the connection
|
||||
* @param password Credentials corresponding to the specified user
|
||||
* @throws MalformedURLException Invalid URL specified
|
||||
* @throws IOException Other connection error
|
||||
* @return the JMX connection
|
||||
*/
|
||||
public static MBeanServerConnection createJMXConnection(String url,
|
||||
String host, String port, String username, String password)
|
||||
throws MalformedURLException, IOException {
|
||||
String urlForJMX;
|
||||
if (url != null)
|
||||
urlForJMX = url;
|
||||
else
|
||||
urlForJMX = JMX_SERVICE_PREFIX + host + ":" + port
|
||||
+ JMX_SERVICE_SUFFIX;
|
||||
Map<String, String[]> environment = null;
|
||||
if (username != null && password != null) {
|
||||
String[] credentials = new String[2];
|
||||
credentials[0] = username;
|
||||
credentials[1] = password;
|
||||
environment = new HashMap<>();
|
||||
environment.put(JMXConnector.CREDENTIALS, credentials);
|
||||
}
|
||||
return JMXConnectorFactory.connect(new JMXServiceURL(urlForJMX),
|
||||
environment).getMBeanServerConnection();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test the if condition
|
||||
*
|
||||
* @return true if there is no if condition, or the named property exists
|
||||
*/
|
||||
protected boolean testIfCondition() {
|
||||
if (ifCondition == null || "".equals(ifCondition)) {
|
||||
return true;
|
||||
}
|
||||
return getProperty(ifCondition) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* test the unless condition
|
||||
*
|
||||
* @return true if there is no unless condition, or there is a named
|
||||
* property but it doesn't exist
|
||||
*/
|
||||
protected boolean testUnlessCondition() {
|
||||
if (unlessCondition == null || "".equals(unlessCondition)) {
|
||||
return true;
|
||||
}
|
||||
return getProperty(unlessCondition) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current Connection from <em>ref</em> parameter or create a new one!
|
||||
*
|
||||
* @param project The Ant project
|
||||
* @param url URL to be used for the JMX connection
|
||||
* (if specified, it is a complete URL so host and port will not
|
||||
* be used)
|
||||
* @param host Host name of the JMX server
|
||||
* @param port Port number for the JMX server
|
||||
* @param username User name for the connection
|
||||
* @param password Credentials corresponding to the specified user
|
||||
* @param refId The Id of the reference to retrieve in the project
|
||||
* @throws MalformedURLException Invalid URL specified
|
||||
* @throws IOException Other connection error
|
||||
* @return the JMX connection
|
||||
*/
|
||||
@SuppressWarnings("null")
|
||||
public static MBeanServerConnection accessJMXConnection(Project project,
|
||||
String url, String host, String port, String username,
|
||||
String password, String refId) throws MalformedURLException,
|
||||
IOException {
|
||||
MBeanServerConnection jmxServerConnection = null;
|
||||
boolean isRef = project != null && refId != null && refId.length() > 0;
|
||||
if (isRef) {
|
||||
Object pref = project.getReference(refId);
|
||||
try {
|
||||
jmxServerConnection = (MBeanServerConnection) pref;
|
||||
} catch (ClassCastException cce) {
|
||||
project.log("wrong object reference " + refId + " - "
|
||||
+ pref.getClass());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jmxServerConnection == null) {
|
||||
jmxServerConnection = createJMXConnection(url, host, port,
|
||||
username, password);
|
||||
}
|
||||
if (isRef && jmxServerConnection != null) {
|
||||
project.addReference(refId, jmxServerConnection);
|
||||
}
|
||||
return jmxServerConnection;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ protected Methods
|
||||
|
||||
/**
|
||||
* get JMXConnection
|
||||
*
|
||||
* @throws MalformedURLException Invalid URL specified
|
||||
* @throws IOException Other connection error
|
||||
* @return the JMX connection
|
||||
*/
|
||||
protected MBeanServerConnection getJMXConnection()
|
||||
throws MalformedURLException, IOException {
|
||||
|
||||
MBeanServerConnection jmxServerConnection = null;
|
||||
if (isUseRef()) {
|
||||
Object pref = null ;
|
||||
if(getProject() != null) {
|
||||
pref = getProject().getReference(getRef());
|
||||
if (pref != null) {
|
||||
try {
|
||||
jmxServerConnection = (MBeanServerConnection) pref;
|
||||
} catch (ClassCastException cce) {
|
||||
getProject().log(
|
||||
"Wrong object reference " + getRef() + " - "
|
||||
+ pref.getClass());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jmxServerConnection == null) {
|
||||
jmxServerConnection = accessJMXConnection(getProject(),
|
||||
getUrl(), getHost(), getPort(), getUsername(),
|
||||
getPassword(), getRef());
|
||||
}
|
||||
} else {
|
||||
jmxServerConnection = accessJMXConnection(getProject(), getUrl(),
|
||||
getHost(), getPort(), getUsername(), getPassword(), null);
|
||||
}
|
||||
return jmxServerConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the specified command, based on the configured properties. The
|
||||
* input stream will be closed upon completion of this task, whether it was
|
||||
* executed successfully or not.
|
||||
*
|
||||
* @param jmxServerConnection The JMX connection that should be used
|
||||
* @return An error message string in some situations
|
||||
* @exception Exception if an error occurs
|
||||
*/
|
||||
public String jmxExecute(MBeanServerConnection jmxServerConnection)
|
||||
throws Exception {
|
||||
|
||||
if ((jmxServerConnection == null)) {
|
||||
throw new BuildException("Must open a connection!");
|
||||
} else if (isEcho()) {
|
||||
handleOutput("JMX Connection ref=" + ref + " is open!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string to datatype FIXME How we can transfer values from ant
|
||||
* project reference store (ref)?
|
||||
*
|
||||
* @param value The value
|
||||
* @param valueType The type
|
||||
* @return The converted object
|
||||
*/
|
||||
protected Object convertStringToType(String value, String valueType) {
|
||||
if ("java.lang.String".equals(valueType))
|
||||
return value;
|
||||
|
||||
Object convertValue = value;
|
||||
if ("java.lang.Integer".equals(valueType) || "int".equals(valueType)) {
|
||||
try {
|
||||
convertValue = Integer.valueOf(value);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (isEcho())
|
||||
handleErrorOutput("Unable to convert to integer:" + value);
|
||||
}
|
||||
} else if ("java.lang.Long".equals(valueType)
|
||||
|| "long".equals(valueType)) {
|
||||
try {
|
||||
convertValue = Long.valueOf(value);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (isEcho())
|
||||
handleErrorOutput("Unable to convert to long:" + value);
|
||||
}
|
||||
} else if ("java.lang.Boolean".equals(valueType)
|
||||
|| "boolean".equals(valueType)) {
|
||||
convertValue = Boolean.valueOf(value);
|
||||
} else if ("java.lang.Float".equals(valueType)
|
||||
|| "float".equals(valueType)) {
|
||||
try {
|
||||
convertValue = Float.valueOf(value);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (isEcho())
|
||||
handleErrorOutput("Unable to convert to float:" + value);
|
||||
}
|
||||
} else if ("java.lang.Double".equals(valueType)
|
||||
|| "double".equals(valueType)) {
|
||||
try {
|
||||
convertValue = Double.valueOf(value);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (isEcho())
|
||||
handleErrorOutput("Unable to convert to double:" + value);
|
||||
}
|
||||
} else if ("javax.management.ObjectName".equals(valueType)
|
||||
|| "name".equals(valueType)) {
|
||||
try {
|
||||
convertValue = new ObjectName(value);
|
||||
} catch (MalformedObjectNameException e) {
|
||||
if (isEcho())
|
||||
handleErrorOutput("Unable to convert to ObjectName:"
|
||||
+ value);
|
||||
}
|
||||
} else if ("java.net.InetAddress".equals(valueType)) {
|
||||
try {
|
||||
convertValue = InetAddress.getByName(value);
|
||||
} catch (UnknownHostException exc) {
|
||||
if (isEcho())
|
||||
handleErrorOutput("Unable to resolve host name:" + value);
|
||||
}
|
||||
}
|
||||
return convertValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name context of result
|
||||
* @param result The result
|
||||
*/
|
||||
protected void echoResult(String name, Object result) {
|
||||
if (isEcho()) {
|
||||
if (result.getClass().isArray()) {
|
||||
for (int i = 0; i < Array.getLength(result); i++) {
|
||||
handleOutput(name + "." + i + "=" + Array.get(result, i));
|
||||
}
|
||||
} else
|
||||
handleOutput(name + "=" + result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create result as property with name from attribute resultproperty
|
||||
*
|
||||
* @param result The result
|
||||
* @see #createProperty(String, Object)
|
||||
*/
|
||||
protected void createProperty(Object result) {
|
||||
if (resultproperty != null) {
|
||||
createProperty(resultproperty, result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create result as property with name from property prefix When result is
|
||||
* an array and isSeparateArrayResults is true, resultproperty used as
|
||||
* prefix (<code>resultproperty.0-array.length</code> and store the
|
||||
* result array length at <code>resultproperty.length</code>. Other
|
||||
* option is that you delimit your result with a delimiter
|
||||
* (java.util.StringTokenizer is used).
|
||||
*
|
||||
* @param propertyPrefix Prefix for the property
|
||||
* @param result The result
|
||||
*/
|
||||
protected void createProperty(String propertyPrefix, Object result) {
|
||||
if (propertyPrefix == null)
|
||||
propertyPrefix = "";
|
||||
if (result instanceof CompositeDataSupport) {
|
||||
CompositeDataSupport data = (CompositeDataSupport) result;
|
||||
CompositeType compositeType = data.getCompositeType();
|
||||
Set<String> keys = compositeType.keySet();
|
||||
for (String key : keys) {
|
||||
Object value = data.get(key);
|
||||
OpenType<?> type = compositeType.getType(key);
|
||||
if (type instanceof SimpleType<?>) {
|
||||
setProperty(propertyPrefix + "." + key, value);
|
||||
} else {
|
||||
createProperty(propertyPrefix + "." + key, value);
|
||||
}
|
||||
}
|
||||
} else if (result instanceof TabularDataSupport) {
|
||||
TabularDataSupport data = (TabularDataSupport) result;
|
||||
for (Object key : data.keySet()) {
|
||||
for (Object key1 : ((List<?>) key)) {
|
||||
CompositeData valuedata = data.get(new Object[] { key1 });
|
||||
Object value = valuedata.get("value");
|
||||
OpenType<?> type = valuedata.getCompositeType().getType(
|
||||
"value");
|
||||
if (type instanceof SimpleType<?>) {
|
||||
setProperty(propertyPrefix + "." + key1, value);
|
||||
} else {
|
||||
createProperty(propertyPrefix + "." + key1, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (result.getClass().isArray()) {
|
||||
if (isSeparatearrayresults()) {
|
||||
int size = 0;
|
||||
for (int i = 0; i < Array.getLength(result); i++) {
|
||||
if (setProperty(propertyPrefix + "." + size, Array.get(
|
||||
result, i))) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
if (size > 0) {
|
||||
setProperty(propertyPrefix + ".Length", Integer
|
||||
.toString(size));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String delim = getDelimiter();
|
||||
if (delim != null) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(result
|
||||
.toString(), delim);
|
||||
int size = 0;
|
||||
for (; tokenizer.hasMoreTokens();) {
|
||||
String token = tokenizer.nextToken();
|
||||
if (setProperty(propertyPrefix + "." + size, token)) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
if (size > 0)
|
||||
setProperty(propertyPrefix + ".Length", Integer
|
||||
.toString(size));
|
||||
} else {
|
||||
setProperty(propertyPrefix, result.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Property
|
||||
* @param property name
|
||||
* @return The property value
|
||||
*/
|
||||
public String getProperty(String property) {
|
||||
Project currentProject = getProject();
|
||||
if (currentProject != null) {
|
||||
return currentProject.getProperty(property);
|
||||
} else {
|
||||
return properties.getProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param property The property
|
||||
* @param value The value
|
||||
* @return True if successful
|
||||
*/
|
||||
public boolean setProperty(String property, Object value) {
|
||||
if (property != null) {
|
||||
if (value == null)
|
||||
value = "";
|
||||
if (isEcho()) {
|
||||
handleOutput(property + "=" + value.toString());
|
||||
}
|
||||
Project currentProject = getProject();
|
||||
if (currentProject != null) {
|
||||
currentProject.setNewProperty(property, value.toString());
|
||||
} else {
|
||||
properties.setProperty(property, value.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.ant.jmx;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* unregister an MBean at <em>JMX</em> JSR 160 MBeans Server.
|
||||
* <ul>
|
||||
* <li>unregister Mbeans</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Examples:
|
||||
* <br>
|
||||
* unregister an existing Mbean at jmx.server connection
|
||||
* </p>
|
||||
* <pre>
|
||||
* <jmx:unregister
|
||||
* ref="jmx.server"
|
||||
* name="Catalina:type=MBeanFactory" />
|
||||
* </pre>
|
||||
* <p>
|
||||
* <b>WARNING</b>Not all Tomcat MBeans can successfully unregister remotely. The mbean
|
||||
* unregistration don't remove valves, realm, .. from parent class.
|
||||
* Please, use the MBeanFactory operation to remove valves and realms.
|
||||
* </p>
|
||||
* <p>
|
||||
* First call to a remote MBeanserver save the JMXConnection a reference <em>jmx.server</em>
|
||||
* </p>
|
||||
* These tasks require Ant 1.6 or later interface.
|
||||
*
|
||||
* @author Peter Rossbach
|
||||
* @since 5.5.12
|
||||
*/
|
||||
public class JMXAccessorUnregisterTask extends JMXAccessorTask {
|
||||
|
||||
// ------------------------------------------------------ protected Methods
|
||||
|
||||
@Override
|
||||
public String jmxExecute(MBeanServerConnection jmxServerConnection)
|
||||
throws Exception {
|
||||
|
||||
if (getName() == null) {
|
||||
throw new BuildException("Must specify a 'name'");
|
||||
}
|
||||
return jmxUuregister(jmxServerConnection, getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unregister MBean.
|
||||
*
|
||||
* @param jmxServerConnection Connection to the JMX server
|
||||
* @param name The MBean name
|
||||
* @return null (no error message to report other than exception)
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
protected String jmxUuregister(MBeanServerConnection jmxServerConnection,String name) throws Exception {
|
||||
String error = null;
|
||||
if(isEcho()) {
|
||||
handleOutput("Unregister MBean " + name );
|
||||
}
|
||||
jmxServerConnection.unregisterMBean(
|
||||
new ObjectName(name));
|
||||
return error;
|
||||
}
|
||||
|
||||
}
|
||||
46
java/org/apache/catalina/ant/jmx/antlib.xml
Normal file
46
java/org/apache/catalina/ant/jmx/antlib.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<antlib>
|
||||
<typedef
|
||||
name="open"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorTask" />
|
||||
<typedef
|
||||
name="set"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorSetTask" />
|
||||
<typedef
|
||||
name="get"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorGetTask" />
|
||||
<typedef
|
||||
name="invoke"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorInvokeTask" />
|
||||
<typedef
|
||||
name="query"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorQueryTask" />
|
||||
<typedef
|
||||
name="create"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorCreateTask" />
|
||||
<typedef
|
||||
name="unregister"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorUnregisterTask" />
|
||||
<typedef
|
||||
name="equals"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorEqualsCondition" />
|
||||
<typedef
|
||||
name="condition"
|
||||
classname="org.apache.catalina.ant.jmx.JMXAccessorCondition" />
|
||||
</antlib>
|
||||
25
java/org/apache/catalina/ant/jmx/jmxaccessor.tasks
Normal file
25
java/org/apache/catalina/ant/jmx/jmxaccessor.tasks
Normal file
@@ -0,0 +1,25 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# JMX
|
||||
jmxOpen=org.apache.catalina.ant.jmx.JMXAccessorTask
|
||||
jmxSet=org.apache.catalina.ant.jmx.JMXAccessorSetTask
|
||||
jmxGet=org.apache.catalina.ant.jmx.JMXAccessorGetTask
|
||||
jmxInvoke=org.apache.catalina.ant.jmx.JMXAccessorInvokeTask
|
||||
jmxQuery=org.apache.catalina.ant.jmx.JMXAccessorQueryTask
|
||||
jmxCreate=org.apache.catalina.ant.jmx.JMXAccessorCreateTask
|
||||
jmxUnregister=org.apache.catalina.ant.jmx.JMXAccessorUnregisterTask
|
||||
jmxEquals=org.apache.catalina.ant.jmx.JMXAccessorEqualsCondition
|
||||
jmxCondition=org.apache.catalina.ant.jmx.JMXAccessorCondition
|
||||
77
java/org/apache/catalina/ant/jmx/package.html
Normal file
77
java/org/apache/catalina/ant/jmx/package.html
Normal file
@@ -0,0 +1,77 @@
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<body>
|
||||
|
||||
<p>This package contains a set of <code>JMX Task</code> implementations for
|
||||
<em>Ant (version 1.6 or later)</em> that can be used to interact with the
|
||||
Remote JMX JSR 160 RMI Adaptor to get/set attributes, invoke MBean operations
|
||||
and query for Mbeans inside a running instance of Tomcat. For more information, see
|
||||
<a href="https://tomcat.apache.org/tomcat-8.5-doc/monitoring.html">
|
||||
https://tomcat.apache.org/tomcat-8.5-doc/monitoring.html</a>.</p>
|
||||
|
||||
<p>Each task element can open a new jmx connection or reference an
|
||||
existing one. The following attribute are exists in every tasks:</p>
|
||||
|
||||
<table>
|
||||
<caption>Common task attributes</caption>
|
||||
<tr>
|
||||
<th>Attribute</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>url</td>
|
||||
<td>
|
||||
The JMX Connection URL of the remote Tomcat MBeansServer.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>username</td>
|
||||
<td>
|
||||
The username of an MBeanServer auth, when configured.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>password</td>
|
||||
<td>
|
||||
The password of an MBeanServer auth, when configured.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>host</td>
|
||||
<td>
|
||||
The JMX Connection host.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>port</td>
|
||||
<td>
|
||||
The JMX Connection port.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ref</td>
|
||||
<td>
|
||||
The name of the ant internal reference for a jmx connection.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<p><strong>NOTE</strong> - This Tasks only work,
|
||||
when JSR 160 MBean Adaptor as remote jvm is configured.</p>
|
||||
|
||||
</body>
|
||||
103
java/org/apache/catalina/ant/package.html
Normal file
103
java/org/apache/catalina/ant/package.html
Normal file
@@ -0,0 +1,103 @@
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<body>
|
||||
|
||||
<p>This package contains a set of <code>Task</code> implementations for
|
||||
<em>Ant (version 1.6.x or later)</em> that can be used to interact with the
|
||||
Manager application to deploy, undeploy, list, reload, start and stop web applications
|
||||
from a running instance of Tomcat. For more information, see
|
||||
<a href="https://tomcat.apache.org/tomcat-8.5-doc/manager-howto.html">
|
||||
https://tomcat.apache.org/tomcat-8.5-doc/manager-howto.html</a>.</p>
|
||||
|
||||
<p>The attributes of each task element correspond
|
||||
exactly to the request parameters that are included with an HTTP request
|
||||
sent directly to the Manager application. They are summarized as follows:
|
||||
</p>
|
||||
|
||||
<table>
|
||||
<caption>Task attributes</caption>
|
||||
<tr>
|
||||
<th>Attribute</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>url</td>
|
||||
<td>
|
||||
The URL of the Manager web application you will use to
|
||||
perform the requested operations. If not specified, defaults to
|
||||
<code>http://localhost:8080/manager/text</code> (which corresponds
|
||||
to a standard installation of Tomcat 7).
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>username</td>
|
||||
<td>
|
||||
The username of a Tomcat user that has been configured with the
|
||||
<code>manager-script</code> role, as required to execute Manager
|
||||
application commands. This attribute is required.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>password</td>
|
||||
<td>
|
||||
The password of a Tomcat user that has been configured with the
|
||||
<code>manager-script</code> role, as required to execute Manager
|
||||
application commands. This attribute is required.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>config</td>
|
||||
<td>
|
||||
A URL pointing at the context configuration file (i.e. a file
|
||||
containing only the <code><Context></code> element, and
|
||||
its nested elements, from <code>server.xml</code> for a particular
|
||||
web application). This attribute is supported only on the
|
||||
<code>install</code> target, and is required only if you wish to
|
||||
install an application with non-default configuration characteristics.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>path</td>
|
||||
<td>
|
||||
The context path (including the leading slash) of the web application
|
||||
this command is intended to manage, or a zero-length string for the
|
||||
ROOT web application. This attribute is valid for the
|
||||
<code>install</code>, <code>reload</code>, <code>remove</code>,
|
||||
<code>start</code>, and <code>stop</code> tasks only, and is
|
||||
required in all of those cases.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>war</td>
|
||||
<td>
|
||||
A <code>jar:</code> URL that points at a web application archive (WAR)
|
||||
file, or a <code>file:</code> URL that points at an unpacked directory
|
||||
containing the web application. This attribute is supported only on
|
||||
the <code>install</code> target. You must specify at least one of the
|
||||
<code>config</code> and <code>war</code> attributes; if you specify
|
||||
both, the <code>war</code> attribute overrides the <code>docBase</code>
|
||||
attribute in the context configuration file.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p><strong>NOTE</strong> - Commands executed through the <em>Manager</em>
|
||||
application are <strong>NOT</strong> reflected in updates to the Tomcat
|
||||
<code>server.xml</code> configuration file, so they do not persist past the
|
||||
next time you restart the entire Tomcat container.</p>
|
||||
|
||||
</body>
|
||||
Reference in New Issue
Block a user