Skip to content

Commit

Permalink
Merge branch 'master' into support_fastjsonutils
Browse files Browse the repository at this point in the history
  • Loading branch information
wangchengming666 authored May 11, 2024
2 parents 0669330 + 12fbfe1 commit 7ca05cc
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 6 deletions.
8 changes: 7 additions & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<sofa.common.tools.version>1.3.15</sofa.common.tools.version>
<javassist.version>3.29.2-GA</javassist.version>
<netty.version>4.1.44.Final</netty.version>
<hessian.version>3.5.2</hessian.version>
<hessian.version>3.5.3</hessian.version>
<resteasy.version>3.6.3.Final</resteasy.version>
<bolt.version>1.6.6</bolt.version>
<tracer.version>3.0.8</tracer.version>
Expand All @@ -74,6 +74,7 @@
<guava.version>32.0.0-jre</guava.version>
<transmittable.version>2.12.1</transmittable.version>
<fury.version>0.4.1</fury.version>
<commons_compress_version>1.26.0</commons_compress_version>
</properties>

<dependencies>
Expand Down Expand Up @@ -445,6 +446,11 @@
<artifactId>fury-core</artifactId>
<version>${fury.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons_compress_version}</version>
</dependency>

</dependencies>

Expand Down
14 changes: 11 additions & 3 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<servlet.version>2.5</servlet.version>
<resteasy.version>3.6.3.Final</resteasy.version>
<jaxrs.api.version>1.0.2.Final</jaxrs.api.version>
<cxf.version>3.4.10</cxf.version>
<cxf.version>3.5.8</cxf.version>
<jetty.version>7.5.4.v20111024</jetty.version>
<zookeeper.version>3.5.7</zookeeper.version>
<curator.version>4.3.0</curator.version>
Expand All @@ -32,7 +32,7 @@
<guava.version>32.0.0-jre</guava.version>
<prometheus.client.version>0.16.0</prometheus.client.version>
<!-- serialization -->
<hessian.version>3.5.2</hessian.version>
<hessian.version>3.5.3</hessian.version>
<thrift.version>0.9.2</thrift.version>
<protobuf.version>3.22.0</protobuf.version>
<jackson.version>2.12.7</jackson.version>
Expand Down Expand Up @@ -63,6 +63,7 @@
<!-- Fabric8 for Kubernetes -->
<fabric8_kubernetes_version>6.9.2</fabric8_kubernetes_version>
<fastjson.version>1.2.83</fastjson.version>
<commons_compress_version>1.26.0</commons_compress_version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -521,7 +522,6 @@
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>

<!-- Fabric8 for Kubernetes -->
<dependency>
<groupId>io.fabric8</groupId>
Expand All @@ -535,6 +535,8 @@
<version>${fabric8_kubernetes_version}</version>
</dependency>



<!-- Test libs -->
<dependency>
<groupId>org.apache.curator</groupId>
Expand Down Expand Up @@ -619,6 +621,12 @@
<version>0.16.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons_compress_version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
5 changes: 5 additions & 0 deletions codec/codec-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 com.alipay.sofa.rpc.codec.bzip2;

import com.alipay.sofa.rpc.codec.Compressor;
import com.alipay.sofa.rpc.ext.Extension;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

/**
* bzip2 compressor, faster compression efficiency
*
* @author chengming
* @version Bzip2RpcCompressor.java, v 0.1 2024年02月28日 10:45 AM chengming
* @link https://commons.apache.org/proper/commons-compress/
*/
@Extension(value = "bzip2", code = 3)
public class Bzip2RpcCompressor implements Compressor {

@Override
public byte[] compress(byte[] src) {
if (null == src || 0 == src.length) {
return new byte[0];
}

ByteArrayOutputStream out = new ByteArrayOutputStream();
BZip2CompressorOutputStream cos;
try {
cos = new BZip2CompressorOutputStream(out);
cos.write(src);
cos.close();
} catch (Exception e) {
throw new IllegalStateException(e);
}

return out.toByteArray();
}

@Override
public byte[] deCompress(byte[] src) {
if (null == src || 0 == src.length) {
return new byte[0];
}

ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(src);
try {
BZip2CompressorInputStream unZip = new BZip2CompressorInputStream(in);
byte[] buffer = new byte[2048];
int n;
while ((n = unZip.read(buffer)) >= 0) {
out.write(buffer, 0, n);
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
return out.toByteArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 com.alipay.sofa.rpc.codec.gzip;

import com.alipay.sofa.rpc.codec.Compressor;
import com.alipay.sofa.rpc.ext.Extension;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/**
* @author chengming
* @version GzipRpcCompressor.java, v 0.1 2024年02月28日 11:25 AM chengming
*/
@Extension(value = "gzip", code = 4)
public class GzipRpcCompressor implements Compressor {

@Override
public byte[] compress(byte[] src) {
if (null == src || 0 == src.length) {
return new byte[0];
}

ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteOutStream)) {
gzipOutputStream.write(src);
} catch (Exception exception) {
throw new IllegalStateException(exception);
}

return byteOutStream.toByteArray();
}

@Override
public byte[] deCompress(byte[] src) {
if (null == src || 0 == src.length) {
return new byte[0];
}

ByteArrayInputStream byteInStream = new ByteArrayInputStream(src);
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
try (GZIPInputStream gzipInputStream = new GZIPInputStream(byteInStream)) {
int readByteNum;
byte[] bufferArr = new byte[256];
while ((readByteNum = gzipInputStream.read(bufferArr)) >= 0) {
byteOutStream.write(bufferArr, 0, readByteNum);
}
} catch (Exception exception) {
throw new IllegalStateException(exception);
}

return byteOutStream.toByteArray();
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
snappy=com.alipay.sofa.rpc.codec.snappy.SnappyRpcCompressor
snappy=com.alipay.sofa.rpc.codec.snappy.SnappyRpcCompressor
bzip2=com.alipay.sofa.rpc.codec.bzip2.Bzip2RpcCompressor
gzip=com.alipay.sofa.rpc.codec.gzip.GzipRpcCompressor
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 com.alipay.sofa.rpc.codec.bzip2;

import com.alipay.sofa.rpc.codec.Compressor;
import com.alipay.sofa.rpc.ext.ExtensionLoaderFactory;
import org.junit.Assert;
import org.junit.Test;

import java.io.UnsupportedEncodingException;

/**
* @author chengming
* @version Bzip2RpcCompressorTest.java, v 0.1 2024年02月28日 2:19 PM chengming
*/
public class Bzip2RpcCompressorTest {

private static final String TEST_STR;

static {
StringBuilder builder = new StringBuilder();
int charNum = 1000000;
for (int i = 0; i < charNum; i++) {
builder.append("a");
}

TEST_STR = builder.toString();
}

@Test
public void testCompression() throws UnsupportedEncodingException {
Compressor compressor = ExtensionLoaderFactory.getExtensionLoader(Compressor.class).getExtension("bzip2");
Assert.assertTrue(compressor instanceof Bzip2RpcCompressor);

byte[] bs = compressor.compress(TEST_STR.getBytes("utf-8"));
String s1 = new String(compressor.deCompress(bs), "utf-8");
Assert.assertEquals(TEST_STR, s1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 com.alipay.sofa.rpc.codec.gzip;

import com.alipay.sofa.rpc.codec.Compressor;
import com.alipay.sofa.rpc.ext.ExtensionLoaderFactory;
import org.junit.Assert;
import org.junit.Test;

import java.io.UnsupportedEncodingException;

/**
* @author chengming
* @version GzipRpcCompressorTest.java, v 0.1 2024年02月28日 2:09 PM chengming
*/
public class GzipRpcCompressorTest {

private static final String TEST_STR;

static {
StringBuilder builder = new StringBuilder();
int charNum = 1000000;
for (int i = 0; i < charNum; i++) {
builder.append("a");
}

TEST_STR = builder.toString();
}

@Test
public void testCompression() throws UnsupportedEncodingException {
Compressor compressor = ExtensionLoaderFactory.getExtensionLoader(Compressor.class).getExtension("gzip");
Assert.assertTrue(compressor instanceof GzipRpcCompressor);

byte[] bs = compressor.compress(TEST_STR.getBytes("utf-8"));
String s1 = new String(compressor.deCompress(bs), "utf-8");
Assert.assertEquals(TEST_STR, s1);
}

}
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>build/generated/source/proto/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ protected void parseRequestHeader(Map<String, String> headerMap, Object sofaRequ
if (sofaRequest instanceof SofaRequest) {
// 处理 tracer
parseRequestHeader(RemotingConstants.RPC_TRACE_NAME, headerMap, (SofaRequest) sofaRequest);
if (RpcInvokeContext.isBaggageEnable()) {
parseRequestHeader(RemotingConstants.RPC_REQUEST_BAGGAGE, headerMap, (SofaRequest) sofaRequest);
}
Map<String, Object> requestProps = ((SofaRequest) sofaRequest).getRequestProps();
if (requestProps == null) {
for (Map.Entry<String, String> entry : headerMap.entrySet()) {
Expand Down
Loading

0 comments on commit 7ca05cc

Please sign in to comment.