--comp-name-1=http
--comp-class-1=tigase.http.HttpMessageReceiver
http/ports[i]=8080
http/api-keys[s]=open_access
#http/8080/domain=xmpp.iyw
http/api-key=open_access
http/server-class[s]=tigase.http.jetty.JettyStandaloneHttpServer
//Stream.groovy用于发送消息的脚本
class Stream extends tigase.http.rest.Handler {
public Stream() {
/**
*description = [
* regex : "/{to_jid}",
* POST : [ info:'Send XMPP stanza', description: """Sends passed HTTP content as XMPP stanza."""]]
*/
regex = /\/(.*)/
isAsync = true
decodeContent = false
//requireRole 可是设置未 null 、user 、admin ,如果这是了 非 null,在调用http发送消息时,需要对用户进行认证,我这里不需要认证直接发送,所以设置未null
requiredRole = null
//requireRole设置未null后 需要去掉user参数 ,注释掉
execPost = { Service service, callback, /*user,*/ HttpServletRequest request, to ->
char[] data = request.getReader().getText()?.toCharArray();
if (data == null || data.length == 0) {
callback({ req, HttpServletResponse resp ->
resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
})
return;
}
SimpleParser parser = SingletonFactory.getParserInstance();
DomBuilderHandler domHandler = new DomBuilderHandler();
parser.parse(domHandler, data, 0, data.length);
Element packetEl = domHandler.getParsedElements().poll();
if (packetEl == null) {
callback({ req, HttpServletResponse resp ->
resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
})
return;
}
if (to != null) {
to = to.trim();
if (!to.isEmpty()) {
packetEl.setAttribute("to", to);
}
}
Packet packet = Packet.packetInstance(packetEl);
def responseHandler = (packet.getElemName() == "iq" && packet.getAttribute("from") == null) ? { Packet result ->
callback({ req, HttpServletResponse resp ->
def outBytes = result.getElement().toString().getBytes();
resp.setContentType("application/xml");
resp.setContentLength(outBytes.length);
resp.getOutputStream().write(outBytes);
});
} : null;
service.sendPacket(packet, null, responseHandler);
if (responseHandler == null) {
callback("");
}
}
}
}