Hi there,
i actually run into the need to determine the port of the AGIserver, in
which an java class is running. Which is necessary because i want to
initiate call by the manager api and connect these calls directly to an
AGI. The other way to connect to an extension or an local channel is not
flexible enough.
so, i want to do something like this:
originateAction.setChannel("Capi/g1/" + invite");
originateAction.setApplication("AGI");
originateAction.setData("agi://localhost:"+port+"/anotherAGI.agi?param1="+value1+"¶m2="+value2+"¶m3="+value3);
if i hardcode the port, and after that move the server to another
instance, which runs on an different channel, i must change the code :(
so, i wrote a little method which determines the port:
private String getPort(String requestURL) {
// agi://localhost:4574/theagi.agi
Pattern p = Pattern.compile(":(\\d+)/");
Matcher matcher = p.matcher(requestURL);
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
this assumes the the agi is executed in the format shown in the comment.
making the scripts independent of the port, allows to run several
instances of the scripts on the same machine. this comes handy for
development purposes, eg run the scripts under development under port
5000 and the ready to use scripts under 6000 without problems.
the solution above suits my needs, but still the method resides in the
my agiscript class. a solution that makes all agiscript capable of
asking for the port number would be nicer.
there even maybe a way to let the server itself annouce its portnumber,
and not building on the niceness of the user to include it in the agi://
line.
what do you think ?? is there any need for others to do so, than me ?? :)
have a nice week-end
tobias wolf
p.s. i hope i have not overlooked a ready to use solution in the current
api of asterisk-java :) but it didn't find a .getPort method in the
javadocs ...
|