Skip to content

Commit

Permalink
[SCB-2245]upgrade netty to 4.1.66 and vert.x to 4.1.1 (#2394)
Browse files Browse the repository at this point in the history
* [SCB-2245]upgrade netty to 4.1.63 and vert.x to 4.0.3

* [SCB-2245]fix compile errors in foundation-test-scaffolding

* [SCB-2245]fix compile errors in foundation-vertx(part1)

* [SCB-2245]fix compile errors in foundation-vertx(part2)

* [SCB-2245]fix compile errors in foundation-registry

* [SCB-2245]fix compile errors in common-rest and common-access-log

* [SCB-2245]fix compile errors in transport-rest-client

* [SCB-2245]fix compile errors in dynamic-config/ede/metrics/transports

* [SCB-2245]fix problems of vert.x bug and wrong usage of client

* [SCB-2245]use latest version and fix thread name/common dispatcher problem

* [SCB-2245]fix options 204 change

* [SCB-2245]fix websocket thread size change

* [SCB-2245]fix NPE in rest client

* [SCB-2245]recover vert.x connect timeout bug and change logs setting

* [SCB-2245]add logs to diagnosis upload failure

* [SCB-2245]do not care about generated jacoco file length

* [SCB-2245]fix upload randomly fail

* [SCB-2245]use latest version and rebase code

* [SCB-2245]fix problems in metrics

* [SCB-2245]fix problems in metrics and todos
  • Loading branch information
liubao68 committed Jul 22, 2021
1 parent 867c762 commit 9a900be
Show file tree
Hide file tree
Showing 83 changed files with 1,530 additions and 1,691 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public void appendClientFormattedItem(InvocationFinishEvent finishEvent, StringB
return;
}
RestClientRequestImpl restRequestImpl = (RestClientRequestImpl) finishEvent.getInvocation().getHandlerContext()
.get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
.get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
if (null == restRequestImpl || null == restRequestImpl.getRequest()
|| null == restRequestImpl.getRequest().method()) {
|| null == restRequestImpl.getRequest().getMethod()) {
builder.append(EMPTY_RESULT);
return;
}
builder.append(restRequestImpl.getRequest().method().toString());
builder.append(restRequestImpl.getRequest().getMethod().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.mockito.Mockito;

import io.vertx.core.http.Cookie;
import io.vertx.core.http.impl.CookieImpl;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.impl.CookieImpl;

public class CookieItemTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void serverFormattedElement() {
@Test
public void clientFormattedElement() {
String uri = "/test/uri";
when(clientRequest.method()).thenReturn(HttpMethod.DELETE);
when(clientRequest.getMethod()).thenReturn(HttpMethod.DELETE);
when(clientRequest.path()).thenReturn(uri);
when(urlEndpoint.isHttp2Enabled()).thenReturn(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void serverFormattedElement() {
@Test
public void clientFormattedElement() {
when(restClientRequest.getRequest()).thenReturn(clientRequest);
when(clientRequest.method()).thenReturn(HttpMethod.DELETE);
when(clientRequest.getMethod()).thenReturn(HttpMethod.DELETE);
ITEM.appendClientFormattedItem(finishEvent, strBuilder);
Assert.assertEquals("DELETE", strBuilder.toString());
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public void serverFormattedElementOnMethodIsNull() {

@Test
public void clientFormattedElementOnMethodIsNull() {
when(clientRequest.method()).thenReturn(null);
when(clientRequest.getMethod()).thenReturn(null);
ITEM.appendClientFormattedItem(finishEvent, strBuilder);
Assert.assertEquals("-", strBuilder.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.impl.headers.VertxHttpHeaders;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import io.vertx.ext.web.RoutingContext;

public class RequestHeaderItemTest {
Expand Down Expand Up @@ -78,7 +78,7 @@ public void initStrBuilder() {

@Test
public void serverFormattedElement() {
VertxHttpHeaders headers = new VertxHttpHeaders();
HeadersMultiMap headers = new HeadersMultiMap();
String testValue = "testValue";
headers.add(VAR_NAME, testValue);
when(routingContext.request()).thenReturn(serverRequest);
Expand Down Expand Up @@ -129,7 +129,7 @@ public void clientFormattedElementIfHeaderIsNull() {

@Test
public void serverFormattedElementIfNotFound() {
VertxHttpHeaders headers = new VertxHttpHeaders();
HeadersMultiMap headers = new HeadersMultiMap();
String testValue = "testValue";
headers.add("anotherKey", testValue);
when(routingContext.request()).thenReturn(serverRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.http.impl.headers.VertxHttpHeaders;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import io.vertx.ext.web.RoutingContext;

public class ResponseHeaderItemTest {
Expand Down Expand Up @@ -64,7 +64,7 @@ public void initStrBuilder() {

@Test
public void serverFormattedElement() {
VertxHttpHeaders headers = new VertxHttpHeaders();
HeadersMultiMap headers = new HeadersMultiMap();
String headerValue = "headerValue";
headers.add(VAR_NAME, headerValue);
when(routingContext.response()).thenReturn(serverResponse);
Expand Down Expand Up @@ -122,7 +122,7 @@ public void clientFormattedElementOnResponseIsNull() {

@Test
public void serverFormattedElementOnNotFound() {
VertxHttpHeaders headers = new VertxHttpHeaders();
HeadersMultiMap headers = new HeadersMultiMap();
String headerValue = "headerValue";
headers.add("anotherHeader", headerValue);
when(routingContext.response()).thenReturn(serverResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import org.apache.servicecomb.common.rest.codec.RestClientRequest;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.foundation.common.utils.PartUtils;
import org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
import org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream;
import org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream;
import org.apache.servicecomb.foundation.vertx.stream.PumpFromPart;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.slf4j.Logger;
Expand All @@ -45,6 +47,7 @@
import com.google.common.collect.Multimap;

import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
Expand All @@ -68,14 +71,14 @@ public class RestClientRequestImpl implements RestClientRequest {

protected Buffer bodyBuffer;

private Handler<Throwable> throwableHandler;
private final Handler<Throwable> throwableHandler;

public RestClientRequestImpl(HttpClientRequest request, Context context, AsyncResponse asyncResp) {
this(request, context, asyncResp, null);
}

public RestClientRequestImpl(HttpClientRequest request, Context context, AsyncResponse asyncResp,
Handler<Throwable> throwableHandler) {
Handler<Throwable> throwableHandler) {
this.context = context;
this.asyncResp = asyncResp;
this.request = request;
Expand Down Expand Up @@ -135,14 +138,12 @@ protected void doEndWithUpload() {
String boundary = "boundary" + UUID.randomUUID().toString();
putHeader(CONTENT_TYPE, MULTIPART_FORM_DATA + "; charset=UTF-8; boundary=" + boundary);

genBodyForm(boundary);

attachFiles(boundary);
genBodyForm(boundary).onSuccess(v -> attachFiles(boundary)).onFailure(e -> asyncResp.consumerFail(e));
}

private void genBodyForm(String boundary) {
private Future<Void> genBodyForm(String boundary) {
if (formMap == null) {
return;
return Future.succeededFuture();
}

try {
Expand All @@ -156,10 +157,11 @@ private void genBodyForm(String boundary) {
output.write(value.getBytes(StandardCharsets.UTF_8));
}
}
request.write(output.getBuffer());

return writeBuffer(output.getBuffer());
}
} catch (Exception e) {
asyncResp.consumerFail(e);
return Future.failedFuture(e);
}
}

Expand Down Expand Up @@ -190,8 +192,7 @@ private void attachFiles(String boundary) {

private void attachFile(String boundary, Iterator<Entry<String, Part>> uploadsIterator) {
if (!uploadsIterator.hasNext()) {
request.write(boundaryEndInfo(boundary));
request.end();
writeBuffer(boundaryEndInfo(boundary)).onSuccess(v -> request.end()).onFailure(e -> asyncResp.consumerFail(e));
return;
}

Expand All @@ -201,19 +202,19 @@ private void attachFile(String boundary, Iterator<Entry<String, Part>> uploadsIt
String name = entry.getKey();
Part part = entry.getValue();
String filename = part.getSubmittedFileName();
Buffer fileHeader = fileBoundaryInfo(boundary, name, part);
request.write(fileHeader);

new PumpFromPart(context, part).toWriteStream(request, throwableHandler).whenComplete((v, e) -> {
if (e != null) {
LOGGER.debug("Failed to sending file [{}:{}].", name, filename, e);
asyncResp.consumerFail(e);
return;
}

LOGGER.debug("finish sending file [{}:{}].", name, filename);
attachFile(boundary, uploadsIterator);
});
LOGGER.debug("Start attach file [{}:{}].", name, filename);
writeBuffer(fileBoundaryInfo(boundary, name, part)).onSuccess(r ->
new PumpFromPart(context, part).toWriteStream(request, throwableHandler).whenComplete((v, e) -> {
if (e != null) {
LOGGER.warn("Failed attach file [{}:{}].", name, filename, e);
asyncResp.consumerFail(e);
return;
}

LOGGER.debug("Finish attach file [{}:{}].", name, filename);
attachFile(boundary, uploadsIterator);
})).onFailure(e -> asyncResp.consumerFail(e));
}

private Buffer boundaryEndInfo(String boundary) {
Expand All @@ -237,6 +238,11 @@ protected Buffer fileBoundaryInfo(String boundary, String name, Part part) {
return buffer;
}

protected Future<Void> writeBuffer(Buffer buffer) {
return new InputStreamToReadStream(context,
new BufferInputStream(buffer.getByteBuf()), true).pipe().endOnComplete(false).to(request);
}

private void genBodyBuffer() throws Exception {
if (bodyBuffer != null) {
return;
Expand Down Expand Up @@ -289,10 +295,6 @@ public Map<String, String> getCookieMap() {
return cookieMap;
}

public Map<String, Object> getFormMap() {
return formMap;
}

@Override
public void addCookie(String name, String value) {
if (cookieMap == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import io.netty.buffer.Unpooled;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.impl.headers.VertxHttpHeaders;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
Expand Down Expand Up @@ -109,7 +109,7 @@ private void setupGetValue(Class<?> type) throws IOException {

@Before
public void before() {
headers = new VertxHttpHeaders();
headers = new HeadersMultiMap();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.google.common.collect.Multimap;

import io.vertx.core.Context;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClientRequest;
Expand All @@ -45,6 +46,9 @@ public class TestRestClientRequestImpl {
@Mocked
private HttpClientRequest request;

@Mocked
private Context context;

@Test
public void testForm() throws Exception {
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, null, null);
Expand Down Expand Up @@ -164,10 +168,10 @@ HttpClientRequest putHeader(String name, String value) {
result = uuid;
}
};
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, null, null);
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, context, null);
restClientRequest.doEndWithUpload();

Assert.assertEquals("multipart/form-data; charset=UTF-8; boundary=boundary00000000-0000-0000-0000-000000000000",
headers.get(HttpHeaders.CONTENT_TYPE.toString()));
headers.get(HttpHeaders.CONTENT_TYPE));
}
}

This file was deleted.

0 comments on commit 9a900be

Please sign in to comment.