[teiid-commits] teiid SVN: r2013 - in trunk: client/src/main/java/org/teiid/adminapi and 12 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Mar 31 17:44:18 EDT 2010


Author: shawkins
Date: 2010-03-31 17:44:15 -0400 (Wed, 31 Mar 2010)
New Revision: 2013

Added:
   trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java
   trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java
Removed:
   trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/FakeCryptor.java
   trunk/jboss-integration/src/test/java/com/
Modified:
   trunk/client/src/main/java/org/teiid/adminapi/Admin.java
   trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
   trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
   trunk/client/src/main/java/org/teiid/net/socket/Message.java
   trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java
   trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectDecoderInputStream.java
   trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectEncoderOutputStream.java
   trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/BasicCryptor.java
   trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/Cryptor.java
   trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/NullCryptor.java
   trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/TestEncryptDecrypt.java
   trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
   trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java
   trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
   trunk/pom.xml
   trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java
   trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
   trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java
   trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java
   trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java
   trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
Log:
TEIID-943 adding streaming from server to client using the same method as client to server.  

Modified: trunk/client/src/main/java/org/teiid/adminapi/Admin.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/Admin.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/client/src/main/java/org/teiid/adminapi/Admin.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -22,7 +22,8 @@
 
 package org.teiid.adminapi;
 
-import java.net.URL;
+import java.io.InputStream;
+import java.io.Reader;
 import java.util.Collection;
 import java.util.Properties;
 import java.util.Set;
@@ -60,10 +61,10 @@
      * Add Connector Type, will import Connector Type from a file
      *
      * @param name  of the Connector Type to add
-     * @param URL URL to RAR file
+     * @param rar RAR file
      * @throws AdminException  if there's a system error.
      */
-    void addConnectorType(String name, URL rarURL) throws AdminException;
+    void addConnectorType(String name, InputStream rar) throws AdminException;
 
     /**
      * Delete Connector Type from Next Configuration
@@ -81,7 +82,7 @@
      * @return InputStream of contents of the rar file
      * @throws AdminException if there's a system error.
      */
-    byte[] exportConnectorType(String name) throws AdminException;    
+    InputStream exportConnectorType(String name) throws AdminException;    
 
     /**
      * Deploy a {@link ConnectorBinding} to Configuration
@@ -106,21 +107,21 @@
      * Export a {@link ConnectorBinding} to character Array in XML format
      *
      * @param deployedName the unique identifier for a {@link ConnectorBinding}.
-     * @return character Array in XML format
+     * @return Reader in XML format
      * @throws AdminException
      *             if there's a system error.
      */
-    char[] exportConnectorBinding(String deployedName) throws AdminException;    
+    Reader exportConnectorBinding(String deployedName) throws AdminException;    
 
     /**
      * Deploy a {@link VDB} file.
      * @param name  Name of the VDB file to save under
-     * @param URL 	VDB file location.
+     * @param VDB 	VDB.
      * @throws AdminException
      *             if there's a system error.
      * @return the {@link VDB} representing the current property values and runtime state.
      */
-    public void deployVDB(String fileName, URL vdbURL) throws AdminException;
+    public void deployVDB(String fileName, InputStream vdb) throws AdminException;
     
     
     /**
@@ -139,7 +140,7 @@
      * @return InputStream of the VDB
      * @throws AdminException if there's a system error.
      */
-    byte[] exportVDB(String vdbName, int vdbVersion) throws AdminException;    
+    InputStream exportVDB(String vdbName, int vdbVersion) throws AdminException;    
     
     /**
      * Set a process level property. 
@@ -354,4 +355,5 @@
      * Closes the admin connection
      */
     void close();
+
 }

Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -26,7 +26,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Properties;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -123,11 +122,6 @@
     }    
 	
 	@Override
-    public Properties getProperties() {
-        return new Properties(super.getProperties());
-    }		
-	
-	@Override
 	@XmlElement(name = "property", type = PropertyMetadata.class)
 	@ManagementProperty(description = "Model Properties", managed=true)
 	public List<PropertyMetadata> getJAXBProperties(){

Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -228,11 +228,6 @@
 		return list;
 	}
 	
-	@Override
-    public Properties getProperties() {
-        return super.getProperties();
-    }		
-	
 	// This one manages the JAXB binding
 	@Override
 	@XmlElement(name = "property", type = PropertyMetadata.class)

Modified: trunk/client/src/main/java/org/teiid/net/socket/Message.java
===================================================================
--- trunk/client/src/main/java/org/teiid/net/socket/Message.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/client/src/main/java/org/teiid/net/socket/Message.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -31,24 +31,24 @@
 
 public class Message implements Externalizable {
 	public static final long serialVersionUID = 1063704220782714098L;
-	private Serializable contents;
+	private Object contents;
 	private Serializable messageKey;
 
 	public String toString() {
 		return "MessageHolder: contents=" + contents; //$NON-NLS-1$
 	}
 
-	public void setContents(Serializable contents) {
+	public void setContents(Object contents) {
 		this.contents = contents;
 	}
 
-	public Serializable getContents() {
+	public Object getContents() {
 		return contents;
 	}
 
 	public void readExternal(ObjectInput in) throws IOException,
 			ClassNotFoundException {
-		this.contents = (Serializable) in.readObject();
+		this.contents = in.readObject();
 		this.messageKey = (Serializable) in.readObject();
 	}
 

Modified: trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java
===================================================================
--- trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -60,7 +60,7 @@
     static final int TYPE_PRIMITIVE = 0;
     static final int TYPE_NON_PRIMITIVE = 1;
     
-    private List<InputStream> lobs = new LinkedList<InputStream>();
+    private List<InputStream> streams = new LinkedList<InputStream>();
     private List<StreamFactoryReference> references = new LinkedList<StreamFactoryReference>();
     
     public CompactObjectOutputStream(OutputStream out) throws IOException {
@@ -68,8 +68,8 @@
         enableReplaceObject(true);
     }
     
-    public List<InputStream> getLobs() {
-		return lobs;
+    public List<InputStream> getStreams() {
+		return streams;
 	}
     
     public List<StreamFactoryReference> getReferences() {
@@ -99,27 +99,27 @@
     	}
 		try {
 	    	if (obj instanceof Reader) {
-	    		lobs.add(new ReaderInputStream((Reader)obj, Charset.forName(Streamable.ENCODING)));
+	    		streams.add(new ReaderInputStream((Reader)obj, Charset.forName(Streamable.ENCODING)));
 	    		StreamFactoryReference sfr = new SerializableReader();
 	    		references.add(sfr);
 	    		return sfr;
 	    	} else if (obj instanceof InputStream) {
-	    		lobs.add((InputStream)obj);
+	    		streams.add((InputStream)obj);
 	    		StreamFactoryReference sfr = new SerializableInputStream();
 	    		references.add(sfr);
 	    		return sfr;
 	    	} else if (obj instanceof SQLXML) {
-				lobs.add(new ReaderInputStream(((SQLXML)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING)));
+				streams.add(new ReaderInputStream(((SQLXML)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING)));
 	    		StreamFactoryReference sfr = new SQLXMLImpl((InputStreamFactory)null);
 	    		references.add(sfr);
 	    		return sfr;
 	    	} else if (obj instanceof Clob) {
-	    		lobs.add(new ReaderInputStream(((Clob)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING)));
+	    		streams.add(new ReaderInputStream(((Clob)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING)));
 	    		StreamFactoryReference sfr = new ClobImpl(null, -1);
 	    		references.add(sfr);
 	    		return sfr;
 	    	} else if (obj instanceof Blob) {
-	    		lobs.add(((Blob)obj).getBinaryStream());
+	    		streams.add(((Blob)obj).getBinaryStream());
 	    		StreamFactoryReference sfr = new BlobImpl(null);
 	    		references.add(sfr);
 	    		return sfr;

Modified: trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectDecoderInputStream.java
===================================================================
--- trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectDecoderInputStream.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectDecoderInputStream.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -22,14 +22,26 @@
  */
 package org.teiid.netty.handler.codec.serialization;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInput;
 import java.io.ObjectInputStream;
+import java.io.OutputStream;
 import java.io.StreamCorruptedException;
+import java.util.List;
 
+import com.metamatrix.common.types.InputStreamFactory;
+import com.metamatrix.common.types.Streamable;
+import com.metamatrix.common.types.InputStreamFactory.StreamFactoryReference;
+import com.metamatrix.core.util.ExternalizeUtil;
+
 /**
  * An {@link ObjectInput} which is interoperable with {@link ObjectEncoder}
  * and {@link ObjectEncoderOutputStream}.
@@ -49,6 +61,11 @@
     private boolean foundLength;
     private byte[] buffer;
     private int count;
+    
+    private Object result;
+    private int streamIndex;
+    private OutputStream stream;
+    private List<StreamFactoryReference> streams;
 
     public ObjectDecoderInputStream(InputStream in, ClassLoader classLoader, int maxObjectSize) throws SecurityException, IOException {
     	super();
@@ -60,35 +77,93 @@
     @Override
     protected final Object readObjectOverride() throws IOException,
     		ClassNotFoundException {
-        if (!foundLength) {
-        	if (buffer == null) {
-        		buffer = new byte[4];
-        	}
-            fillBuffer();
-    		int dataLen = getIntFromBytes(buffer);
-	        if (dataLen <= 0) {
-	            throw new StreamCorruptedException("invalid data length: " + dataLen); //$NON-NLS-1$
+    	if (result == null) {
+	        if (!foundLength) {
+	        	int dataLen = findLength(4);
+	        	if (dataLen <= 0) {
+	    		    throw new StreamCorruptedException("invalid data length: " + dataLen); //$NON-NLS-1$
+	    		}
+	    		if (dataLen > maxObjectSize) {
+	    		    throw new StreamCorruptedException(
+	    		            "data length too big: " + dataLen + " (max: " + maxObjectSize + ')'); //$NON-NLS-1$ //$NON-NLS-2$
+	    		}
 	        }
-	        if (dataLen > maxObjectSize) {
-	            throw new StreamCorruptedException(
-	                    "data length too big: " + dataLen + " (max: " + maxObjectSize + ')'); //$NON-NLS-1$ //$NON-NLS-2$
+	        fillBuffer();
+	        foundLength = false;
+	        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+	        buffer = null;
+	        CompactObjectInputStream cois = new CompactObjectInputStream(bais, classLoader);
+	        result = cois.readObject();
+	        streams = ExternalizeUtil.readList(cois, StreamFactoryReference.class);
+	        streamIndex = 0;
+    	}
+    	while (streamIndex < streams.size()) {
+    		if (!foundLength) {
+	        	findLength(2);
+    		}
+	        if (stream == null) {
+	        	final File f = File.createTempFile("teiid", null); //$NON-NLS-1$
+		        StreamFactoryReference sfr = streams.get(streamIndex);
+		        sfr.setStreamFactory(new InputStreamFactory(Streamable.ENCODING) {
+					
+					@Override
+					public InputStream getInputStream() throws IOException {
+						return new BufferedInputStream(new FileInputStream(f)) {
+							@Override
+							public void close() throws IOException {
+								super.close();
+								f.delete();
+							}
+							
+							@Override
+							protected void finalize() throws Throwable {
+								super.finalize();
+								f.delete();
+							}
+						};
+					}
+					
+				});
+		        this.stream = new BufferedOutputStream(new FileOutputStream(f));
 	        }
-        	//check if the underlying buffer can be used
-	        if (in.available() >= dataLen) { 
-	        	return new CompactObjectInputStream(in, classLoader).readObject();
+	        if (buffer.length == 0) {
+	        	stream.close();
+	        	stream = null;
+	        	streamIndex++;
+	        	foundLength = false;
+	        	buffer = null;
+		        continue;
 	        }
-	        buffer = new byte[dataLen];
-	        foundLength = true;
-        }
-        fillBuffer();
-        foundLength = false;
-        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
-        buffer = null;
-        return new CompactObjectInputStream(bais, classLoader).readObject();
+	        fillBuffer();
+	        foundLength = false;
+	        this.stream.write(buffer);
+	        buffer = null;
+    	}
+        Object toReturn = result;
+        result = null;
+        streams = null;
+        stream = null;
+        return toReturn;
     }
 
+	private int findLength(int bytes) throws IOException, EOFException,
+			StreamCorruptedException {
+		if (buffer == null) {
+			buffer = new byte[bytes];
+		}
+		fillBuffer();
+		int dataLen = getIntFromBytes(buffer);
+		buffer = new byte[dataLen];
+		foundLength = true;
+		return dataLen;
+	}
+
 	static int getIntFromBytes(byte[] buffer) {
-		return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16) + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff);
+		int result = 0;
+		for (int i = 0; i < buffer.length; i++) {
+			result += ((buffer[i] & 0xff) << (buffer.length - i - 1)*8);
+		}
+		return result;
 	}
 
 	private void fillBuffer() throws IOException, EOFException {

Modified: trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectEncoderOutputStream.java
===================================================================
--- trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectEncoderOutputStream.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/client/src/main/java/org/teiid/netty/handler/codec/serialization/ObjectEncoderOutputStream.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -64,11 +64,12 @@
         out.writeInt(baos.getCount()); //includes the lob references
         out.write(baos.getBuffer(), 0, baos.getCount());
         byte[] chunk = new byte[1 << 16];
-        for (InputStream is : oout.getLobs()) {
+        for (InputStream is : oout.getStreams()) {
         	while (true) {
 	        	int bytes = is.read(chunk);
 	        	out.writeShort(Math.max(0, bytes));
 	        	if (bytes < 1) {
+	        		is.close();
 	        		break;
 	        	}
 	    		out.write(chunk, 0, bytes);

Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/BasicCryptor.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/BasicCryptor.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/BasicCryptor.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -128,7 +128,7 @@
         }
     }
     
-    public synchronized Serializable unsealObject(Serializable object) throws CryptoException {
+    public synchronized Object unsealObject(Object object) throws CryptoException {
         
         if (!(object instanceof SealedObject)) {
             return object;
@@ -137,7 +137,7 @@
         SealedObject so = (SealedObject)object;
         
         try {
-            return (Serializable)so.getObject(decryptCipher);
+            return so.getObject(decryptCipher);
         } catch ( Exception e ) {
             try {
                 initDecryptCipher();
@@ -204,9 +204,12 @@
         } 
     }
     
-    public synchronized Serializable sealObject(Serializable object) throws CryptoException {
+    public synchronized Object sealObject(Object object) throws CryptoException {
+    	if (object != null && !(object instanceof Serializable)) {
+    		throw new CryptoException(ErrorMessageKeys.CM_UTIL_ERR_0081, CorePlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0081, "not Serializable")); //$NON-NLS-1$
+    	}
         try {
-            return new SealedObject(object, encryptCipher);        
+            return new SealedObject((Serializable)object, encryptCipher);        
         } catch ( Exception e ) {
             try {
                 initEncryptCipher();

Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/Cryptor.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/Cryptor.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/Cryptor.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -22,7 +22,6 @@
 
 package com.metamatrix.common.util.crypto;
 
-import java.io.Serializable;
 
 /**
  * Interface defining a utility that can perform both encryption and decryption.
@@ -43,7 +42,7 @@
      */
     String encrypt( String cleartext ) throws CryptoException;
     
-    Serializable sealObject(Serializable object) throws CryptoException;
+    Object sealObject(Object object) throws CryptoException;
     
     /**
      * Decrypt the ciphertext in byte array format to yield the original
@@ -61,6 +60,6 @@
      */
     String decrypt( String ciphertext ) throws CryptoException;
     
-    Serializable unsealObject(Serializable object) throws CryptoException;
+    Object unsealObject(Object object) throws CryptoException;
     
 }

Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/NullCryptor.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/NullCryptor.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/NullCryptor.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -22,7 +22,6 @@
 
 package com.metamatrix.common.util.crypto;
 
-import java.io.Serializable;
 
 public class NullCryptor implements Cryptor {
 
@@ -34,7 +33,7 @@
 		return cleartext;
 	}
 
-	public Serializable sealObject(Serializable object) throws CryptoException {
+	public Object sealObject(Object object) throws CryptoException {
 		return object;
 	}
 
@@ -46,7 +45,7 @@
 		return ciphertext;
 	}
 
-	public Serializable unsealObject(Serializable object)
+	public Object unsealObject(Object object)
 			throws CryptoException {
 		return object;
 	}

Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/FakeCryptor.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/FakeCryptor.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/FakeCryptor.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util.crypto;
-
-import java.io.Serializable;
-
-/**
- * This class implements the {@link com.metamatrix.common.util.crypto.Cryptor Cryptor}
- * interface with methods that return fake data.
- * <br></br>
- * It is used to provide testing of cryptographic functionality without actually
- * doing encryption or decryption.
- */
-public class FakeCryptor implements Cryptor, Serializable {
-    private String fakeEncrypted;  
-    private String fakeDecrypted;  
-    
-    public FakeCryptor(String fakeEncrypted, String fakeDecrypted) {
-        this.fakeEncrypted = fakeEncrypted;
-        this.fakeDecrypted = fakeDecrypted;
-    }
-    
-    /**
-     * Decrypt the ciphertext in byte array format to yield the original
-     * cleartext.
-     * @param ciphertext The text to be encrypted, in byte form
-     * @param The decrypted cleartext, in byte form
-     */
-    public byte[] decrypt(byte[] ciphertext) throws CryptoException {
-        if (ciphertext.length > 100) {
-            throw new CryptoException("can't decrypt: too long"); //$NON-NLS-1$
-        } 
-        return fakeDecrypted.getBytes(); 
-    }
-
-    /**
-     * Decrypt the ciphertext in character array format to yield the original
-     * cleartext.  This requires a byte-to-char encoding.
-     * @param ciphertext The text to be encrypted, in character form
-     * @param The decrypted cleartext, in character form
-     */
-    public String decrypt(String ciphertext) throws CryptoException {
-        if (ciphertext.length() > 100) {
-            throw new CryptoException("can't decrypt: too long"); //$NON-NLS-1$
-        } 
-        return fakeDecrypted; 
-    }
-
-    /**
-     * Encrypt the cleartext in character array format.  This requires
-     * a byte-to-char encoding.
-     * @param cleartext The text to be encrypted, in character form
-     * @param The encrypted ciphertext, in character form
-     */
-    public String encrypt(String cleartext) throws CryptoException {
-        if (cleartext.length() > 100) {
-            throw new CryptoException("can't encrypt: too long"); //$NON-NLS-1$
-        } 
-        return fakeEncrypted; 
-    }
-
-    /**
-     * Encrypt the cleartext in byte array format.
-     * @param cleartext The text to be encrypted, in byte form
-     * @param The encrypted ciphertext, in byte form
-     */
-    public byte[] encrypt(byte[] cleartext) throws CryptoException {
-        if (cleartext.length > 100) {
-            throw new CryptoException("can't encrypt: too long"); //$NON-NLS-1$
-        } 
-        return fakeEncrypted.getBytes(); 
-    }
-
-    /** 
-     * @see com.metamatrix.common.util.crypto.Encryptor#sealObject(java.io.Serializable)
-     */
-    public Serializable sealObject(Serializable object) throws CryptoException {
-        return fakeEncrypted;
-    }
-
-    /** 
-     * @see com.metamatrix.common.util.crypto.Decryptor#unsealObject(java.io.Serializable)
-     */
-    public Serializable unsealObject(Serializable object) throws CryptoException {
-        return fakeDecrypted;
-    }
-}

Modified: trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/TestEncryptDecrypt.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/TestEncryptDecrypt.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/TestEncryptDecrypt.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -29,7 +29,6 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Arrays;
 
@@ -198,7 +197,7 @@
         
         ArrayList test = new ArrayList(Arrays.asList(new String[] {ALPHA_L, ALPHA_U, CLEARTEXT, NUMBERS}));
         
-        Serializable result = randomSymCryptor.sealObject(test);
+        Object result = randomSymCryptor.sealObject(test);
 
         //ensure that we can serialize
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -207,7 +206,7 @@
         
         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
         ObjectInputStream ois = new ObjectInputStream(bais);
-        result = (Serializable)ois.readObject();
+        result = ois.readObject();
         
         ArrayList clearObject = (ArrayList)randomSymCryptor.unsealObject(result);
         

Modified: trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -23,10 +23,12 @@
 package org.teiid.adminapi.jboss;
 
 import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -86,8 +88,6 @@
 import org.teiid.jboss.IntegrationPlugin;
 import org.teiid.jboss.deployers.RuntimeEngineDeployer;
 
-import com.metamatrix.core.util.FileUtils;
-
 public class Admin extends TeiidAdmin {
 	private static final ProfileKey DEFAULT_PROFILE_KEY = new ProfileKey(ProfileKey.DEFAULT);
 	
@@ -174,20 +174,18 @@
 	}
 
 	@Override
-	public char[] exportConnectorBinding(String deployedName) throws AdminException {
+	public Reader exportConnectorBinding(String deployedName) throws AdminException {
 		ManagedComponent mc = getConnectorBindingComponent(deployedName);
 		if (mc != null) {
-			return new String(exportDeployment(mc.getDeployment().getName()).toByteArray()).toCharArray();
+			return new InputStreamReader(exportDeployment(mc.getDeployment().getName()));
 		}
 		return null;
 	}
 
-	private ByteArrayOutputStream exportDeployment(String url) throws AdminComponentException {
+	private InputStream exportDeployment(String url) throws AdminComponentException {
 		try {
 			URL contentURL = new URL(url);
-			ByteArrayOutputStream bos = new ByteArrayOutputStream();
-			FileUtils.write(contentURL.openStream(), bos, FileUtils.DEFAULT_BUFFER_SIZE);
-			return bos;
+			return contentURL.openStream();
 		} catch (MalformedURLException e) {
 			throw new AdminComponentException(e);
 		} catch (IOException e) {
@@ -382,11 +380,11 @@
     }	
     
 	@Override
-	public void deployVDB(String fileName, URL vdbURL) throws AdminException {
+	public void deployVDB(String fileName, InputStream vdb) throws AdminException {
 		if (!fileName.endsWith(".vdb") && !fileName.endsWith("-vdb.xml")) {//$NON-NLS-1$ //$NON-NLS-2$
 			throw new AdminProcessingException(IntegrationPlugin.Util.getString("bad_vdb_extension")); //$NON-NLS-1$
 		}
-		ManagedUtil.deployArchive(getDeploymentManager(), fileName, vdbURL, false);
+		ManagedUtil.deployArchive(getDeploymentManager(), fileName, vdb, false);
 	}
 
 	
@@ -399,10 +397,10 @@
 	}	
 	
 	@Override
-	public byte[] exportVDB(String vdbName, int vdbVersion) throws AdminException{
+	public InputStream exportVDB(String vdbName, int vdbVersion) throws AdminException{
 		ManagedComponent mc = getVDBManagedComponent(vdbName, vdbVersion);
 		if (mc != null) {
-			return exportDeployment(mc.getDeployment().getName()).toByteArray();
+			return exportDeployment(mc.getDeployment().getName());
 		}
 		return null;
 	}
@@ -592,7 +590,7 @@
 	}	
 	
 	@Override
-	public void addConnectorType(String connectorName, URL rarURL) throws AdminException{
+	public void addConnectorType(String connectorName, InputStream rar) throws AdminException{
 		if (!connectorName.startsWith("connector-")) {//$NON-NLS-1$
 			throw new AdminProcessingException(IntegrationPlugin.Util.getString("bad_connector_type_name")); //$NON-NLS-1$
 		}
@@ -606,7 +604,7 @@
 			throw new AdminProcessingException(IntegrationPlugin.Util.getString("connector_type_exists", deployerName)); //$NON-NLS-1$
 		}
 		
-		ManagedUtil.deployArchive(getDeploymentManager(), connectorName, rarURL, false);
+		ManagedUtil.deployArchive(getDeploymentManager(), connectorName, rar, false);
 		
 		//also need to add a template for the properties
 		try {
@@ -635,19 +633,17 @@
 	}
 	
 	@Override
-	public byte[] exportConnectorType(String connectorName) throws AdminException {
+	public InputStream exportConnectorType(String connectorName) throws AdminException {
 		if (!connectorName.endsWith(".rar")) {//$NON-NLS-1$
 			connectorName = connectorName + ".rar";//$NON-NLS-1$
 		}
 		String deployerName = getRarDeployerName(connectorName);
 		if (deployerName != null) {
-			return exportDeployment(deployerName).toByteArray();			
+			return exportDeployment(deployerName);			
 		}
 		return null;
 	}
 	
-
-	
 	@Override
 	public Collection<String> getCacheTypes() throws AdminException {
 		try {

Modified: trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -21,9 +21,14 @@
  */
 package org.teiid.adminapi.jboss;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -50,6 +55,7 @@
 import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.profileservice.spi.DeploymentOption;
 import org.teiid.adminapi.AdminProcessingException;
+import org.teiid.jboss.IntegrationPlugin;
 
 import com.metamatrix.core.MetaMatrixRuntimeException;
 
@@ -96,7 +102,7 @@
 				SimpleValue simple = (SimpleValue)v1;
 				return simple.getValue().toString();
 			}
-			throw new MetaMatrixRuntimeException("Failed to convert value to string value");
+			throw new MetaMatrixRuntimeException("Failed to convert value to string value"); //$NON-NLS-1$
 		}
 		return null;
 	}	
@@ -113,7 +119,7 @@
 				 EnumValue enumValue = (EnumValue)mp.getValue();
 				 return expectedType.cast((enumValue != null) ? enumValue.getValue() : null);
 			 }
-			 throw new IllegalStateException(prop+ " is not a simple type");
+			 throw new IllegalArgumentException(prop+ " is not a simple type"); //$NON-NLS-1$
 		 }
 		 return null;
 	}	
@@ -135,7 +141,7 @@
 				}
 				return props;
 			 }
-			 throw new IllegalStateException(prop+ " is not a properties type");
+			 throw new IllegalArgumentException(prop+ " is not a properties type"); //$NON-NLS-1$
 		 }
 		 return null;
 	}	
@@ -152,7 +158,7 @@
 						 list.add(expectedType.cast(simpleValue.getValue()));
 					 }
 					 else {
-						 throw new IllegalStateException(prop+ " is not a simple type");
+						 throw new IllegalArgumentException(prop+ " is not a simple type"); //$NON-NLS-1$
 					 }
 				 }
 			 }
@@ -181,9 +187,9 @@
 				return new SimpleValueSupport(st,value.charAt(0));
 			} else if (SimpleMetaType.DATE.equals(st)) {
 				try {
-					return new SimpleValueSupport(st, new SimpleDateFormat().parse(value));
+					return new SimpleValueSupport(st, SimpleDateFormat.getInstance().parse(value));
 				} catch (ParseException e) {
-					throw new MetaMatrixRuntimeException("Failed to convert the String to date value");
+					throw new MetaMatrixRuntimeException(e, IntegrationPlugin.Util.getString("failed_to_convert", type.getClassName())); //$NON-NLS-1$
 				}
 			} else if (SimpleMetaType.DOUBLE.equals(st)) {
 				return new SimpleValueSupport(st, Double.valueOf(value));
@@ -209,23 +215,24 @@
 				return new SimpleValueSupport(st,value);
 			}
 		}
-		throw new MetaMatrixRuntimeException("Failed to convert from String value to \""+ type.getClassName() +"\" type");
+		throw new MetaMatrixRuntimeException(IntegrationPlugin.Util.getString("failed_to_convert", type.getClassName())); //$NON-NLS-1$
 	}
 	
+	public static void deployArchive(DeploymentManager deploymentManager, String fileName, final InputStream resource, boolean deployExploded) throws AdminProcessingException {
+		deployArchive(deploymentManager, fileName, getTempURL(resource), deployExploded);
+	}
 	
 	public static void deployArchive(DeploymentManager deploymentManager, String fileName, URL resourceURL, boolean deployExploded) throws AdminProcessingException {
-
 		List<DeploymentOption> deploymentOptions = new ArrayList<DeploymentOption>();
 		deploymentOptions.add(DeploymentOption.FailIfExists);
 		if (deployExploded) {
 			deploymentOptions.add(DeploymentOption.Explode);
 		}
-		
 		// try to deploy
 		DeploymentProgress progress = null;
 		try {
 			progress = deploymentManager.distribute(fileName, resourceURL, deploymentOptions.toArray(new DeploymentOption[deploymentOptions.size()]));
-			execute(progress, fileName+" Distribute failed for unknown reason.");
+			execute(progress, IntegrationPlugin.Util.getString("distribute_failed", fileName)); //$NON-NLS-1$
 		} catch (Exception e) {
 			handleException(e);
 		}
@@ -235,11 +242,11 @@
 		String[] deploymentNames = progress.getDeploymentID().getRepositoryNames();
 		try {
 			progress = deploymentManager.start(deploymentNames);
-			execute(progress, "Start of the deployment Failed");
+			execute(progress, IntegrationPlugin.Util.getString("deployment_start_failed", fileName)); //$NON-NLS-1$ 
 		} catch(Exception e) {
 			try {
 				// if failed to start remove it.
-				execute(deploymentManager.remove(deploymentNames), "Failed to remove the deployment");
+				execute(deploymentManager.remove(deploymentNames), IntegrationPlugin.Util.getString("failed_to_remove")); //$NON-NLS-1$ 
 			} catch (Exception e1) {
 				handleException(e1);
 			}
@@ -247,6 +254,31 @@
 		}
 	}
 
+	static URL getTempURL(final InputStream resource) {
+		try {
+			return new URL(null, "temp:#temp", new URLStreamHandler() { //$NON-NLS-1$
+				
+				@Override
+				protected URLConnection openConnection(URL u) throws IOException {
+					return new URLConnection(u) {
+						
+						@Override
+						public void connect() throws IOException {
+							
+						}
+						
+						@Override
+						public InputStream getInputStream() throws IOException {
+							return resource;
+						}
+					};
+				}
+			});
+		} catch (MalformedURLException e2) {
+			throw new MetaMatrixRuntimeException(e2);
+		}
+	}
+
 	public static void handleException(Exception e) throws AdminProcessingException {
 		if (e instanceof AdminProcessingException) {
 			throw (AdminProcessingException)e;
@@ -268,7 +300,7 @@
 
 	public static void removeArchive(DeploymentManager deploymentManager, String... deploymentNames) throws AdminProcessingException{
 		try {
-			execute(deploymentManager.remove(deploymentNames), "Failed to remove the deployment");
+			execute(deploymentManager.remove(deploymentNames), IntegrationPlugin.Util.getString("failed_to_remove")); //$NON-NLS-1$ 
 		} catch (Exception e) {
 			handleException(e);
 		}
@@ -280,6 +312,6 @@
 				return mo.invoke(args);
 			}
 		}
-		throw new MetaMatrixRuntimeException("No operation found with given name =" + operation); 
+		throw new MetaMatrixRuntimeException(IntegrationPlugin.Util.getString("no_operation", operation)); //$NON-NLS-1$ 
 	}
 }

Modified: trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2010-03-31 21:44:15 UTC (rev 2013)
@@ -40,4 +40,9 @@
 connector_stopped=Teiid connector {0} stopped
 vdb_activated={0}.{1} status has been changed to active
 vdb_inactivated={0}.{1} status has been changed to inactive. Check the connector mappings!
-jndi_not_found=For {0}.{1} VDB, JNDI resource "{2}" not found for Source Name "{3}"
\ No newline at end of file
+jndi_not_found=For {0}.{1} VDB, JNDI resource "{2}" not found for Source Name "{3}"
+no_operation=No operation found with given name = {0}
+failed_to_remove=Failed to remove the deployment
+distibute_failed={0} distribute failed.
+deployment_start_failed={0} deployment start failed
+failed_to_convert=Failed to convert from String value to {0} type
\ No newline at end of file

Added: trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java
===================================================================
--- trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java	                        (rev 0)
+++ trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.adminapi.jboss;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.net.URL;
+
+import org.junit.Test;
+
+import com.metamatrix.core.util.ObjectConverterUtil;
+
+public class TestManagedUtil {
+
+	@Test public void testTempURL() throws Exception {
+		ByteArrayInputStream bais = new ByteArrayInputStream(new byte[100]);
+		URL url = ManagedUtil.getTempURL(bais);
+		assertEquals(100, ObjectConverterUtil.convertToByteArray(url.openStream()).length);
+	}
+	
+}


Property changes on: trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/pom.xml	2010-03-31 21:44:15 UTC (rev 2013)
@@ -457,7 +457,7 @@
 			<dependency>
 				<groupId>org.jboss.netty</groupId>
 				<artifactId>netty</artifactId>
-				<version>3.0.2.GA</version>
+				<version>3.1.5.GA</version>
 			</dependency>
 			<dependency>
 				<groupId>org.apache.ant</groupId>

Modified: trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -127,19 +127,13 @@
 	                new ChannelBufferInputStream(buffer, dataLen), classLoader);
 	        result = cois.readObject();
 	        streams = ExternalizeUtil.readList(cois, StreamFactoryReference.class);
+	        streamIndex = 0;
     	}
     	while (streamIndex < streams.size()) {
 	    	if (buffer.readableBytes() < 2) {
 	            return null;
 	        }
-	        int dataLen = buffer.getShort(buffer.readerIndex()) & 0xff;
-	        if (dataLen == 0) {
-	        	stream.close();
-	        	stream = null;
-	        	streamIndex++;
-		        buffer.skipBytes(2);
-		        continue;
-	        }
+	        int dataLen = buffer.getShort(buffer.readerIndex()) & 0xffff;
 	        if (buffer.readableBytes() < dataLen + 2) {
 	            return null;
 	        }
@@ -158,10 +152,18 @@
 				});
 		        this.stream = new BufferedOutputStream(store.createOutputStream());
 	        }
+	        if (dataLen == 0) {
+	        	stream.close();
+	        	stream = null;
+	        	streamIndex++;
+		        continue;
+	        }
 	        buffer.readBytes(this.stream, dataLen);
     	}
         Object toReturn = result;
         result = null;
+        streams = null;
+        stream = null;
         return toReturn;
     }
 }

Added: trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java	                        (rev 0)
+++ trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @author tags. See the COPYRIGHT.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.teiid.transport;
+
+import static org.jboss.netty.buffer.ChannelBuffers.*;
+import static org.jboss.netty.channel.Channels.*;
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBufferOutputStream;
+import org.jboss.netty.channel.ChannelDownstreamHandler;
+import org.jboss.netty.channel.ChannelEvent;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipelineCoverage;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.DownstreamMessageEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.handler.stream.ChunkedInput;
+import org.jboss.netty.handler.stream.ChunkedStream;
+import org.teiid.netty.handler.codec.serialization.CompactObjectOutputStream;
+import org.teiid.netty.handler.codec.serialization.ObjectDecoderInputStream;
+
+import com.metamatrix.core.util.ExternalizeUtil;
+
+/**
+ * An encoder which serializes a Java object into a {@link ChannelBuffer}.
+ * <p>
+ * Please note that the serialized form this encoder produces is not
+ * compatible with the standard {@link ObjectInputStream}.  Please use
+ * {@link ObjectDecoder} or {@link ObjectDecoderInputStream} to ensure the
+ * interoperability with this encoder.
+ *
+ * @author The Netty Project (netty-dev at lists.jboss.org)
+ * @author Trustin Lee (tlee at redhat.com)
+ *
+ * @version $Rev:231 $, $Date:2008-06-12 16:44:50 +0900 (목, 12 6월 2008) $
+ *
+ * @apiviz.landmark
+ * @apiviz.has org.jboss.netty.handler.codec.serialization.ObjectEncoderOutputStream - - - compatible with
+ */
+ at ChannelPipelineCoverage("all")
+public class ObjectEncoder implements ChannelDownstreamHandler {
+    private static final byte[] LENGTH_PLACEHOLDER = new byte[4];
+	private static final int CHUNK_SIZE = 1 << 16;
+
+    private final int estimatedLength;
+
+    /**
+     * Creates a new encoder with the estimated length of 512 bytes.
+     */
+    public ObjectEncoder() {
+        this(512);
+    }
+
+    /**
+     * Creates a new encoder.
+     *
+     * @param estimatedLength
+     *        the estimated byte length of the serialized form of an object.
+     *        If the length of the serialized form exceeds this value, the
+     *        internal buffer will be expanded automatically at the cost of
+     *        memory bandwidth.  If this value is too big, it will also waste
+     *        memory bandwidth.  To avoid unnecessary memory copy or allocation
+     *        cost, please specify the properly estimated value.
+     */
+    public ObjectEncoder(int estimatedLength) {
+        if (estimatedLength < 0) {
+            throw new IllegalArgumentException(
+                    "estimatedLength: " + estimatedLength);
+        }
+        this.estimatedLength = estimatedLength;
+    }
+    
+    public void handleDownstream(
+            final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
+        if (!(evt instanceof MessageEvent)) {
+            ctx.sendDownstream(evt);
+            return;
+        }
+
+        MessageEvent e = (MessageEvent) evt;
+        
+        if (e.getMessage() instanceof ChunkedInput) {
+            ctx.sendDownstream(evt);
+            return;
+        }
+        
+        ChannelBufferOutputStream bout =
+            new ChannelBufferOutputStream(dynamicBuffer(
+                    estimatedLength, ctx.getChannel().getConfig().getBufferFactory()));
+        bout.write(LENGTH_PLACEHOLDER);
+        final CompactObjectOutputStream oout = new CompactObjectOutputStream(bout);
+        oout.writeObject(e.getMessage());
+        ExternalizeUtil.writeCollection(oout, oout.getReferences());
+        oout.flush();
+        oout.close();
+
+        ChannelBuffer encoded = bout.buffer();
+        encoded.setInt(0, encoded.writerIndex() - 4);
+        write(ctx, e.getFuture(), encoded, e.getRemoteAddress());
+		for (InputStream is : oout.getStreams()) {
+			Channels.write(ctx.getChannel(), new AnonymousChunkedStream(new BufferedInputStream(is, CHUNK_SIZE)));
+		}
+    }
+    
+    static class AnonymousChunkedStream extends ChunkedStream {
+
+		public AnonymousChunkedStream(InputStream in) {
+			super(in, CHUNK_SIZE);
+		}
+    	
+		@Override
+		public Object nextChunk() throws Exception {
+			ChannelBuffer cb = (ChannelBuffer)super.nextChunk();
+			int length = cb.capacity();
+			ChannelBuffer prefix = wrappedBuffer(new byte[2]);
+			prefix.setShort(0, (short)length);
+			if (!hasNextChunk()) {
+				//append a 0 short
+				return wrappedBuffer(prefix, cb, wrappedBuffer(new byte[2]));
+			}
+			
+			return wrappedBuffer(prefix, cb);
+		}
+		
+    }
+
+}


Property changes on: trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -49,8 +49,8 @@
 import org.jboss.netty.channel.ExceptionEvent;
 import org.jboss.netty.channel.MessageEvent;
 import org.jboss.netty.channel.SimpleChannelHandler;
-import org.jboss.netty.handler.codec.serialization.ObjectEncoder;
 import org.jboss.netty.handler.ssl.SslHandler;
+import org.jboss.netty.handler.stream.ChunkedWriteHandler;
 import org.teiid.net.NetPlugin;
 import org.teiid.net.socket.ObjectChannel;
 
@@ -228,6 +228,7 @@
 	        pipeline.addLast("ssl", new SslHandler(engine)); //$NON-NLS-1$
 	    }
 	    pipeline.addLast("decoder", new ObjectDecoder(1 << 20, classLoader, storageManager)); //$NON-NLS-1$
+	    pipeline.addLast("chunker", new ChunkedWriteHandler()); //$NON-NLS-1$
 	    pipeline.addLast("encoder", new ObjectEncoder()); //$NON-NLS-1$
 	    pipeline.addLast("handler", this); //$NON-NLS-1$
 	    return pipeline;

Modified: trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -83,11 +83,11 @@
 				throw e.getCause();
 			}
 			if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
-				ResultsFuture<Serializable> future = (ResultsFuture<Serializable>) methodResult;
-				future.addCompletionListener(new ResultsFuture.CompletionListener<Serializable>() {
+				ResultsFuture<Object> future = (ResultsFuture<Object>) methodResult;
+				future.addCompletionListener(new ResultsFuture.CompletionListener<Object>() {
 
 							public void onCompletion(
-									ResultsFuture<Serializable> completedFuture) {
+									ResultsFuture<Object> completedFuture) {
 								Message asynchResult = new Message();
 								try {
 									asynchResult.setContents(completedFuture.get());
@@ -102,7 +102,7 @@
 						});
 			} else { // synch call
 				Message resultHolder = new Message();
-				resultHolder.setContents((Serializable)methodResult);
+				resultHolder.setContents(methodResult);
 				result = resultHolder;
 			}
 		} catch (Throwable t) {

Modified: trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -26,6 +26,7 @@
 import static org.mockito.Mockito.*;
 
 import java.io.ByteArrayInputStream;
+import java.io.Serializable;
 import java.io.StringReader;
 import java.net.InetSocketAddress;
 import java.util.Properties;
@@ -49,8 +50,10 @@
 import com.metamatrix.api.exception.ComponentNotFoundException;
 import com.metamatrix.common.buffer.BufferManagerFactory;
 import com.metamatrix.common.util.crypto.NullCryptor;
+import com.metamatrix.core.util.ObjectConverterUtil;
 import com.metamatrix.dqp.service.SessionService;
 
+ at SuppressWarnings("nls")
 public class TestCommSockets {
 
 	SocketListener listener;
@@ -124,7 +127,15 @@
 		SocketServerConnection conn = helpEstablishConnection(false);
 		FakeService fs = conn.getService(FakeService.class);
 		assertEquals(150, fs.lobMethod(new ByteArrayInputStream(new byte[100]), new StringReader(new String(new char[50]))));
+		assertEquals(0, fs.lobMethod(new ByteArrayInputStream(new byte[0]), new StringReader(new String(new char[0]))));
 	}
+	
+	@Test public void testServerRemoteStreaming() throws Exception {
+		SocketServerConnection conn = helpEstablishConnection(false);
+		FakeService fs = conn.getService(FakeService.class);
+		assertEquals("hello world", ObjectConverterUtil.convertToString(fs.getReader()));
+		assertTrue(Serializable.class.isAssignableFrom(fs.getReader().getClass()));
+	}
 
 	@Test public void testConnectWithoutClientEncryption() throws Exception {
 		SSLConfiguration config = new SSLConfiguration();

Modified: trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -28,6 +28,7 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.io.Serializable;
+import java.io.StringReader;
 import java.util.Properties;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -70,6 +71,8 @@
 		
 		int lobMethod(InputStream is, Reader r) throws IOException;
 		
+		Reader getReader() throws IOException;
+		
 	}
 	
 	static class FakeServiceImpl implements FakeService {
@@ -88,6 +91,11 @@
 		public int lobMethod(InputStream is, Reader r) throws IOException {
 			return ObjectConverterUtil.convertToByteArray(is).length + ObjectConverterUtil.convertToString(r).length();
 		}
+
+		@Override
+		public Reader getReader() throws IOException {
+			return new StringReader("hello world"); //$NON-NLS-1$
+		}
 		
 	}
 	

Modified: trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
===================================================================
--- trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-03-31 20:48:49 UTC (rev 2012)
+++ trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-03-31 21:44:15 UTC (rev 2013)
@@ -1,13 +1,13 @@
 package org.teiid.adminapi.jboss;
 
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.*;
 
 import java.io.File;
-import java.net.MalformedURLException;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.sql.Connection;
 import java.util.Collection;
 import java.util.HashSet;
@@ -227,11 +227,16 @@
 		}
 	}
 
-	private static void installVDB() throws AdminException, MalformedURLException {
+	private static void installVDB() throws AdminException, FileNotFoundException {
 		VDB vdb = admin.getVDB("TransactionsRevisited", 1); //$NON-NLS-1$
 		if (vdb == null) {
 			File f = UnitTestUtil.getTestDataFile("TransactionsRevisited.vdb"); //$NON-NLS-1$
-			admin.deployVDB(f.getName(), f.toURI().toURL());
+			FileInputStream fis = new FileInputStream(f);
+			admin.deployVDB(f.getName(), fis);
+			try {
+				fis.close();
+			} catch (IOException e) {
+			}
 		}
 	}
 	
@@ -299,7 +304,9 @@
 	@Test
 	public void testTemplate() throws Exception{
 		File f = new File(UnitTestUtil.getTestDataPath()+"/connector-loopback.rar"); //$NON-NLS-1$
-		admin.addConnectorType("connector-loopy", f.toURI().toURL()); //$NON-NLS-1$
+		FileInputStream fis = new FileInputStream(f);
+		admin.addConnectorType("connector-loopy", fis); //$NON-NLS-1$
+		fis.close();
 		
 		Set<String> names = admin.getConnectorTypes();
 		assertTrue(names.contains("connector-loopy")); //$NON-NLS-1$
@@ -316,7 +323,7 @@
 		
 		assertTrue(!f.exists());
 		
-		byte[] contents = admin.exportVDB("TransactionsRevisited", 1); //$NON-NLS-1$
+		InputStream contents = admin.exportVDB("TransactionsRevisited", 1); //$NON-NLS-1$
 		if (contents != null) {
 			ObjectConverterUtil.write(contents, f.getCanonicalPath());
 		}



More information about the teiid-commits mailing list