10-03-2009 05:31 AM
use warnings;
use strict;
use HTTP::Request::Common;
use HTTP::Request;
use HTTP::Response;
use HTTP::Headers;
use LWP::UserAgent;
use JSON;
my $alfTicket;
my $host = 'localhost';
my $port = 8080;
sub login ()
{
my ($username, $password) = @_;
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'text/x-json', Accept=>'text/x-json');
my $GetReq = HTTP::Request->new
(
'POST',
"http://$host:$port/alfresco/service/api/login",
$h,
'{"username" : "' . $username . '","password" : "' . $password . '"}'
);
my $res = $ua->request($GetReq);
# Check the outcome of the response
if ($res->is_success)
{
my $hashRef = JSON::decode_json ($res->content);
$alfTicket = $hashRef->{"data"}->{"ticket"};
return 1;
}
else
{
print 'Error (' . $res->{_rc} . ') : ' . $res->{_msg} . "\n";
print "\t" . $res->content . "\n";
return 0;
}
}
sub createSite ()
{
my ($siteInfosRef) = @_;
my $content = JSON::encode_json ($siteInfosRef);
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'text/x-json', Accept=>'text/x-json');
my $GetReq = HTTP::Request->new
(
'POST',
"http://$host:$port/alfresco/service/api/sites?alf_ticket=$alfTicket",
$h,
$content
);
print "—————————-\n";
print "Request :\n" . $GetReq->as_string . "\n";
print "—————————-\n";
my $res = $ua->request($GetReq);
if ($res->is_success)
{
%{$siteInfosRef} = %{JSON::decode_json ($res->content)};
return 1;
}
else
{
print "—————————-\n";
print "Response :\n";
print 'Error (' . $res->{_rc} . ') : ' . $res->{_msg} . "\n";
print "\t" . $res->content . "\n";
print "—————————-\n";
return 0;
}
}
print "username: ";
my $username = <STDIN>;
chomp ($username);
print "password: ";
my $password = <STDIN>;
chomp ($password);
if (&login ($username, $password))
{
print "Site creation :\n";
print "Short name : ";
my $shortName = <STDIN>;
chomp ($shortName);
print "Description : ";
my $description = <STDIN>;
chomp ($description);
print "Title : ";
my $title = <STDIN>;
chomp ($title);
my %siteInfos;
$siteInfos {"visibility"} = 'PRIVATE';
$siteInfos {"shortName"} = $shortName;
$siteInfos {"description"} = $description;
$siteInfos {"title"} = $title;
$siteInfos {"sitePreset"} = 'site-dashboard';
print "$username is logged on !\n";
if (&createSite (\%siteInfos))
{
print "$shortName created !\n";
}
else
{
print "Can't create site $shortName\n";
}
}
else
{
print "$username can't log in $host:$port\n";
}
10-04-2009 04:05 PM
10-05-2009 10:10 AM
$h->header ('Content-Type' => 'text/x-json', Accept=>'text/x-json');
$h->header ('Content-Type' => 'application/json', Accept=>'application/json');
10-05-2009 01:43 PM
10-14-2009 03:42 AM
use warnings;
use strict;
use HTTP::Request::Common;
use HTTP::Request;
use HTTP::Response;
use HTTP::Headers;
use LWP::UserAgent;
use JSON;
my $alfTicket;
my $host = 'localhost';
my $port = 8080;
sub login ()
{
my ($username, $password) = @_;
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'application/json', Accept=>'application/json');
my $GetReq = HTTP::Request->new
(
'POST',
"http://$host:$port/alfresco/service/api/login",
$h,
'{"username" : "' . $username . '","password" : "' . $password . '"}'
);
my $res = $ua->request($GetReq);
# Check the outcome of the response
if ($res->is_success)
{
my $hashRef = JSON::decode_json ($res->content);
$alfTicket = $hashRef->{"data"}->{"ticket"};
return 1;
}
else
{
print 'Error (' . $res->{_rc} . ') : ' . $res->{_msg} . "\n";
print "\t" . $res->content . "\n";
return 0;
}
}
sub createShareSite ()
{
my ($siteInfosRef) = @_;
my $content = JSON::encode_json ($siteInfosRef);
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'json', Accept=>'json');
my $req = HTTP::Request->new
(
'POST',
"http://$host:$port/share/service/modules/create-site?alf_ticket=$alfTicket",
$h,
$content
);
print "—————————-\n";
print "Request :\n" . $req->as_string . "\n";
print "—————————-\n";
my $res = $ua->request($req);
print "++++++++++++++++++++++++++++\n";
print "Response :\n" . $res->as_string . "\n";
print "++++++++++++++++++++++++++++\n";
if ($res->is_success)
{
%{$siteInfosRef} = %{JSON::decode_json ($res->content)};
return 1;
}
else
{
print "—————————-\n";
print "Response :\n";
print 'Error (' . $res->{_rc} . ') : ' . $res->{_msg} . "\n";
print "\t" . $res->content . "\n";
print "—————————-\n";
return 0;
}
}
print "username: ";
my $username = <STDIN>;
chomp ($username);
print "password: ";
my $password = <STDIN>;
chomp ($password);
if (&login ($username, $password))
{
print "Site creation :\n";
print "Short name : ";
my $shortName = <STDIN>;
chomp ($shortName);
print "Description : ";
my $description = <STDIN>;
chomp ($description);
print "Title : ";
my $title = <STDIN>;
chomp ($title);
my %siteInfos;
$siteInfos {"visibility"} = 'PRIVATE';
$siteInfos {"shortName"} = $shortName;
$siteInfos {"description"} = $description;
$siteInfos {"title"} = $title;
$siteInfos {"sitePreset"} = 'site-dashboard';
print "$username is logged on !\n";
if (&createShareSite (\%siteInfos))
{
print "$shortName created !\n";
}
else
{
print "Can't create site $shortName\n";
}
}
else
{
print "$username can't log in $host:$port\n";
}
INFO: Server startup in 100711 ms
09:24:28,928 ERROR [freemarker.runtime]
Expression success is undefined on line 2, column 17 in org/alfresco/modules/cre
ate-site.post.json.ftl.
The problematic instruction:
———-
==> ${success?string} [on line 2, column 15 in org/alfresco/modules/create-site.
post.json.ftl]
———-
Java backtrace for programmers:
———-
freemarker.core.InvalidReferenceException: Expression success is undefined on li
ne 2, column 17 in org/alfresco/modules/create-site.post.json.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.ja
va:134)
at freemarker.core.BuiltIn$stringBI._getAsTemplateModel(BuiltIn.java:361
)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.Environment.process(Environment.java:188)
at freemarker.template.Template.process(Template.java:237)
at org.alfresco.web.scripts.PresentationTemplateProcessor.process(Presen
tationTemplateProcessor.java:185)
at org.alfresco.web.scripts.AbstractWebScript.renderTemplate(AbstractWeb
Script.java:523)
at org.alfresco.web.scripts.DeclarativeWebScript.renderFormatTemplate(De
clarativeWebScript.java:241)
at org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebS
cript.java:147)
at org.alfresco.web.scripts.PresentationContainer.executeScript(Presenta
tionContainer.java:60)
at org.alfresco.web.scripts.LocalWebScriptRuntimeContainer.executeScript
(LocalWebScriptRuntimeContainer.java:186)
at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntim
e.java:262)
at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntim
e.java:139)
at org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptSe
rvlet.java:122)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
at java.lang.Thread.run(Thread.java:619)
09:24:28,959 ERROR [web.scripts.AbstractRuntime] Exception from executeScript -
redirecting to status template error: 09140000 Failed to process template org/a
lfresco/modules/create-site.post.json.ftl
org.alfresco.web.scripts.WebScriptException: 09140000 Failed to process template
org/alfresco/modules/create-site.post.json.ftl
at org.alfresco.web.scripts.PresentationTemplateProcessor.process(Presen
tationTemplateProcessor.java:189)
at org.alfresco.web.scripts.AbstractWebScript.renderTemplate(AbstractWeb
Script.java:523)
at org.alfresco.web.scripts.DeclarativeWebScript.renderFormatTemplate(De
clarativeWebScript.java:241)
at org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebS
cript.java:147)
at org.alfresco.web.scripts.PresentationContainer.executeScript(Presenta
tionContainer.java:60)
at org.alfresco.web.scripts.LocalWebScriptRuntimeContainer.executeScript
(LocalWebScriptRuntimeContainer.java:186)
at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntim
e.java:262)
at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntim
e.java:139)
at org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptSe
rvlet.java:122)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
at java.lang.Thread.run(Thread.java:619)
Caused by: freemarker.core.InvalidReferenceException: Expression success is unde
fined on line 2, column 17 in org/alfresco/modules/create-site.post.json.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.ja
va:134)
at freemarker.core.BuiltIn$stringBI._getAsTemplateModel(BuiltIn.java:361
)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:208)
at freemarker.core.Environment.process(Environment.java:188)
at freemarker.template.Template.process(Template.java:237)
at org.alfresco.web.scripts.PresentationTemplateProcessor.process(Presen
tationTemplateProcessor.java:185)
… 21 more
{
"success": ${success?string}
<#if code?exists>, "code": ${code}</#if>
<#if error?exists>, "error": "${error}"</#if>
}
01-14-2011 06:04 AM
Expression success is undefined on line 2, column 17 in org/alfresco/modules/create-site.post.json.ftl.
10-12-2012 04:03 PM
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.