use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class StreamMessageImpl method reset.
/**
* Put the message body in read-only mode, and reposition the stream to the beginning.
*
* @exception JMSException if JMS fails to reset the message due to some internal JMS error.
* @exception MessageFormatException if message has an invalid format
*/
@Override
public void reset() throws JMSException {
try {
if (bufferIsDirty) {
objectOutputStream.flush();
messageBody = byteArrayOutputStream.toByteArray();
objectOutputStream.close();
byteArrayOutputStream.close();
}
if (messageBody != null) {
byteArrayInputStream = new ByteArrayInputStream(messageBody);
objectInputStream = new FilteringObjectInputStream(byteArrayInputStream);
}
} catch (Exception e) {
ExceptionHandler.handleException(e, AdministeredObject.cr.X_MESSAGE_RESET);
}
setBufferIsDirty(false);
setMessageReadMode(true);
// reset flag
byteArrayReadState = false;
notYetProcessedPrimitiveObject = null;
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class Reader method run.
@Override
public void run() {
try {
ObjectInputStream dis = new FilteringObjectInputStream(is);
int n = 0;
while (MAX < 0 || n < MAX) {
RandomBytes rb = (RandomBytes) dis.readObject();
boolean valid = rb.isValid();
int seq = rb.getSequence();
if (seq != n) {
System.out.println("#### PACKET OUT OF SEQUENCE ####");
return;
}
if (VERBOSITY > 0) {
System.out.println("#### Received packet #" + seq);
}
if (VERBOSITY > 1) {
byte[] tmp = rb.getData();
int len = tmp.length > 64 ? 64 : tmp.length;
System.out.println("Bytes = " + new String(tmp, 1, len - 1));
System.out.println("Length = " + (tmp.length - 1));
System.out.println("Checksum = " + rb.getChecksum());
System.out.println("Computed checksum = " + RandomBytes.computeChecksum(tmp));
System.out.println("rb.isValid() = " + valid);
System.out.println();
}
if (!valid) {
System.out.println("#### CHECKSUM ERROR DETECTED ####");
return;
}
n++;
if (n % 100 == 0) {
System.out.println("#### Free memory = " + Runtime.getRuntime().freeMemory());
System.out.println("#### Total memory = " + Runtime.getRuntime().totalMemory());
System.out.println();
}
}
} catch (Exception e) {
e.printStackTrace();
}
try {
s.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("#### Reader exiting...");
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class AdminCmdHandler method getBodyObject.
/**
* Get object from the body of a packet
*/
protected Object getBodyObject(Packet pkt) {
ObjectInputStream ois = null;
Object o = null;
// Extract the object from the message body
try {
ois = new FilteringObjectInputStream(pkt.getMessageBodyStream());
o = ois.readObject();
} catch (Exception e) {
// Programing error. Do not need to localize
logger.logStack(Logger.ERROR, rb.E_INTERNAL_BROKER_ERROR, this.getClass().getName() + " : Got exception reading body of administration message:\n" + e + "\n" + pkt.dumpPacketString(), e);
} finally {
if (ois != null) {
try {
ois.close();
} catch (Exception e) {
/* ignore */
}
}
}
return o;
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class JDBCTxLogImpl method logHeuristicBranch.
/**
* @param bxid the branch xid to update
* @param lr the LogRecord to identify the record to update
*/
@Override
public void logHeuristicBranch(BranchXid bxid, LogRecord lr) throws Exception {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "jdbcTxLog: log branch heuristic decision " + lr);
}
final GlobalXid gxid = lr.getGlobalXid();
final BranchXid branchXid = bxid;
final LogRecord newlr = lr;
super.checkClosedAndSetInProgress();
try {
UpdateOpaqueDataCallback callback = new UpdateOpaqueDataCallback() {
@Override
public Object update(Object currlr) throws Exception {
ObjectInputStream ois = new FilteringObjectInputStream(new ByteArrayInputStream((byte[]) currlr));
LogRecord oldlr = (LogRecord) ois.readObject();
if (oldlr == null) {
throw new IllegalArgumentException("Unexpected null current log record for " + gxid);
}
if (!oldlr.getGlobalXid().equals(gxid)) {
throw new IllegalArgumentException("Unexpected global xid " + oldlr.getGlobalXid() + " from store, expected:" + gxid);
}
ois.close();
if (oldlr.getBranchDecision(branchXid) == newlr.getBranchDecision(branchXid)) {
return currlr;
}
oldlr.setBranchDecision(branchXid, newlr.getBranchDecision(branchXid));
return oldlr;
}
};
_store.updateTMLogRecord(gxid.toString(), lr.toBytes(), _jmsbridge, callback, true, true, _logger);
} finally {
super.setInProgress(false);
}
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class BaseTransaction method readFromBytes.
// io methods to read and write to byte array
public void readFromBytes(byte[] data) throws IOException, BrokerException {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
readData(dis);
int objectBodySize = dis.readInt();
byte[] objectBody = new byte[objectBodySize];
dis.read(objectBody);
ByteArrayInputStream bais2 = new ByteArrayInputStream(objectBody);
ObjectInputStream ois = new FilteringObjectInputStream(bais2);
try {
readObjects(ois);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ois.close();
bais2.close();
dis.close();
bais.close();
}
Aggregations