Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dubbo Compatible with hessian1] Fix hessian1 serialized short, byte is converted to int #1616

Merged
merged 3 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix hessian1 serialized short, byte is converted to int
  • Loading branch information
zonghaishang committed Apr 16, 2018
commit 0652ddf94b6fe652a4e70c8a37e7a3028647ec06
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
don't set it same as provider -->
<dubbo:application name="demo-consumer"/>

<!-- generate proxy for the remote service, then demoService can be used in the same way as the
local regular interface -->
<dubbo:reference id="demoService" check="false" interface="com.alibaba.dubbo.demo.DemoService" timeout="100000"
url="dubbo://172.17.12.206:30880"
/>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<!-- provider's application name, used for tracing dependency relationship -->
<dubbo:application name="demo-provider"/>

<!-- use multicast registry center to export service -->
<dubbo:registry address="zookeeper://192.168.47.102:2181"/>

<!-- use dubbo protocol to export service on port 20880 -->
<dubbo:protocol name="dubbo" port="30880"/>

<!-- service implementation, as same as regular local bean -->
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/>

<!-- declare the service interface to be exported -->
<dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" timeout="20000"/>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
* Input stream for Hessian requests.
Expand Down Expand Up @@ -977,7 +978,15 @@ private HashMap readFault()
*/
public Object readObject(Class cl)
throws IOException {
if (cl == null || cl == Object.class)
return readObject(cl, null, null);
}

/**
* Reads an object from the input stream with an expected type.
*/
public Object readObject(Class expectedClass, Class<?>... expectedTypes)
throws IOException {
if (expectedClass == null || expectedClass == Object.class)
return readObject();

int tag = read();
Expand All @@ -989,17 +998,23 @@ public Object readObject(Class cl)
case 'M': {
String type = readType();

boolean keyValuePair = expectedTypes != null && expectedTypes.length == 2;

// hessian/3386
if ("".equals(type)) {
Deserializer reader;
reader = _serializerFactory.getDeserializer(cl);
reader = _serializerFactory.getDeserializer(expectedClass);

return reader.readMap(this);
return reader.readMap(this
, keyValuePair ? expectedTypes[0] : null
, keyValuePair ? expectedTypes[1] : null);
} else {
Deserializer reader;
reader = _serializerFactory.getObjectDeserializer(type, cl);
reader = _serializerFactory.getObjectDeserializer(type, expectedClass);

return reader.readMap(this);
return reader.readMap(this
, keyValuePair ? expectedTypes[0] : null
, keyValuePair ? expectedTypes[1] : null);
}
}

Expand All @@ -1010,12 +1025,14 @@ public Object readObject(Class cl)
Deserializer reader;
reader = _serializerFactory.getObjectDeserializer(type);

if (cl != reader.getType() && cl.isAssignableFrom(reader.getType()))
return reader.readList(this, length);
boolean valueType = expectedTypes != null && expectedTypes.length == 1;

if (expectedClass != reader.getType() && expectedClass.isAssignableFrom(reader.getType()))
return reader.readList(this, length, valueType ? expectedTypes[0] : null);

reader = _serializerFactory.getDeserializer(cl);
reader = _serializerFactory.getDeserializer(expectedClass);

Object v = reader.readList(this, length);
Object v = reader.readList(this, length, valueType ? expectedTypes[0] : null);

return v;
}
Expand All @@ -1039,7 +1056,7 @@ public Object readObject(Class cl)
// hessian/332i vs hessian/3406
//return readObject();

Object value = _serializerFactory.getDeserializer(cl).readObject(this);
Object value = _serializerFactory.getDeserializer(expectedClass).readObject(this);

return value;
}
Expand All @@ -1050,6 +1067,15 @@ public Object readObject(Class cl)
*/
public Object readObject()
throws IOException {
return readObject((List<Class<?>>) null);
}

/**
* Reads an arbitrary object from the input stream when the type
* is unknown.
*/
public Object readObject(List<Class<?>> expectedTypes)
throws IOException {
int tag = read();

switch (tag) {
Expand Down Expand Up @@ -1114,13 +1140,29 @@ public Object readObject()
String type = readType();
int length = readLength();

return _serializerFactory.readList(this, length, type);
Deserializer reader;
reader = _serializerFactory.getObjectDeserializer(type);

boolean valueType = expectedTypes != null && expectedTypes.size() == 1;

if (List.class != reader.getType() && List.class.isAssignableFrom(reader.getType()))
return reader.readList(this, length);

reader = _serializerFactory.getDeserializer(List.class);

Object v = reader.readList(this, length, valueType ? expectedTypes.get(0) : null);

return v;
}

case 'M': {
String type = readType();

return _serializerFactory.readMap(this, type);
boolean keyValuePair = expectedTypes != null && expectedTypes.size() == 2;

return _serializerFactory.readMap(this, type
, keyValuePair ? expectedTypes.get(0) : null
, keyValuePair ? expectedTypes.get(1) : null);
}

case 'R': {
Expand Down
Loading