Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
x956 committed Sep 21, 2023
1 parent 5194171 commit 448c334
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
package com.taobao.arthas.grpcweb.proxy;

import com.taobao.arthas.grpcweb.proxy.MessageUtils.ContentType;
import com.taobao.arthas.grpcweb.proxy.util.IOUtils;
import com.taobao.arthas.common.IOUtils;
import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
Expand Down Expand Up @@ -63,7 +62,7 @@ public boolean processInput(InputStream in, MessageUtils.ContentType contentType
byte[] inBytes;
try {
InputStream inStream = (contentType == ContentType.GRPC_WEB_TEXT) ? Base64.getDecoder().wrap(in) : in;
inBytes = IOUtils.toByteArray(inStream);
inBytes = IOUtils.getBytes(inStream);
} catch (IOException e) {
e.printStackTrace();
logger.warn("invalid input");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.taobao.arthas.grpcweb.proxy;

import com.google.common.annotations.VisibleForTesting;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.grpc.Metadata;
import io.netty.handler.codec.http.HttpHeaders;

import java.util.*;

class MetadataUtil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.netty.handler.stream.ChunkedStream;
import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

package com.taobao.arthas.grpcweb.proxy.server;


import com.taobao.arthas.grpcweb.proxy.GrpcServiceConnectionManager;
import com.taobao.arthas.grpcweb.proxy.GrpcWebRequestHandler;
import io.netty.buffer.Unpooled;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.taobao.arthas.grpcweb.proxy.server;

import io.netty.bootstrap.ServerBootstrap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.taobao.arthas.grpcweb.proxy.server;

import io.netty.channel.ChannelInitializer;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@ public void startServer(){
GRPC_PORT = SocketUtils.findAvailableTcpPort();
// 启动grpc服务
Thread grpcStart = new Thread(() -> {
startGrpcTest startGrpcTest = new startGrpcTest(GRPC_PORT);
StartGrpcTest startGrpcTest = new StartGrpcTest(GRPC_PORT);
startGrpcTest.startGrpcService();
});
grpcStart.start();
// 启动grpc-web-proxy服务
Thread grpcWebProxyStart = new Thread(() -> {
startGrpcWebProxyTest startGrpcWebProxyTest = new startGrpcWebProxyTest(GRPC_WEB_PROXY_PORT,GRPC_PORT);
StartGrpcWebProxyTest startGrpcWebProxyTest = new StartGrpcWebProxyTest(GRPC_WEB_PROXY_PORT,GRPC_PORT);
startGrpcWebProxyTest.startGrpcWebProxy();
});
grpcWebProxyStart.start();
try {
// waiting for the server to start
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
hostName = "http://127.0.0.1:" + GRPC_WEB_PROXY_PORT;
httpClient = HttpClients.createDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import com.taobao.arthas.grpcweb.proxy.server.grpcService.GreeterService;
import com.taobao.arthas.grpcweb.proxy.server.grpcService.HelloImpl;
import io.grpc.BindableService;
import io.grpc.Grpc;
import io.grpc.Server;
import io.grpc.ServerBuilder;

import java.io.IOException;

public class startGrpcTest {
public class StartGrpcTest {

private int GRPC_PORT;

public startGrpcTest(int grpcPort){
public StartGrpcTest(int grpcPort){
this.GRPC_PORT = grpcPort;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.taobao.arthas.grpcweb.proxy.server;

public class startGrpcWebProxyTest {
public class StartGrpcWebProxyTest {

private int GRPC_WEB_PROXY_PORT;

private int GRPC_PORT;


public startGrpcWebProxyTest(int grpcWebPort, int grpcPort){
public StartGrpcWebProxyTest(int grpcWebPort, int grpcPort){
this.GRPC_WEB_PROXY_PORT = grpcWebPort;
this.GRPC_PORT = grpcPort;
}
Expand Down

0 comments on commit 448c334

Please sign in to comment.