/**
* @see nexj.core.tools.GenericTool#execute(java.lang.String)
*/
protected void execute(String sCommand) throws Exception
{
HTTPClient client = new HTTPClient();
client.setPasswordProvider(new PasswordAuthenticationProvider()
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("nexjsa", "nexj".toCharArray());
}
public boolean isAuthenticationDeterministic()
{
return true;
}
});
int nReqCount = Integer.parseInt(getProperty("req.count", "1"));
final Request request = new Request();
TransferObject tobj = new TransferObject();
tobj.setClassName("TestMessage");
tobj.setEventName("runTest");
request.addInvocation(tobj);
request.setAsync(StringUtil.parseBoolean(getProperty("async", "0")));
for (int nReq = 0; nReq < nReqCount; ++ nReq)
{
Object response = client.invoke(new URI(getProperty("url", "http://localhost:8080/nexj/text")), HTTP.METHOD_POST,
new HTTPClient.RequestHandler()
{
public void handleRequest(HTTPClient client, OutputStream ostream) throws IOException
{
Writer writer = new OutputStreamWriter(ostream, XMLUtil.ENCODING);
new TextMarshaller(null).serialize(request, writer);
writer.close();
}
},
new HTTPClient.ResponseHandler()
{
public Object handleResponse(HTTPClient client, InputStream istream) throws IOException
{
int nResult = client.getResponseStatus();
if (nResult != HTTP.STATUS_OK)
{
RuntimeException e = null;
if (nResult == HTTP.STATUS_UNAUTHORIZED ||
nResult == HTTP.STATUS_FORBIDDEN)
{
e = new LoginException("err.auth.login");
}
if (e == null || e.getCause() == null)
{
RuntimeException x = new HTTPException(nResult, client.getResponseMessage());
if (e == null)
{
e = x;
}