Java Code Examples for com.caucho.hessian.io.Hessian2Output#close()

The following examples show how to use com.caucho.hessian.io.Hessian2Output#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleTesGO2GO.java    From sofa-hessian with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testDate() throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());

    hout.writeObject(dg.generateDate_0());
    hout.writeObject(dg.generateDate_1());
    hout.writeObject(dg.generateDate_2());

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    assertEquals(dg.generateDate_0(), hin.readObject());
    assertEquals(dg.generateDate_1(), hin.readObject());
    assertEquals(dg.generateDate_2(), hin.readObject());

    hin.close();
}
 
Example 2
Source File: SimpleTestO2GO.java    From sofa-hessian with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testNull() throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new SerializerFactory());

    hout.writeObject(dg.generateNull());
    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    assertNull(hin.readObject());

    hin.close();
}
 
Example 3
Source File: TestArray.java    From sofa-hessian with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericArray() throws IOException {
    GenericArray ga = dg.generateGenericArray();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());

    hout.writeObject(ga);

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new SerializerFactory());

    Person[] pArr = (Person[]) hin.readObject();

    assertEquals(ga.getLength(), pArr.length);
    cmpGPersonEqualPerson((GenericObject) ga.get(0), (Person) pArr[0]);
    cmpGPersonEqualPerson((GenericObject) ga.get(1), (Person) pArr[1]);
    cmpGPersonEqualPerson((GenericObject) ga.get(2), (Person) pArr[2]);

}
 
Example 4
Source File: HessianSerialize.java    From Raincat with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void serialize(final OutputStream output, final Object object) {
    Hessian2Output ho = new Hessian2Output(output);
    try {
        ho.startMessage();
        ho.writeObject(object);
        ho.completeMessage();
        ho.close();
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: X509Encryption.java    From jvm-sandbox-repeater with Apache License 2.0 5 votes vote down vote up
public void close()
  throws IOException
{
  Hessian2Output out = _out;
  _out = null;

  if (out != null) {
    _cipherOut.close();
    _bodyOut.close();

    out.writeInt(0);
    out.completeEnvelope();
    out.close();
  }
}
 
Example 6
Source File: SimpleTesGO2GO.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testList() throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());

    hout.writeObject(dg.generateUntypedFixedList_0());
    hout.writeObject(dg.generateUntypedFixedList_1());
    hout.writeObject(dg.generateUntypedFixedList_7());
    hout.writeObject(dg.generateUntypedFixedList_8());

    hout.writeObject(dg.generateTypedFixedList_0());
    hout.writeObject(dg.generateTypedFixedList_1());
    hout.writeObject(dg.generateTypedFixedList_7());
    hout.writeObject(dg.generateTypedFixedList_8());

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    assertEquals(dg.generateUntypedFixedList_0(), hin.readObject());
    assertEquals(dg.generateUntypedFixedList_1(), hin.readObject());
    assertEquals(dg.generateUntypedFixedList_7(), hin.readObject());
    assertEquals(dg.generateUntypedFixedList_8(), hin.readObject());

    assertTrue(Arrays.equals((Object[]) dg.generateTypedFixedList_0(),
        (Object[]) hin.readObject()));
    assertTrue(Arrays.equals((Object[]) dg.generateTypedFixedList_1(),
        (Object[]) hin.readObject()));
    assertTrue(Arrays.equals((Object[]) dg.generateTypedFixedList_7(),
        (Object[]) hin.readObject()));
    assertTrue(Arrays.equals((Object[]) dg.generateTypedFixedList_8(),
        (Object[]) hin.readObject()));

    hin.close();
}
 
Example 7
Source File: ComplexTestO2GO.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
@Test
public void testMap() throws IOException {
    Map map = (Map) dg.generateMapPerson_1();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new SerializerFactory());

    hout.writeObject(map);

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    Map dmap = (Map) hin.readObject();

    assertEquals(dmap.size(), map.size());
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dmap.get(1), (Person) map.get(1));
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dmap.get(2), (Person) map.get(2));

    Map dmap2 = (Map) dmap.get("map");
    Map map2 = (Map) map.get("map");
    assertEquals(dmap2.size(), map2.size());
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dmap2.get("lll"),
        (Person) map2.get("lll"));
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dmap2.get("qqq"),
        (Person) map2.get("qqq"));
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dmap2.get("www"),
        (Person) map2.get("www"));
    assertSame(dmap2.get("lll"), dmap2.get("www"));
}
 
Example 8
Source File: SofaResponseHessianSerializer.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public AbstractByteBuf encodeObject(SofaResponse sofaResponse, Map<String, String> context) {
    try {
        UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream();
        Hessian2Output output = new Hessian2Output(byteArray);
        output.setSerializerFactory(serializerFactory);
        output.writeObject(sofaResponse);
        output.close();
        return new ByteStreamWrapperByteBuf(byteArray);
    } catch (IOException e) {
        throw buildSerializeError(e.getMessage(), e);
    }
}
 
Example 9
Source File: ComplexTestO2GO.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
public void testArray() throws IOException {
    Object[] arr = (Object[]) dg.generateArrayPerson_1();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new SerializerFactory());

    hout.writeObject(arr);

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    Object[] darr = (Object[]) hin.readObject();

    assertEquals(darr.length, arr.length);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr[0], (Person) arr[0]);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr[1], (Person) arr[1]);

    Object[] darr2 = (Object[]) darr[2];
    Object[] arr2 = (Object[]) arr[2];
    assertEquals(darr2.length, arr2.length);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr2[0], (Person) arr2[0]);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr2[1], (Person) arr2[1]);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr2[2], (Person) arr2[2]);
    assertSame(darr2[0], darr2[2]);

}
 
Example 10
Source File: HessianSerialize.java    From Lottor with MIT License 5 votes vote down vote up
@Override
public void serialize(OutputStream output, Object object) {
    Hessian2Output ho = new Hessian2Output(output);
    try {
        ho.startMessage();
        ho.writeObject(object);
        ho.completeMessage();
        ho.close();
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 11
Source File: CollectionTest.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapGeneric() throws Exception {

    TestMap testMap = new TestMap();
    testMap.put("1", new SimplePerson("wang", "coder"));

    GenericMap map = new GenericMap(TestMap.class.getName());
    map.setMap(testMap);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());
    hout.writeObject(map);
    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    Object o = hin.readObject();
    assertTrue(o.getClass() == GenericMap.class);
    GenericMap genericMap = (GenericMap) o;
    assertEquals(genericMap.getType(), TestMap.class.getName());
    assertEquals(genericMap.getMap().size(), 1);
    assertTrue(genericMap.getMap().get("1").getClass() == GenericObject.class);

    GenericObject genericObject = (GenericObject) genericMap.getMap().get("1");
    assertEquals(genericObject.getType(), SimplePerson.class.getName());
    assertEquals(genericObject.getField("name"), "wang");
    assertEquals(genericObject.getField("job"), "coder");
}
 
Example 12
Source File: SofaRequestHessianSerializer.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public AbstractByteBuf encodeObject(SofaRequest sofaRequest, Map<String, String> context) {
    try {
        UnsafeByteArrayOutputStream outputStream = new UnsafeByteArrayOutputStream();
        Hessian2Output output = new Hessian2Output(outputStream);

        // 根据SerializeType信息决定序列化器
        boolean genericSerialize = context != null &&
            isGenericRequest(context.get(RemotingConstants.HEAD_GENERIC_TYPE));
        if (genericSerialize) {
            output.setSerializerFactory(genericSerializerFactory);
        } else {
            output.setSerializerFactory(serializerFactory);
        }

        output.writeObject(sofaRequest);
        final Object[] args = sofaRequest.getMethodArgs();
        if (args != null) {
            for (Object arg : args) {
                output.writeObject(arg);
            }
        }
        output.close();

        return new ByteStreamWrapperByteBuf(outputStream);
    } catch (IOException e) {
        throw buildSerializeError(e.getMessage(), e);
    }
}
 
Example 13
Source File: SimpleTestO2GO.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testMap() throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new SerializerFactory());

    hout.writeObject(dg.generateUntypedMap_0());
    hout.writeObject(dg.generateUntypedMap_1());
    hout.writeObject(dg.generateUntypedMap_2());
    hout.writeObject(dg.generateUntypedMap_3());

    hout.writeObject(dg.generateTypedMap_0());
    hout.writeObject(dg.generateTypedMap_1());
    hout.writeObject(dg.generateTypedMap_2());
    hout.writeObject(dg.generateTypedMap_3());

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    assertEquals(dg.generateUntypedMap_0(), hin.readObject());
    assertEquals(dg.generateUntypedMap_1(), hin.readObject());
    assertEquals(dg.generateUntypedMap_2(), hin.readObject());
    assertEquals(dg.generateUntypedMap_3(), hin.readObject());

    assertEquals(dg.generateTypedMap_0(), hin.readObject());
    assertEquals(dg.generateTypedMap_1(), hin.readObject());
    assertEquals(dg.generateTypedMap_2(), hin.readObject());
    assertEquals(dg.generateTypedMap_3(), hin.readObject());

    hin.close();
}
 
Example 14
Source File: CollectionTest.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
@Test
public void testCollection() throws Exception {

    TestList testList = new TestList();
    testList.add(1);
    testList.add(new SimplePerson("wang", "coder"));

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());
    hout.writeObject(testList);
    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    Object o = hin.readObject();
    assertTrue(o.getClass() == GenericCollection.class);
    GenericCollection genericCollection = (GenericCollection) o;
    assertEquals(genericCollection.getType(), TestList.class.getName());
    assertEquals(genericCollection.getCollection().size(), 2);
    assertEquals(((ArrayList) genericCollection.getCollection()).get(0), 1);
    assertEquals(((ArrayList) genericCollection.getCollection()).get(1).getClass(),
        GenericObject.class);

    GenericObject genericObject = (GenericObject) ((ArrayList) genericCollection
        .getCollection()).get(1);
    assertEquals(genericObject.getType(), SimplePerson.class.getName());
    assertEquals(genericObject.getField("name"), "wang");
    assertEquals(genericObject.getField("job"), "coder");
}
 
Example 15
Source File: SimpleTesGO2GO.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testDoubles() throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());

    hout.writeObject(dg.generateDouble_0_0());
    hout.writeObject(dg.generateDouble_1_0());
    hout.writeObject(dg.generateDouble_2_0());
    hout.writeObject(dg.generateDouble_127_0());
    hout.writeObject(dg.generateDouble_m128_0());
    hout.writeObject(dg.generateDouble_128_0());
    hout.writeObject(dg.generateDouble_m129_0());
    hout.writeObject(dg.generateDouble_32767_0());
    hout.writeObject(dg.generateDouble_m32768_0());
    hout.writeObject(dg.generateDouble_0_001());
    hout.writeObject(dg.generateDouble_m0_001());
    hout.writeObject(dg.generateDouble_65_536());
    hout.writeObject(dg.generateDouble_3_14159());

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    assertEquals(dg.generateDouble_0_0(), hin.readObject());
    assertEquals(dg.generateDouble_1_0(), hin.readObject());
    assertEquals(dg.generateDouble_2_0(), hin.readObject());
    assertEquals(dg.generateDouble_127_0(), hin.readObject());
    assertEquals(dg.generateDouble_m128_0(), hin.readObject());
    assertEquals(dg.generateDouble_128_0(), hin.readObject());
    assertEquals(dg.generateDouble_m129_0(), hin.readObject());
    assertEquals(dg.generateDouble_32767_0(), hin.readObject());
    assertEquals(dg.generateDouble_m32768_0(), hin.readObject());
    assertEquals(dg.generateDouble_0_001(), hin.readObject());
    assertEquals(dg.generateDouble_m0_001(), hin.readObject());
    assertEquals(dg.generateDouble_65_536(), hin.readObject());
    assertEquals(dg.generateDouble_3_14159(), hin.readObject());

    hin.close();
}
 
Example 16
Source File: DubboHessianPipe.java    From Ak47 with Apache License 2.0 4 votes vote down vote up
@Override
public void encodeDubboRequest(Request<DubboHessianRequest> request, DubboData dd) throws Exception {
    
    DubboHessianRequest dubboreq = request.pojo();
    // set flag
       DubboHeader dh = dubboreq.getDubboHeader();
       dh.setFlag((byte) (FLAG_REQUEST | FLAG_TWOWAY | HESSIAN_SERIALIZATION_ID) );
    
    // set body
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       Hessian2Output h2out = hessianFactory.createHessian2Output(bos);
       
       String dubboVersion = dubboreq.getDubboVersion();
       if( null == dubboVersion ) dubboVersion = DEFAULT_DUBBO_VERSION;
       h2out.writeString(dubboVersion);
       
       String service = dubboreq.getService();
       h2out.writeString(service);
       
       String version = dubboreq.getVersion();
       if( null == version ) version = DEFAULT_METHOD_VERSION;
       h2out.writeString(version);
       
       String method = dubboreq.getMethod();
       h2out.writeString(method);
       
       Class<?>[] argtypes = CollectionUtil.objects2Classes( dubboreq.getArgs() );
       String argsdesc = ReflectUtils.getDesc(argtypes);
       h2out.writeString(argsdesc);
       
       for( Object obj : dubboreq.getArgs() ){
           h2out.writeObject(obj);
       }
       
       Map<String, String> attachments = dubboreq.getAttachments();
       h2out.writeObject(attachments);
       
       h2out.close();
       byte[] body = bos.toByteArray();
       
       dd.setDubboHeader(dubboreq.getDubboHeader());
       dd.setBody(body);
       
       log.debug("encodeDubboRequest dubboVersion:{} service:{} version:{} method:{} args.size:{} attachments:{}",
               dubboVersion, service, version, method, argtypes.length, YmlUtil.obj2Yml(attachments));
	
}
 
Example 17
Source File: SimpleTesGO2GO.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testObject() throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());

    hout.writeObject(dg.generateGenericObject_0());
    hout.writeObject(dg.generateGenericObject_16());
    hout.writeObject(dg.generateGenericObject_1());
    hout.writeObject(dg.generateGenericObject_2());
    hout.writeObject(dg.generateGenericObject_2a());
    hout.writeObject(dg.generateGenericObject_2b());
    hout.writeObject(dg.generateGenericObject_3());

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    Object dobj1 = hin.readObject();
    Object dobj2 = hin.readObject();
    Object dobj3 = hin.readObject();
    Object dobj4 = hin.readObject();
    Object dobj5 = hin.readObject();
    Object dobj6 = hin.readObject();
    Object dobj7 = hin.readObject();

    Object obj1 = dg.generateObject_0();
    Object obj2 = dg.generateObject_16();
    Object obj3 = dg.generateObject_1();
    Object obj4 = dg.generateObject_2();
    Object obj5 = dg.generateObject_2a();
    Object obj6 = dg.generateObject_2b();
    Object obj7 = dg.generateObject_3();

    assertEquals(obj1.getClass().getName(), ((GenericObject) dobj1).getType());

    List listO2 = (List) obj2;
    List listGO2 = (List) dobj2;
    for (int i = 0; i < listO2.size(); ++i)
        assertEquals(listO2.get(i).getClass().getName(),
            ((GenericObject) listGO2.get(i)).getType());

    assertEquals(obj3.getClass().getName(), ((GenericObject) dobj3).getType());
    assertEquals(((TestObject) obj3).getValue(),
        ((GenericObject) dobj3).getField("_value"));

    List listO4 = (List) obj4;
    List listGO4 = (List) dobj4;
    assertEquals(listO4.get(0).getClass().getName(), ((GenericObject) listGO4.get(0)).getType());
    assertEquals(((TestObject) listO4.get(0)).getValue(),
        ((GenericObject) listGO4.get(0)).getField("_value"));
    assertEquals(listO4.get(1).getClass().getName(), ((GenericObject) listGO4.get(1)).getType());
    assertEquals(((TestObject) listO4.get(1)).getValue(),
        ((GenericObject) listGO4.get(1)).getField("_value"));

    List listO5 = (List) obj5;
    List listGO5 = (List) dobj5;
    assertEquals(listO5.get(0).getClass().getName(), ((GenericObject) listGO5.get(0)).getType());
    assertEquals(((TestObject) listO5.get(0)).getValue(),
        ((GenericObject) listGO5.get(0)).getField("_value"));
    assertSame(listGO5.get(0), listGO5.get(1));

    List listO6 = (List) obj6;
    List listGO6 = (List) dobj6;
    assertEquals(listO6.get(0).getClass().getName(), ((GenericObject) listGO6.get(0)).getType());
    assertEquals(((TestObject) listO6.get(0)).getValue(),
        ((GenericObject) listGO6.get(0)).getField("_value"));
    assertEquals(listO6.get(1).getClass().getName(), ((GenericObject) listGO6.get(1)).getType());
    assertEquals(((TestObject) listO6.get(1)).getValue(),
        ((GenericObject) listGO6.get(1)).getField("_value"));

    GenericObject gobj7 = (GenericObject) dobj7;
    assertEquals(obj7.getClass().getName(), gobj7.getType());
    assertSame(gobj7, gobj7.getField("_rest"));

    hin.close();

}
 
Example 18
Source File: ComplexTestGO2O.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
@Test
public void singlePerson() throws IOException {
    Object gp1 = dg.generateGenericPerson_1();
    Object gp2 = dg.generateGenericPerson_2();
    Object gp3 = dg.generateGenericPerson_3();
    Object gp4 = dg.generateGenericPerson_4();
    Object gp5 = dg.generateGenericPerson_5();
    Object gp6 = dg.generateGenericPerson_6();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new GenericSerializerFactory());

    hout.writeObject(gp1);
    hout.writeObject(gp2);
    hout.writeObject(gp3);
    hout.writeObject(gp4);
    hout.writeObject(gp5);
    hout.writeObject(gp6);

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new SerializerFactory());

    Person dp1 = (Person) hin.readObject();
    Person dp2 = (Person) hin.readObject();
    Person dp3 = (Person) hin.readObject();
    Person dp4 = (Person) hin.readObject();
    Person dp5 = (Person) hin.readObject();
    Person dp6 = (Person) hin.readObject();

    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) gp1, dp1);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) gp2, dp2);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) gp3, dp3);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) gp4, dp4);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) gp5, dp5);
    ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) gp6, dp6);

    //System.out.println(dp6);
}
 
Example 19
Source File: ComplexTestO2GO.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
@Test
public void singlePerson() throws IOException {
    Object p1 = dg.generatePerson_1();
    Object p2 = dg.generatePerson_2();
    Object p3 = dg.generatePerson_3();
    Object p4 = dg.generatePerson_4();
    Object p5 = dg.generatePerson_5();
    Object p6 = dg.generatePerson_6();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output hout = new Hessian2Output(bout);
    hout.setSerializerFactory(new SerializerFactory());

    hout.writeObject(p1);
    hout.writeObject(p2);
    hout.writeObject(p3);
    hout.writeObject(p4);
    hout.writeObject(p5);
    hout.writeObject(p6);

    hout.close();

    byte[] body = bout.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);
    hin.setSerializerFactory(new GenericSerializerFactory());

    GenericObject dp1 = (GenericObject) hin.readObject();
    GenericObject dp2 = (GenericObject) hin.readObject();
    GenericObject dp3 = (GenericObject) hin.readObject();
    GenericObject dp4 = (GenericObject) hin.readObject();
    GenericObject dp5 = (GenericObject) hin.readObject();
    GenericObject dp6 = (GenericObject) hin.readObject();

    ComplexTestGO2GO.cmpGPersonEqualPerson(dp1, (Person) p1);
    ComplexTestGO2GO.cmpGPersonEqualPerson(dp2, (Person) p2);
    ComplexTestGO2GO.cmpGPersonEqualPerson(dp3, (Person) p3);
    ComplexTestGO2GO.cmpGPersonEqualPerson(dp4, (Person) p4);
    ComplexTestGO2GO.cmpGPersonEqualPerson(dp5, (Person) p5);
    ComplexTestGO2GO.cmpGPersonEqualPerson(dp6, (Person) p6);

}
 
Example 20
Source File: ComplexTestMix.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
@Test
public void testSofaRequest() throws IOException {
    SofaRequest request = dg.generateSofaRequest();

    // serialization uses GenericHessian
    ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
    Hessian2Output output = new Hessian2Output(byteArray);
    output.setSerializerFactory(new GenericSerializerFactory());
    output.writeObject(request);

    final Object[] args = request.getMethodArgs();
    if (args != null) {
        for (int i = 0; i < args.length; i++) {
            output.writeObject(args[i]);
        }
    }
    output.close();
    byteArray.close();

    // deserialization uses Hessian
    byte[] body = byteArray.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length);
    Hessian2Input hin = new Hessian2Input(bin);

    hin.setSerializerFactory(new SerializerFactory());

    SofaRequest deRequest = (SofaRequest) hin.readObject();
    String[] sig = deRequest.getMethodArgSigs();
    Class<?>[] classSig = new Class[sig.length];

    final Object[] deArgs = new Object[sig.length];
    for (int i = 0; i < deRequest.getMethodArgSigs().length; ++i) {
        deArgs[i] = hin.readObject(classSig[i]);
    }
    deRequest.setMethodArgs(deArgs);

    bin.close();
    hin.close();

    assertEquals(request.getTargetServiceUniqueName(), deRequest.getTargetServiceUniqueName());
    assertEquals(request.getMethodName(), deRequest.getMethodName());
    assertEquals(request.getTargetAppName(), deRequest.getTargetAppName());
    assertEquals(request.getRequestProps(), deRequest.getRequestProps());

    // 1st argument is a Person, and 2nd argument is an int
    cmpGPersonEqualPerson((GenericObject) request.getMethodArgs()[0],
        (Person) deRequest.getMethodArgs()[0]);
    assertEquals(request.getMethodArgs()[1], deRequest.getMethodArgs()[1]);

}