use of org.freeswitch.esl.client.transport.message.EslHeaders.Name in project bigbluebutton by bigbluebutton.
the class EslFrameDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, State state) throws Exception {
log.trace("decode() : state [{}]", state);
switch(state) {
case READ_HEADER:
if (currentMessage == null) {
currentMessage = new EslMessage();
}
/*
* read '\n' terminated lines until reach a single '\n'
*/
boolean reachedDoubleLF = false;
while (!reachedDoubleLF) {
// this will read or fail
String headerLine = readToLineFeedOrFail(buffer, maxHeaderSize);
log.debug("read header line [{}]", headerLine);
if (!headerLine.isEmpty()) {
// split the header line
String[] headerParts = HeaderParser.splitHeader(headerLine);
Name headerName = Name.fromLiteral(headerParts[0]);
if (headerName == null) {
if (treatUnknownHeadersAsBody) {
// cache this 'header' as a body line <-- useful for Outbound client mode
currentMessage.addBodyLine(headerLine);
} else {
throw new IllegalStateException("Unhandled ESL header [" + headerParts[0] + ']');
}
}
currentMessage.addHeader(headerName, headerParts[1]);
} else {
reachedDoubleLF = true;
}
// do not read in this line again
checkpoint();
}
// have read all headers - check for content-length
if (currentMessage.hasContentLength()) {
checkpoint(State.READ_BODY);
log.debug("have content-length, decoding body ..");
return null;
} else {
// end of message
checkpoint(State.READ_HEADER);
// send message upstream
EslMessage decodedMessage = currentMessage;
currentMessage = null;
return decodedMessage;
}
case READ_BODY:
/*
* read the content-length specified
*/
int contentLength = currentMessage.getContentLength();
ChannelBuffer bodyBytes = buffer.readBytes(contentLength);
log.debug("read [{}] body bytes", bodyBytes.writerIndex());
// most bodies are line based, so split on LF
while (bodyBytes.readable()) {
String bodyLine = readLine(bodyBytes, contentLength);
log.debug("read body line [{}]", bodyLine);
currentMessage.addBodyLine(bodyLine);
}
// end of message
checkpoint(State.READ_HEADER);
// send message upstream
EslMessage decodedMessage = currentMessage;
currentMessage = null;
return decodedMessage;
default:
throw new Error("Illegal state: [" + state + ']');
}
}
use of org.freeswitch.esl.client.transport.message.EslHeaders.Name in project bigbluebutton by bigbluebutton.
the class ClientTest method sofia_contact.
@Test
public void sofia_contact() {
Client client = new Client();
try {
client.connect(host, port, password, 2);
} catch (InboundConnectionFailure e) {
log.error("Connect failed", e);
return;
}
EslMessage response = client.sendSyncApiCommand("sofia_contact", "internal/102@192.168.100.201");
log.info("Response to 'sofia_contact': [{}]", response);
for (Entry<Name, String> header : response.getHeaders().entrySet()) {
log.info(" * header [{}]", header);
}
for (String bodyLine : response.getBodyLines()) {
log.info(" * body [{}]", bodyLine);
}
client.close();
}
Aggregations