Question

I am using the library com.thoughtworks.xstream:xstream:1.4.5 to transfer Java object between two machines.

The first one is running Windows 8.1 with Java Hotspot Client VM 1.7.0_51 The second one is running Ubuntu Linux 12.04 with Java HotSpot 64bit Server VM 1.7.0_51

I am transfering a TestNG testcase from the Windows machine to the Linux machine thus requiring XStream for deserialization. When a result is returned from Linux to Windows there is a problem deserializing the XML on the Windows machine.

Obviously the java.lang.UNIX ** classes are not available on the Windows JVM. How do I suppress this exception. These classes are not required for further processing, but could be ignored.

com.thoughtworks.xstream.converters.ConversionException: java.lang.UNIXProcess$ProcessPipeInputStream : java.lang.UNIXProcess$ProcessPipeInputStream
---- Debugging information ----
message             : java.lang.UNIXProcess$ProcessPipeInputStream
cause-exception     : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message       : java.lang.UNIXProcess$ProcessPipeInputStream
class               : org.apache.commons.exec.StreamPumper
required-type       : org.apache.commons.exec.StreamPumper
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /org.testng.internal.TestResult/m_testClass/m_beforeTestMethods/org.testng.internal.ConfigurationMethod/m_instance/driver/executor/connection/process/process/process/executor/streamHandler/outputThread/target/is
line number         : 107
class[1]            : java.lang.Thread
class[2]            : org.apache.commons.exec.PumpStreamHandler
class[3]            : org.apache.commons.exec.DefaultExecutor
class[4]            : org.openqa.selenium.os.UnixProcess
class[5]            : org.openqa.selenium.os.CommandLine
class[6]            : org.openqa.selenium.firefox.FirefoxBinary
class[7]            : org.openqa.selenium.firefox.internal.NewProfileExtensionConnection
class[8]            : org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor
class[9]            : org.openqa.selenium.firefox.FirefoxDriver
class[10]           : my.work.selenium.MySeleniumTest
class[11]           : org.testng.internal.ConfigurationMethod
class[12]           : [Lorg.testng.ITestNGMethod;
converter-type[1]   : com.thoughtworks.xstream.converters.collections.ArrayConverter
class[13]           : org.testng.TestClass
class[14]           : org.testng.internal.TestResult
version             : 1.4.5
-------------------------------
Was it helpful?

Solution

I found the solution after some further research...

XStream allow to intercept the (un-)marshalling processes by adding converter. Hence I registered the following converter which stop (un-)marshalling as soon as a FirefoxDriver class is identified.

import org.openqa.selenium.firefox.FirefoxDriver;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class CutoffConverter implements Converter{

      @SuppressWarnings("unchecked")
      public boolean canConvert(Class type) {
        return type.equals(FirefoxDriver.class);
      }

      public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      }

      public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
          return null;
      }
}   

Registering it at the XStream instance is simple:

XStream xstream = new XStream();
xstream.registerConverter(new CutoffConverter());

Maybe someone finds this helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top