12-22-2007 02:24 PM
script:
{
var authorEmail = null;
var content = null;
var comment = null;
for (arg in args)
{
logger.log(arg + "=" + args[arg]);
}
// log each argument (assuming one or more values have been provided for each)
for (arg in argsM)
{
for each (val in argsM[arg])
{
logger.log(arg + "=" + val);
}
}
// locate file attributes
for each (field in formdata.fields)
{
if (logger.isLoggingEnabled()) {
logger.log("found field "+field.name+" with value "+field.value);
}
if (field.name == "email")
{
authorEmail = field.value;
}
else if (field.name == "comment")
{
content = field.value;
}
}
if (logger.isLoggingEnabled()) {
// logger.log("formdata is +"formdata.fields);
logger.log("email is "+authorEmail);
logger.log("content is "+content);
}
client.getHttpConnectionManager().getParams()
.setConnectionTimeout(5000);
client.getState().setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password));
PostMethod post = new PostMethod(url);
post.setDoAuthentication(true);
post.setRequestHeader("Content-Type", "multipart/form-data");
Part[] parts = { new StringPart("email", authorEmail),
new StringPart("comment", comment) };
post.setRequestEntity(new MultipartRequestEntity(parts, post
.getParams()));
try {
int status = client.executeMethod(post);
System.out.println("received status " + status);
if (status > 299) { // there was an error
System.out.println(post.getResponseBodyAsString());
}
} finally {
post.releaseConnection();
}
}
12-26-2007 02:09 PM
//create HttpClient object
HttpClient client = new HttpClient();
//pre-authenticate with alfresco server
client.getParams().setAuthenticationPreemptive(true);
Credentials loginCreds = new UsernamePasswordCredentials("admin", "admin");
//Use AuthScope.ANY since the HttpClient connects to just one URL
client.getState().setCredentials(AuthScope.ANY , loginCreds);
PostMethod post= new PostMethod(url);
post.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
//Alfresco only reads the POST parameters if they are in the body of the request, so we need to create a RequestEntity to populate the body.
Part[] parts = {new StringPart("email", authorEmail), new StringPart("submit", "Post"), new StringPart("comment", comment)};
MultipartRequestEntity entity = new MultipartRequestEntity(parts, post.getParams());
post.setRequestEntity(entity);
try
{
//subimit the request and get the response code
int statusCode = client.executeMethod(method);
//Check for code 200
if (statusCode != HttpStatus.SC_OK)
{
throw new HttpException("HTTP returned status code " + statusCode);
}
InputStream responseBody = post.getResponseBodyAsStream();
}
12-27-2007 06:57 PM
01-17-2008 07:19 AM
01-17-2008 11:19 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.