Exemplo n.º 1
0
 @Override
 public Object decode(byte[] bytes) throws Exception {
   ClassLoader tccl = Thread.currentThread().getContextClassLoader();
   Thread.currentThread().setContextClassLoader(HessianCodec.class.getClassLoader());
   HessianInput input = new HessianInput(new ByteArrayInputStream(bytes));
   input.setSerializerFactory(serializerFactory);
   Object resultObject = input.readObject();
   Thread.currentThread().setContextClassLoader(tccl);
   return resultObject;
 }
Exemplo n.º 2
0
  @Test
  public void testHessianSerializable() throws Exception {
    Test1 test1 = new Test1();
    Test2 test2 = new Test2();
    Test3 test3 = new Test3();
    test2.setTest1(test1);
    test1.setTest2(test2);
    test1.setTest3(test3);
    test3.setTest2(test2);
    try {
      String bigcontent =
          FileUtil.getFileContent(
              new File(
                  "F:\\workspace\\bbossgroups-3.5\\bboss-core\\test\\org\\frameworkset\\soa\\testxstream.xml"),
              "UTF-8");
      // 预热bboss和xstream
      test1.setXmlvalue(bigcontent);
      long s = System.currentTimeMillis();
      String xml = ObjectSerializable.toXML(test1);
      long e = System.currentTimeMillis();
      System.out.println("bboss:" + xml.getBytes().length + ",times:" + (e - s));
      s = System.currentTimeMillis();
      Test1 test1_ = (Test1) ObjectSerializable.toBean(xml, Test1.class);
      e = System.currentTimeMillis();
      System.out.println("bboss de times:" + (e - s));
      s = System.currentTimeMillis();
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      HessianOutput ho = new HessianOutput(os);
      ho.writeObject(test1);
      byte[] cs = os.toByteArray();
      e = System.currentTimeMillis();

      System.out.println("hessian:" + cs.length + ",times:" + (e - s));
      s = System.currentTimeMillis();
      ByteArrayInputStream is = new ByteArrayInputStream(cs);
      HessianInput hi = new HessianInput(is);
      test1_ = (Test1) hi.readObject();
      e = System.currentTimeMillis();
      System.out.println("hessian de times:" + (e - s));

      // 测试用例结束

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 public void invoke(InputStream inputStream, OutputStream outputStream) throws Throwable {
   HessianInput in = new HessianInput(inputStream);
   HessianOutput out = new HessianOutput(outputStream);
   if (this.serializerFactory != null) {
     in.setSerializerFactory(this.serializerFactory);
     if (applySerializerFactoryToOutput) {
       out.setSerializerFactory(this.serializerFactory);
     }
   }
   try {
     invokeMethod.invoke(this.skeleton, new Object[] {in, out});
   } finally {
     try {
       in.close();
       inputStream.close();
     } catch (IOException ex) {
     }
     try {
       out.close();
       outputStream.close();
     } catch (IOException ex) {
     }
   }
 }