XStream CannotResolveClassException:java.lang.UNIXProcess $ ProcessPipeInputStream(Windows< - > Unix)

时间:2014-02-05 15:14:48

标签: java selenium-webdriver testng xstream

我正在使用库com.thoughtworks.xstream:xstream:1.4.5在两台机器之间传输Java对象。

第一个是运行带有Java Hotspot Client VM 1.7.0_51的Windows 8.1 第二个是使用Java HotSpot 64位服务器VM 1.7.0_51运行Ubuntu Linux 12.04

我正在将TestNG测试用例从Windows机器转移到Linux机器,因此需要XStream进行反序列化。当从Linux返回到Windows的结果时,在Windows机器上反序列化XML时会出现问题。

显然,Windows JVM上没有java.lang.UNIX **类。如何抑制此异常。这些类不是进一步处理所必需的,但可以忽略。

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
-------------------------------

1 个答案:

答案 0 :(得分:0)

经过深入研究后,我找到了解决方案......

XStream允许通过添加转换器来拦截(un-)编组过程。因此,我注册了以下转换器,一旦识别出FirefoxDriver类,就会停止(取消)编组。

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;
      }
}   

在XStream实例上注册很简单:

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

也许有人觉得这很有帮助。