2014-02-05 183 views
0

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

第一个是运行Windows 8.1和Java HotSpot客户端虚拟机1.7.0_51 第二种运行Ubuntu Linux操作系统12.04与Java HotSpot的64位服务器VM 1.7.0_51

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

很明显,java.lang.UNIX **类在Windows JVM上不可用。我如何抑制这个异常。这些类不需要进一步处理,但可以忽略。

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

回答

0

后我发现了一些进一步的研究解决方案......

XStream的允许通过增加转换器拦截(未)编组过程。因此,我注册了以下转换器,一旦识别出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()); 

也许有人认为这是很有帮助的。

相关问题