Skip to content
Permalink
Browse files
Enable Cmsfv2 reading support, part 1
  • Loading branch information
ngmr committed Apr 22, 2015
1 parent 2b16c3a commit 62d9f24bf5bc99704b8764ddb2fd11ce4c451f06
Show file tree
Hide file tree
Showing 10 changed files with 948 additions and 405 deletions.
@@ -784,11 +784,40 @@ private Serializable read(CreationStrategy strategy) {
throw new MARSHAL("Illegal valuetype tag 0x" + Integer.toHexString(h.tag));
} else {
initHeader(h);
final Serializable vb = strategy.create(h);
// read_value() may be called to skip over a secondary custom valuetype.
// If so, return an internal marker object so it shows up if misused.
final Serializable result = isSecondaryCustomValuetype(h) ?
SecondaryValuetypeMarker.ATTEMPT_TO_READ_CUSTOM_DATA_AS_VALUE
: strategy.create(h);
skipChunk();
return vb;
return result;
}
}

private enum SecondaryValuetypeMarker {
ATTEMPT_TO_READ_CUSTOM_DATA_AS_VALUE
}

private boolean isSecondaryCustomValuetype(Header h) {
// there must be exactly one repository ID
if (h.ids.length != 1)
return false;

// the repository ID must start with one of the Java-to-IDL spec prefixes
final String repId = h.ids[0];
if (!(repId.startsWith("RMI:org.omg.custom.") || repId.startsWith("RMI:org.omg.customRMI.")))
return false;

// it matched enough of the rules, so treat it as a secondary custom valuetype

// there should not be a codebase (tolerate but log this)
if (h.codebase != null) {
final String fmt = "Secondary custom marshal valuetype found with non-null codebase: \"%s\", repId: \"%s\"";
logger.fine(String.format(fmt, h.codebase, repId));
}

return true;
}

//
// Remarshal each valuetype member
@@ -14,7 +14,7 @@

public enum CmsfVersion {
CMSFv1(1), CMSFv2(2);
public static final boolean ENABLED = false;
public static final boolean ENABLED = true;
private final byte value;
private final TaggedComponent tc;
private final ServiceContext sc;
@@ -0,0 +1,162 @@
package org.apache.yoko.rmi.impl;

import java.io.Externalizable;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputValidation;
import java.rmi.Remote;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Logger;

import org.omg.CORBA.portable.IndirectionException;

class ClosedObjectReader extends ObjectReader {
private static final Logger LOGGER = Logger.getLogger(ClosedObjectReader.class.getName());
public static final ClosedObjectReader INSTANCE = AccessController.doPrivileged(new PrivilegedAction<ClosedObjectReader>() {
@Override
public ClosedObjectReader run() {
try {
return new ClosedObjectReader();
} catch (IOException e) {
LOGGER.severe("Unable to create ClosedObjectInputStream singleton instance: " + e);
return null;
}
}
});

private ClosedObjectReader() throws IOException {
}

private IllegalStateException newException() {
return new IllegalStateException("Stream already closed");
}

public void close() {
}

//////////////////////////////////////
// ONLY DELEGATE METHODS BELOW HERE //
//////////////////////////////////////

public int read(byte[] b) {
throw newException();
}
public long skip(long n) {
throw newException();
}
public void mark(int readlimit) {
throw newException();
}
public void reset() {
throw newException();
}
public boolean markSupported() {
throw newException();
}
public Object readUnshared() {
throw newException();
}
public void defaultReadObject() {
throw newException();
}
public GetField readFields() {
throw newException();
}
public void registerValidation(ObjectInputValidation obj, int prio) {
throw newException();
}
public int read() {
throw newException();
}
public int read(byte[] buf, int off, int len) {
throw newException();
}
public int available() {
throw newException();
}
public boolean readBoolean() {
throw newException();
}
public byte readByte() {
throw newException();
}
public int readUnsignedByte() {
throw newException();
}
public char readChar() {
throw newException();
}
public short readShort() {
throw newException();
}
public int readUnsignedShort() {
throw newException();
}
public int readInt() {
throw newException();
}
public long readLong() {
throw newException();
}
public float readFloat() {
throw newException();
}
public double readDouble() {
throw newException();
}
public void readFully(byte[] buf) {
throw newException();
}
public void readFully(byte[] buf, int off, int len) {
throw newException();
}
public int skipBytes(int len) {
throw newException();
}
public String readLine() {
throw newException();
}
public String readUTF() {
throw newException();
}

// ObjectReader methods

void _startValue() throws IOException {
throw newException();
}
void _endValue() throws IOException {
throw newException();
}
void setCurrentValueDescriptor(ValueDescriptor desc) {
throw newException();
}
void enterRecursion() {
throw newException();
}
void exitRecursion() throws InvalidObjectException {
throw newException();
}
Object readAbstractObject() throws IndirectionException {
throw newException();
}
Object readAny() throws IndirectionException {
throw newException();
}
Object readValueObject() throws IndirectionException {
throw newException();
}
Object readValueObject(Class<?> clz) throws IndirectionException {
throw newException();
}
org.omg.CORBA.Object readCorbaObject(Class<?> type) {
throw newException();
}
Remote readRemoteObject(Class<?> type) {
throw newException();
}
void readExternal(Externalizable ext) throws IOException, ClassNotFoundException {
throw newException();
}
}
@@ -292,7 +292,7 @@ protected void _nullValue() throws IOException {

}

public class Reader extends ObjectReader {
public class Reader extends ObjectReaderBase {

int cpos;

@@ -330,15 +330,15 @@ public Object readValueObject() {
return dequeue();
}

public Object readValueObject(Class clz) {
public Object readValueObject(Class<?> clz) {
return dequeue();
}

public org.omg.CORBA.Object readCorbaObject(Class type) {
public org.omg.CORBA.Object readCorbaObject(Class<?> type) {
return (org.omg.CORBA.Object) dequeue();
}

public java.rmi.Remote readRemoteObject(Class type) {
public java.rmi.Remote readRemoteObject(Class<?> type) {
return (java.rmi.Remote) dequeue();
}

@@ -473,6 +473,14 @@ public java.lang.String readUTF() throws java.io.IOException {
return (String) dequeue();
}

@Override
protected void _startValue() throws IOException {
}

@Override
protected void _endValue() throws IOException {
}

}

}
@@ -21,15 +21,17 @@
import org.omg.CORBA.MARSHAL;
import org.omg.CORBA.portable.IndirectionException;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.ValueInputStream;

import javax.rmi.CORBA.Util;
import javax.rmi.PortableRemoteObject;

import java.io.IOException;
import java.io.Serializable;
import java.rmi.Remote;
import java.util.Map;

public class CorbaObjectReader extends ObjectReader {
public class CorbaObjectReader extends ObjectReaderBase {
final org.omg.CORBA_2_3.portable.InputStream in;

private final Map<Integer, Object> offsetMap;
@@ -92,7 +94,7 @@ public double readDouble() throws IOException {
return in.read_double();
}

@SuppressWarnings("deprecation")
@Deprecated
public String readLine() throws IOException {
final StringBuilder buf = new StringBuilder();

@@ -164,7 +166,7 @@ public Object readValueObject() throws IndirectionException {
}
}

public Object readValueObject(Class clz)
public Object readValueObject(Class<?> clz)
throws IndirectionException {
try {
return in.read_value(clz);
@@ -173,11 +175,11 @@ public Object readValueObject(Class clz)
}
}

public org.omg.CORBA.Object readCorbaObject(Class type) {
public org.omg.CORBA.Object readCorbaObject(Class<?> type) {
return in.read_Object();
}

public Remote readRemoteObject(Class type) {
public Remote readRemoteObject(Class<?> type) {
final org.omg.CORBA.Object objref = in.read_Object();
return (Remote) PortableRemoteObject.narrow(objref, type);
}
@@ -203,4 +205,14 @@ public long skip(long len) throws IOException {
public int available() throws IOException {
return in.available();
}
}

@Override
protected void _startValue() throws IOException {
((ValueInputStream)in).start_value();
}

@Override
protected void _endValue() throws IOException {
((ValueInputStream)in).end_value();
}
}

0 comments on commit 62d9f24

Please sign in to comment.