-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge serialization-native-hessian-for-apache-dubbo into incubator-dubbo * test success * test success * Merge serialization-native-hessian-for-apache-dubbo into incubator-dubbo * change maven install * add apache license * remove @generated * optimize import * remove thrift * merge master * distribution pom add native hessian
- Loading branch information
Showing
28 changed files
with
1,449 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
dubbo-serialization/dubbo-serialization-native-hession/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!-- | ||
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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>dubbo-serialization</artifactId> | ||
<groupId>org.apache.dubbo</groupId> | ||
<version>${revision}</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>dubbo-serialization-native-hession</artifactId> | ||
<packaging>jar</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>The native-hession serialization module of dubbo project</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-serialization-api</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.caucho</groupId> | ||
<artifactId>hessian</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
98 changes: 98 additions & 0 deletions
98
...-native-hession/src/main/java/org/apache/dubbo/serialize/hessian/Hessian2ObjectInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.dubbo.serialize.hessian; | ||
|
||
import com.caucho.hessian.io.Hessian2Input; | ||
import org.apache.dubbo.common.serialize.ObjectInput; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* Hessian2 Object input. | ||
*/ | ||
public class Hessian2ObjectInput implements ObjectInput { | ||
private final Hessian2Input input; | ||
|
||
public Hessian2ObjectInput(InputStream is) { | ||
input = new Hessian2Input(is); | ||
input.setSerializerFactory(Hessian2SerializerFactory.INSTANCE); | ||
} | ||
|
||
@Override | ||
public boolean readBool() throws IOException { | ||
return input.readBoolean(); | ||
} | ||
|
||
@Override | ||
public byte readByte() throws IOException { | ||
return (byte) input.readInt(); | ||
} | ||
|
||
@Override | ||
public short readShort() throws IOException { | ||
return (short) input.readInt(); | ||
} | ||
|
||
@Override | ||
public int readInt() throws IOException { | ||
return input.readInt(); | ||
} | ||
|
||
@Override | ||
public long readLong() throws IOException { | ||
return input.readLong(); | ||
} | ||
|
||
@Override | ||
public float readFloat() throws IOException { | ||
return (float) input.readDouble(); | ||
} | ||
|
||
@Override | ||
public double readDouble() throws IOException { | ||
return input.readDouble(); | ||
} | ||
|
||
@Override | ||
public byte[] readBytes() throws IOException { | ||
return input.readBytes(); | ||
} | ||
|
||
@Override | ||
public String readUTF() throws IOException { | ||
return input.readString(); | ||
} | ||
|
||
@Override | ||
public Object readObject() throws IOException { | ||
return input.readObject(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T> T readObject(Class<T> cls) throws IOException { | ||
return (T) input.readObject(cls); | ||
} | ||
|
||
@Override | ||
public <T> T readObject(Class<T> cls, Type type) throws IOException { | ||
return readObject(cls); | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
...native-hession/src/main/java/org/apache/dubbo/serialize/hessian/Hessian2ObjectOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.dubbo.serialize.hessian; | ||
|
||
import com.caucho.hessian.io.Hessian2Output; | ||
import org.apache.dubbo.common.serialize.ObjectOutput; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* Hessian2 Object output. | ||
*/ | ||
public class Hessian2ObjectOutput implements ObjectOutput { | ||
private final Hessian2Output output; | ||
|
||
public Hessian2ObjectOutput(OutputStream os) { | ||
output = new Hessian2Output(os); | ||
output.setSerializerFactory(Hessian2SerializerFactory.INSTANCE); | ||
} | ||
|
||
@Override | ||
public void writeBool(boolean v) throws IOException { | ||
output.writeBoolean(v); | ||
} | ||
|
||
@Override | ||
public void writeByte(byte v) throws IOException { | ||
output.writeInt(v); | ||
} | ||
|
||
@Override | ||
public void writeShort(short v) throws IOException { | ||
output.writeInt(v); | ||
} | ||
|
||
@Override | ||
public void writeInt(int v) throws IOException { | ||
output.writeInt(v); | ||
} | ||
|
||
@Override | ||
public void writeLong(long v) throws IOException { | ||
output.writeLong(v); | ||
} | ||
|
||
@Override | ||
public void writeFloat(float v) throws IOException { | ||
output.writeDouble(v); | ||
} | ||
|
||
@Override | ||
public void writeDouble(double v) throws IOException { | ||
output.writeDouble(v); | ||
} | ||
|
||
@Override | ||
public void writeBytes(byte[] b) throws IOException { | ||
output.writeBytes(b); | ||
} | ||
|
||
@Override | ||
public void writeBytes(byte[] b, int off, int len) throws IOException { | ||
output.writeBytes(b, off, len); | ||
} | ||
|
||
@Override | ||
public void writeUTF(String v) throws IOException { | ||
output.writeString(v); | ||
} | ||
|
||
@Override | ||
public void writeObject(Object obj) throws IOException { | ||
output.writeObject(obj); | ||
} | ||
|
||
@Override | ||
public void flushBuffer() throws IOException { | ||
output.flushBuffer(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ative-hession/src/main/java/org/apache/dubbo/serialize/hessian/Hessian2Serialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.dubbo.serialize.hessian; | ||
|
||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.common.serialize.ObjectInput; | ||
import org.apache.dubbo.common.serialize.ObjectOutput; | ||
import org.apache.dubbo.common.serialize.Serialization; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class Hessian2Serialization implements Serialization { | ||
|
||
@Override | ||
public byte getContentTypeId() { | ||
return 10; | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return "x-application/native-hessian"; | ||
} | ||
|
||
@Override | ||
public ObjectOutput serialize(URL url, OutputStream out) throws IOException { | ||
return new Hessian2ObjectOutput(out); | ||
} | ||
|
||
@Override | ||
public ObjectInput deserialize(URL url, InputStream is) throws IOException { | ||
return new Hessian2ObjectInput(is); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...e-hession/src/main/java/org/apache/dubbo/serialize/hessian/Hessian2SerializerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.dubbo.serialize.hessian; | ||
|
||
import com.caucho.hessian.io.Deserializer; | ||
import com.caucho.hessian.io.HessianProtocolException; | ||
import com.caucho.hessian.io.Serializer; | ||
import com.caucho.hessian.io.SerializerFactory; | ||
|
||
public class Hessian2SerializerFactory extends SerializerFactory { | ||
public static final SerializerFactory INSTANCE = new Hessian2SerializerFactory(); | ||
|
||
private Hessian2SerializerFactory() { | ||
super(); | ||
} | ||
|
||
@Override | ||
protected Serializer loadSerializer(Class<?> cl) throws HessianProtocolException { | ||
Serializer serializer = Java8SerializerFactory.INSTANCE.getSerializer(cl); | ||
return serializer != null ? serializer : super.loadSerializer(cl); | ||
} | ||
|
||
@Override | ||
protected Deserializer loadDeserializer(Class cl) throws HessianProtocolException { | ||
Deserializer deserializer = Java8SerializerFactory.INSTANCE.getDeserializer(cl); | ||
return deserializer != null ? deserializer : super.loadDeserializer(cl); | ||
} | ||
} |
Oops, something went wrong.