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

native hessian merge #3966

Merged
merged 11 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-native-hession</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-jdk</artifactId>
Leishunyu marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -583,6 +590,7 @@
<include>org.apache.dubbo:dubbo-metadata-report-zookeeper</include>
<include>org.apache.dubbo:dubbo-metadata-report-consul</include>
<include>org.apache.dubbo:dubbo-metadata-report-etcd</include>
<include>org.apache.dubbo:dubbo-serialization-native-hession</include>
</includes>
</artifactSet>
<transformers>
Expand Down
5 changes: 5 additions & 0 deletions dubbo-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@
<artifactId>dubbo-serialization-hessian2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-native-hession</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-jdk</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions dubbo-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@
<artifactId>dubbo-serialization-hessian2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-native-hession</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-jdk</artifactId>
Expand Down
42 changes: 42 additions & 0 deletions dubbo-serialization/dubbo-serialization-native-hession/pom.xml
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>
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);
}

}
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();
}
}
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);
}

}
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);
}
}
Loading