public void send(Object replyTo, short rval, int rcode, byte[] data,
int len, int correlationId, int flags, int ttl, String type,
String subtype) throws ConnectionException {
if (closed) {
throw new ConnectionException(Connection.TPEPROTO, "Sender closed");
}
if (data == null) {
data = new byte[1];
len = 1;
}
if (len < 1) {
throw new ConnectionException(Connection.TPEINVAL,
"Length of buffer must be greater than 0");
}
log.debug("Sender sending: " + destinationName);
Message message = new Message();
message.setCommand("SEND");
Map<String, String> headers = new HashMap<String, String>();
try {
String ior = JtsTransactionImple.getTransactionIOR();
if (ior != null) {
headers.put("messagecontrol", ior);
log.debug("Sender sending IOR: " + ior);
}
} catch (Exception e) {
throw new ConnectionException(Connection.TPETRAN, e.getMessage());
}
if (replyTo != null) {
log.debug("Reply to: " + replyTo);
headers.put("messagereplyto", (String) replyTo);
}
headers.put("servicename", destinationName);
headers.put("messagecorrelationId", String.valueOf(correlationId));
headers.put("messageflags", String.valueOf(flags));
headers.put("messagerval", String.valueOf(rval));
headers.put("messagercode", String.valueOf(rcode));
headers.put("messagetype", type == null ? "" : type);
headers.put("messagesubtype", subtype == null ? "" : subtype);
if (ttl > 0) {
headers.put("expires", String.valueOf(ttl));
log.debug("EXPIRES: " + headers.get("expires"));
}
synchronized (StompSenderImpl.class) {
headers.put("receipt", "send-J-" + counter);
log.debug("RECEIPT: " + headers.get("receipt"));
counter++;
}
headers.put("destination", destinationName);
message.setHeaders(headers);
byte[] toSend = new byte[len];
if (data != null) {
int min = Math.min(toSend.length, data.length);
System.arraycopy(data, 0, toSend, 0, min);
headers.put("content-length", String.valueOf(toSend.length));
}
message.setBody(toSend);
Message ack;
try {
management.send(message, this.outputStream);
ack = management.receive(this.inputStream);
} catch (IOException e) {
throw new ConnectionException(Connection.TPEOS, e.getMessage());
}
if (!ack.getCommand().equals("RECEIPT")) {
log.error(new String(ack.getBody()));
throw new ConnectionException(Connection.TPENOENT, new String(
ack.getBody()));
}
log.debug("sent message");
}