Skip to content
Permalink
Browse files
Enhance UnknownExceptionInfo unmarshalling handling
  • Loading branch information
ngmr committed Jun 3, 2015
1 parent 7b46aa0 commit 628e87edfe26ad742755c713f5c56b2d30509332
Showing 2 changed files with 57 additions and 37 deletions.
@@ -17,19 +17,10 @@

package org.apache.yoko.orb.OB;

import static org.apache.yoko.orb.OB.CodeSetDatabase.UTF16;
import static org.apache.yoko.orb.OCI.GiopVersion.GIOP1_2;

import java.util.Vector;

import org.apache.yoko.orb.OCI.Buffer;
import org.apache.yoko.orb.OCI.GiopVersion;
import org.omg.CORBA.MARSHAL;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.UNKNOWN;
import org.omg.CORBA.portable.UnknownException;
import org.omg.IOP.ServiceContext;
import org.omg.IOP.UnknownExceptionInfo;

public class Downcall {
//
@@ -557,35 +548,10 @@ private void setSystemExceptionImpl(org.omg.CORBA.SystemException ex) {
Assert._OB_assert(responseExpected_);
Assert._OB_assert(ex_ == null);
state_ = DowncallStateSystemException;
ex_ = convertToUnknownExceptionIfAppropriate(ex);
ex_ = ex;
logger_.debug("Received system exception", ex);
}

private SystemException convertToUnknownExceptionIfAppropriate(org.omg.CORBA.SystemException ex) {
if (ex instanceof UNKNOWN) {
for (ServiceContext sc : replySCL_) {
if (sc.context_id == UnknownExceptionInfo.value) {
final byte[] data = sc.context_data;
CodeConverters codeConverters = new CodeConverters();
codeConverters.outputWcharConverter = CodeSetDatabase.instance().getConverter(UTF16, UTF16);
Buffer buf = new Buffer(data, data.length);
try (org.apache.yoko.orb.CORBA.InputStream in =
new org.apache.yoko.orb.CORBA.InputStream(buf, 0, false, codeConverters, GIOP1_2)) {
in._OB_readEndian();
Throwable t = (Throwable) in.read_value();
UnknownException x = new UnknownException(t);
x.completed = ex.completed;
x.minor = ex.minor;
return x;
} catch (Exception e) {
throw (MARSHAL)(new MARSHAL(e.getMessage())).initCause(e);
}
}
}
}
return ex;
}

public void setSystemException(org.omg.CORBA.SystemException ex) {
if (stateMonitor_ != null) {
synchronized (stateMonitor_) {
@@ -17,10 +17,21 @@

package org.apache.yoko.orb.OB;

import static org.apache.yoko.orb.OCI.GiopVersion.GIOP1_2;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.yoko.orb.CORBA.InputStream;
import org.apache.yoko.orb.OB.Logger;
import org.apache.yoko.orb.OCI.Buffer;
import org.apache.yoko.orb.OCI.GiopVersion;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.UNKNOWN;
import org.omg.CORBA.portable.UnknownException;
import org.omg.IOP.ServiceContext;
import org.omg.IOP.UnknownExceptionInfo;
import org.omg.SendingContext.CodeBase;

abstract public class GIOPConnection implements DowncallEmitter, UpcallReturn {
@@ -557,8 +568,8 @@ synchronized protected void processReply(GIOPIncomingMessage msg) {

case org.omg.GIOP.ReplyStatusType_1_2._SYSTEM_EXCEPTION: {
try {
org.omg.CORBA.SystemException ex = Util
.unmarshalSystemException(in);
org.omg.CORBA.SystemException ex = Util.unmarshalSystemException(in);
ex = convertToUnknownExceptionIfAppropriate(ex, in, scl.value);
down.setSystemException(ex);
} catch (org.omg.CORBA.SystemException ex) {
processException(State.Error, ex, false);
@@ -614,6 +625,49 @@ synchronized protected void processReply(GIOPIncomingMessage msg) {
}
}

private SystemException convertToUnknownExceptionIfAppropriate(org.omg.CORBA.SystemException ex, InputStream is,
ServiceContext[] scl) {
if (ex instanceof UNKNOWN) {
for (ServiceContext sc : scl) {
if (sc.context_id == UnknownExceptionInfo.value) {
final byte[] data = sc.context_data;
Buffer buf = new Buffer(data, data.length);
try (org.apache.yoko.orb.CORBA.InputStream in =
new org.apache.yoko.orb.CORBA.InputStream(buf, 0, false, is._OB_codeConverters(), GIOP1_2)) {
try {
in.__setSendingContextRuntime(is.__getSendingContextRuntime());
in.__setCodeBase(is.__getCodeBase());
in._OB_readEndian();
Throwable t = (Throwable) in.read_value();
UnknownException x = new UnknownException(t);
x.completed = ex.completed;
x.minor = ex.minor;
return x;
} catch (Exception e) {
final String dump = in.dumpData();
final int curPos = in.buf_.pos();
in.buf_.pos(0);
final String fullDump = in.dumpData();
in.buf_.pos(curPos);
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)) {
e.printStackTrace(pw);
logger.severe(String.format("%s:%n%s:%n%s%n%s:%n%s%n%s:%n%s",
"Exception reading UnknownExceptionInfo service context",
"Remaining data", dump, "Full data", fullDump,
"Exception thrown", sw.toString()));
}
}
} catch (IOException e) {
//ignore IOException from AutoCloseable.close()
}
break;
}
}
}
return ex;
}

private void assignSendingContextRuntime(InputStream in, ServiceContext[] scl) {
if (serverRuntime_ == null) {
serverRuntime_

0 comments on commit 628e87e

Please sign in to comment.