package org.xmlsh.aws;
import java.io.IOException;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.xmlsh.aws.util.AWSSQSCommand;
import org.xmlsh.core.CoreException;
import org.xmlsh.core.Options;
import org.xmlsh.core.UnexpectedException;
import org.xmlsh.core.XValue;
import org.xmlsh.core.io.OutputPort;
import com.amazonaws.services.sqs.model.ListQueuesRequest;
import com.amazonaws.services.sqs.model.ListQueuesResult;
import net.sf.saxon.s9api.SaxonApiException;
public class sqsListQueues extends AWSSQSCommand {
/**
* @param args
* @throws IOException
*/
@Override
public int run(List<XValue> args) throws Exception {
Options opts = getOptions();
parseOptions(opts, args);
args = opts.getRemainingArgs();
setSerializeOpts(this.getSerializeOpts(opts));
String prefix = null;
if(args.size() > 0)
prefix = args.get(0).toString();
try {
getSQSClient(opts);
} catch (UnexpectedException e) {
usage(e.getLocalizedMessage());
return 1;
}
int ret;
ret = list(prefix);
return ret;
}
private int list(String prefix)
throws IOException, XMLStreamException, SaxonApiException, CoreException {
OutputPort stdout = getStdout();
mWriter = stdout.asXMLStreamWriter(getSerializeOpts());
startDocument();
startElement(getName());
ListQueuesRequest request = new ListQueuesRequest();
if(prefix != null)
request.setQueueNamePrefix(prefix);
traceCall("listQueues");
ListQueuesResult result = getAWSClient().listQueues(request);
for(String url : result.getQueueUrls()) {
startElement("queue");
attribute("url", url);
endElement();
}
endElement();
endDocument();
closeWriter();
stdout.writeSequenceTerminator(getSerializeOpts());
return 0;
}
}