Skip to content

Commit

Permalink
(split)bug: 35314
Browse files Browse the repository at this point in the history
Added -t/--timeout option to zmmailbox CLI, for timeout in seconds.  0 means infinite, and default is to use httpclient_connmgr_so_timeout from localconfig. (The default for that is 60000ms, or 60 seconds.)

http://bugzilla.zimbra.com/show_bug.cgi?id=35314

Copied from Perforce
 Change: 169952
  • Loading branch information
Unknown Perforce User committed Aug 18, 2009
1 parent 713b671 commit 61d2511
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/java/com/zimbra/cs/zclient/ZMailbox.java
Expand Up @@ -2565,7 +2565,7 @@ private InputStream getRESTResource(String relativePath, String startTimeArg, St

get = new GetMethod(uri.toString());

if (msecTimeout > 0)
if (msecTimeout > -1)
get.getParams().setSoTimeout(msecTimeout);

statusCode = client.executeMethod(get);
Expand Down Expand Up @@ -2632,7 +2632,7 @@ public void postRESTResource(String relativePath, InputStream is, boolean closeI

post = new PostMethod(uri.toString());

if (msecTimeout > 0)
if (msecTimeout > -1)
post.getParams().setSoTimeout(msecTimeout);

RequestEntity entity = (length > 0) ?
Expand Down
27 changes: 23 additions & 4 deletions src/java/com/zimbra/cs/zclient/ZMailboxUtil.java
Expand Up @@ -129,6 +129,7 @@ public class ZMailboxUtil implements DebugListener {
SoapProvisioning mProv;
SoapProtocol mRequestProto = SoapProtocol.SoapJS;
SoapProtocol mResponseProto = SoapProtocol.SoapJS;
private int mTimeout = LC.httpclient_connmgr_so_timeout.intValue();

private Map<Integer, String> mIndexToId = new HashMap<Integer, String>();

Expand Down Expand Up @@ -176,6 +177,18 @@ public void setUrl(String url, boolean admin) throws ServiceException {
mUrl = ZMailbox.resolveUrl(url, admin);
}

public void setTimeout(String timeout) throws ServiceException {
int num;
try {
num = Integer.parseInt(timeout);
} catch (NumberFormatException e) {
throw ServiceException.INVALID_REQUEST("Invalid timeout value " + timeout, e);
}
if (num < 0)
throw ServiceException.INVALID_REQUEST("Timeout can't be negative", null);
mTimeout = num * 1000;
}

private void usage() {

if (mCommand != null) {
Expand All @@ -199,6 +212,7 @@ private void usage() {
stdout.println(" -p/--password {pass} password for admin account and/or mailbox");
stdout.println(" -P/--passfile {file} read password from file");
stdout.println(" -r/--protocol {proto|req-proto/response-proto} specify request/response protocol [soap11,soap12,json]");
stdout.println(" -t/--timeout timeout (in seconds)");
stdout.println(" -v/--verbose verbose mode (dumps full exception stack trace)");
stdout.println(" -d/--debug debug mode (dumps SOAP messages)");

Expand Down Expand Up @@ -551,7 +565,8 @@ public void selectMailbox(String targetAccount, SoapProvisioning prov) throws Se
ZMailbox.Options options = prov.getMailboxOptions(AccountBy.name, mMailboxName, 60*60*24);
options.setRequestProtocol(mRequestProto);
options.setResponseProtocol(mResponseProto);

options.setTimeout(mTimeout);

if (prov.soapGetTransportDebugListener() != null)
options.setDebugListener(prov.soapGetTransportDebugListener());
else // use the same debug listener used by zmprov
Expand Down Expand Up @@ -600,6 +615,7 @@ private void auth(String name, String password, String uri) throws ServiceExcept
options.setDebugListener(mDebug ? this : null);
options.setRequestProtocol(mRequestProto);
options.setResponseProtocol(mResponseProto);
options.setTimeout(mTimeout);
mMbox = ZMailbox.getMailbox(options);
mPrompt = String.format("mbox %s> ", mMbox.getName());
dumpMailboxConnect();
Expand Down Expand Up @@ -2505,6 +2521,7 @@ public static void main(String args[]) throws IOException, ServiceException {
options.addOption("m", "mailbox", true, "mailbox to open");
options.addOption("p", "password", true, "password for admin/mailbox");
options.addOption("P", "passfile", true, "filename with password in it");
options.addOption("t", "timeout", true, "timeout (in seconds)");
options.addOption("v", "verbose", false, "verbose mode");
options.addOption("d", "debug", false, "debug mode");
options.addOption(SoapCLI.OPT_AUTHTOKEN);
Expand Down Expand Up @@ -2559,9 +2576,11 @@ public static void main(String args[]) throws IOException, ServiceException {
if (cl.hasOption('r')) pu.setProtocol(cl.getOptionValue('r'));
if (cl.hasOption('P')) {
pu.setPassword(StringUtil.readSingleLineFromFile(cl.getOptionValue('P')));
}
}
if (cl.hasOption('d')) pu.setDebug(true);

if (cl.hasOption('t')) pu.setTimeout(cl.getOptionValue('t'));

args = cl.getArgs();

pu.setInteractive(args.length < 1);
Expand Down Expand Up @@ -2678,7 +2697,7 @@ private void doGetRestURL(String args[]) throws ServiceException {

try {
os = hasOutputFile ? new FileOutputStream(outputFile) : System.out;
mMbox.getRESTResource(encodeURL(args[0]), os, hasOutputFile, startTimeOpt(), endTimeOpt(), 0, urlOpt(false));
mMbox.getRESTResource(encodeURL(args[0]), os, hasOutputFile, startTimeOpt(), endTimeOpt(), mTimeout, urlOpt(false));
} catch (IOException e) {
throw ZClientException.IO_ERROR(e.getMessage(), e);
} finally {
Expand All @@ -2690,7 +2709,7 @@ private void doPostRestURL(String args[]) throws ServiceException {
try {
File file = new File(args[1]);
mMbox.postRESTResource(encodeURL(args[0]), new FileInputStream(file), true, file.length(),
contentTypeOpt(), ignoreAndContinueOnErrorOpt(), preserveAlarmsOpt(), 0, urlOpt(false));
contentTypeOpt(), ignoreAndContinueOnErrorOpt(), preserveAlarmsOpt(), mTimeout, urlOpt(false));
} catch (FileNotFoundException e) {
throw ZClientException.CLIENT_ERROR("file not found: "+args[1], e);
}
Expand Down

0 comments on commit 61d2511

Please sign in to comment.