use of java.io.StreamCorruptedException in project geode by apache.
the class TcpServer method processRequest.
/**
* fix for bug 33711 - client requests are spun off to another thread for processing. Requests are
* synchronized in processGossip.
*/
private void processRequest(final Socket sock) {
executor.execute(() -> {
long startTime = DistributionStats.getStatTime();
DataInputStream input = null;
Object request, response;
try {
socketCreator.configureServerSSLSocket(sock);
sock.setSoTimeout(READ_TIMEOUT);
try {
input = new DataInputStream(sock.getInputStream());
} catch (StreamCorruptedException e) {
// Some garbage can be left on the socket stream
// if a peer disappears at exactly the wrong moment.
log.debug("Discarding illegal request from " + (sock.getInetAddress().getHostAddress() + ":" + sock.getPort()), e);
return;
}
int gossipVersion = readGossipVersion(sock, input);
short versionOrdinal;
if (gossipVersion <= getCurrentGossipVersion() && GOSSIP_TO_GEMFIRE_VERSION_MAP.containsKey(gossipVersion)) {
// Create a versioned stream to remember sender's GemFire version
versionOrdinal = (short) GOSSIP_TO_GEMFIRE_VERSION_MAP.get(gossipVersion);
} else {
// Close the socket. We can not accept requests from a newer version
try {
sock.getOutputStream().write("unknown protocol version".getBytes());
sock.getOutputStream().flush();
} catch (IOException e) {
log.debug("exception in sending reply to process using unknown protocol " + gossipVersion, e);
}
sock.close();
return;
}
if (Version.GFE_71.compareTo(versionOrdinal) <= 0) {
// Recent versions of TcpClient will send the version ordinal
versionOrdinal = input.readShort();
}
if (log.isDebugEnabled() && versionOrdinal != Version.CURRENT_ORDINAL) {
log.debug("Locator reading request from " + sock.getInetAddress() + " with version " + Version.fromOrdinal(versionOrdinal, false));
}
input = new VersionedDataInputStream(input, Version.fromOrdinal(versionOrdinal, false));
request = DataSerializer.readObject(input);
if (log.isDebugEnabled()) {
log.debug("Locator received request " + request + " from " + sock.getInetAddress());
}
if (request instanceof ShutdownRequest) {
shuttingDown = true;
// Don't call shutdown from within the worker thread, see java bug #6576792.
// Closing the socket will cause our acceptor thread to shutdown the executor
this.serverSocketPortAtClose = srv_sock.getLocalPort();
srv_sock.close();
response = new ShutdownResponse();
} else if (request instanceof InfoRequest) {
response = handleInfoRequest(request);
} else if (request instanceof VersionRequest) {
response = handleVersionRequest(request);
} else {
response = handler.processRequest(request);
}
handler.endRequest(request, startTime);
startTime = DistributionStats.getStatTime();
if (response != null) {
DataOutputStream output = new DataOutputStream(sock.getOutputStream());
if (versionOrdinal != Version.CURRENT_ORDINAL) {
output = new VersionedDataOutputStream(output, Version.fromOrdinal(versionOrdinal, false));
}
DataSerializer.writeObject(response, output);
output.flush();
}
handler.endResponse(request, startTime);
} catch (EOFException ignore) {
// client went away - ignore
} catch (CancelException ignore) {
// ignore
} catch (ClassNotFoundException ex) {
String sender = null;
if (sock != null) {
sender = sock.getInetAddress().getHostAddress();
}
log.info("Unable to process request from " + sender + " exception=" + ex.getMessage());
} catch (Exception ex) {
String sender = null;
if (sock != null) {
sender = sock.getInetAddress().getHostAddress();
}
if (ex instanceof IOException) {
// log with severe.
if (!sock.isClosed()) {
log.info("Exception in processing request from " + sender, ex);
}
} else {
log.fatal("Exception in processing request from " + sender, ex);
}
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
throw err;
} catch (Throwable ex) {
SystemFailure.checkFailure();
String sender = null;
if (sock != null) {
sender = sock.getInetAddress().getHostAddress();
}
try {
log.fatal("Exception in processing request from " + sender, ex);
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
throw err;
} catch (Throwable t) {
SystemFailure.checkFailure();
t.printStackTrace();
}
} finally {
try {
sock.close();
} catch (IOException ignore) {
// ignore
}
}
});
}
use of java.io.StreamCorruptedException in project jdk8u_jdk by JetBrains.
the class StreamRemoteCall method getResultStream.
/**
* Returns an output stream (may put out header information
* relating to the success of the call).
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @exception StreamCorruptedException If result stream previously
* acquired
* @exception IOException For any other problem with I/O.
*/
public ObjectOutput getResultStream(boolean success) throws IOException {
/* make sure result code only marshaled once. */
if (resultStarted)
throw new StreamCorruptedException("result already in progress");
else
resultStarted = true;
// write out return header
// return header, part 1 (read by Transport)
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
// transport op
wr.writeByte(TransportConstants.Return);
// creates a MarshalOutputStream
getOutputStream(true);
// return header, part 2 (read by client-side RemoteCall)
if (//
success)
out.writeByte(TransportConstants.NormalReturn);
else
out.writeByte(TransportConstants.ExceptionalReturn);
// write id for gcAck
out.writeID();
return out;
}
use of java.io.StreamCorruptedException in project midpoint by Evolveum.
the class PropertyComplexValueFilterType method copyOf.
/**
* Creates and returns a deep copy of a given {@code Serializable}.
*
* @param serializable
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
*/
private static Serializable copyOf(final Serializable serializable) {
// CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
if (serializable != null) {
try {
final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
out.writeObject(serializable);
out.close();
final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
final Serializable copy = ((Serializable) in.readObject());
in.close();
return copy;
} catch (SecurityException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (ClassNotFoundException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (InvalidClassException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (NotSerializableException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (StreamCorruptedException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (OptionalDataException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (IOException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
}
}
return null;
}
use of java.io.StreamCorruptedException in project midpoint by Evolveum.
the class QueryType method copyOf.
/**
* Creates and returns a deep copy of a given {@code Serializable}.
*
* @param serializable
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
*/
private static Serializable copyOf(final Serializable serializable) {
// CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
if (serializable != null) {
try {
final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
out.writeObject(serializable);
out.close();
final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
final Serializable copy = ((Serializable) in.readObject());
in.close();
return copy;
} catch (SecurityException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (ClassNotFoundException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (InvalidClassException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (NotSerializableException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (StreamCorruptedException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (OptionalDataException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (IOException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
}
}
return null;
}
use of java.io.StreamCorruptedException in project jdk8u_jdk by JetBrains.
the class Path2D method readObject.
final void readObject(java.io.ObjectInputStream s, boolean storedbl) throws java.lang.ClassNotFoundException, java.io.IOException {
s.defaultReadObject();
// The subclass calls this method with the storage type that
// they want us to use (storedbl) so we ignore the storage
// method hint from the stream.
s.readByte();
int nT = s.readInt();
int nC = s.readInt();
try {
setWindingRule(s.readByte());
} catch (IllegalArgumentException iae) {
throw new java.io.InvalidObjectException(iae.getMessage());
}
pointTypes = new byte[(nT < 0) ? INIT_SIZE : nT];
if (nC < 0) {
nC = INIT_SIZE * 2;
}
if (storedbl) {
((Path2D.Double) this).doubleCoords = new double[nC];
} else {
((Path2D.Float) this).floatCoords = new float[nC];
}
PATHDONE: for (int i = 0; nT < 0 || i < nT; i++) {
boolean isdbl;
int npoints;
byte segtype;
byte serialtype = s.readByte();
switch(serialtype) {
case SERIAL_SEG_FLT_MOVETO:
isdbl = false;
npoints = 1;
segtype = SEG_MOVETO;
break;
case SERIAL_SEG_FLT_LINETO:
isdbl = false;
npoints = 1;
segtype = SEG_LINETO;
break;
case SERIAL_SEG_FLT_QUADTO:
isdbl = false;
npoints = 2;
segtype = SEG_QUADTO;
break;
case SERIAL_SEG_FLT_CUBICTO:
isdbl = false;
npoints = 3;
segtype = SEG_CUBICTO;
break;
case SERIAL_SEG_DBL_MOVETO:
isdbl = true;
npoints = 1;
segtype = SEG_MOVETO;
break;
case SERIAL_SEG_DBL_LINETO:
isdbl = true;
npoints = 1;
segtype = SEG_LINETO;
break;
case SERIAL_SEG_DBL_QUADTO:
isdbl = true;
npoints = 2;
segtype = SEG_QUADTO;
break;
case SERIAL_SEG_DBL_CUBICTO:
isdbl = true;
npoints = 3;
segtype = SEG_CUBICTO;
break;
case SERIAL_SEG_CLOSE:
isdbl = false;
npoints = 0;
segtype = SEG_CLOSE;
break;
case SERIAL_PATH_END:
if (nT < 0) {
break PATHDONE;
}
throw new StreamCorruptedException("unexpected PATH_END");
default:
throw new StreamCorruptedException("unrecognized path type");
}
needRoom(segtype != SEG_MOVETO, npoints * 2);
if (isdbl) {
while (--npoints >= 0) {
append(s.readDouble(), s.readDouble());
}
} else {
while (--npoints >= 0) {
append(s.readFloat(), s.readFloat());
}
}
pointTypes[numTypes++] = segtype;
}
if (nT >= 0 && s.readByte() != SERIAL_PATH_END) {
throw new StreamCorruptedException("missing PATH_END");
}
}
Aggregations