This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.3 by this push:
new ab6362e102 Some rest bugfix (#14511)
ab6362e102 is described below
commit ab6362e10265edd00f5e399b8474d2525eea0a1f
Author: Sean Yang <[email protected]>
AuthorDate: Mon Aug 12 10:06:47 2024 +0800
Some rest bugfix (#14511)
---
.../spring/SpringMvcRequestMappingResolver.java | 13 +-
.../tri/rest/support/servlet/FileUploadPart.java | 90 ++++++
.../tri/rest/support/servlet/FilterAdapter.java | 3 +-
.../protocol/tri/rest/support/servlet/Helper.java | 80 +-----
.../servlet/ServletHttpMessageAdapterFactory.java | 11 +-
.../support/servlet/ServletHttpRequestAdapter.java | 2 +-
.../http12/message/DefaultStreamingDecoder.java | 11 +-
.../remoting/http12/message/codec/HtmlCodec.java | 14 +-
.../http12/message/codec/MultipartDecoder.java | 270 ------------------
.../message/codec/MultipartDecoderFactory.java | 44 ---
.../http12/message/codec/PlainTextCodec.java | 14 +-
.../http12/message/codec/UrlEncodeFormCodec.java | 139 ----------
.../message/codec/UrlEncodeFormCodecFactory.java | 46 ----
...moting.http12.message.HttpMessageDecoderFactory | 2 -
...moting.http12.message.HttpMessageEncoderFactory | 1 -
.../http12/message/codec/CodeUtilsTest.java | 15 -
.../remoting/http12/message/codec/CodecTest.java | 304 ---------------------
.../rpc/protocol/tri/CancelableStreamObserver.java | 2 +-
.../dubbo/rpc/protocol/tri/DescriptorUtils.java | 2 +-
.../rpc/protocol/tri/ReflectionPackableMethod.java | 14 +-
.../rpc/protocol/tri/ServerStreamObserver.java | 7 +-
...per.java => TripleCustomerProtocolWrapper.java} | 2 +-
.../dubbo/rpc/protocol/tri/TripleHeaderEnum.java | 11 +-
.../dubbo/rpc/protocol/tri/TripleInvoker.java | 14 +-
.../protocol/tri/TripleScopeModelInitializer.java | 41 ---
.../TripleReflectionTypeDescriberRegistrar.java | 25 ++
.../rpc/protocol/tri/call/TripleClientCall.java | 4 +-
.../dubbo/rpc/protocol/tri/rest/Messages.java | 22 +-
.../dubbo/rpc/protocol/tri/rest/RestException.java | 4 +-
.../NamedValueArgumentResolverSupport.java | 5 +-
.../mapping/DefaultRequestMappingRegistry.java | 22 +-
.../tri/rest/mapping/meta/AnnotationSupport.java | 6 +-
.../protocol/tri/rest/mapping/meta/MethodMeta.java | 4 +-
.../tri/rest/mapping/meta/NamedValueMeta.java | 11 +
.../support/basic/FallbackArgumentResolver.java | 2 +-
.../rest/support/basic/ParamArgumentResolver.java | 2 +-
...rg.apache.dubbo.rpc.model.ScopeModelInitializer | 1 -
...java => TripleCustomerProtocolWrapperTest.java} | 48 ++--
.../rpc/protocol/tri/test/TestRunnerImpl.java | 3 +-
.../protocol/tri/test/UrlEncodeFormEncoder.java | 73 +++++
40 files changed, 322 insertions(+), 1062 deletions(-)
diff --git
a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java
b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java
index bdb3aff019..428f4f9d18 100644
---
a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java
+++
b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringMvcRequestMappingResolver.java
@@ -36,25 +36,16 @@ import org.springframework.http.HttpStatus;
public class SpringMvcRequestMappingResolver implements RequestMappingResolver
{
private final FrameworkModel frameworkModel;
- private volatile RestToolKit toolKit;
+ private final RestToolKit toolKit;
private CorsMeta globalCorsMeta;
public SpringMvcRequestMappingResolver(FrameworkModel frameworkModel) {
this.frameworkModel = frameworkModel;
+ toolKit = new SpringRestToolKit(frameworkModel);
}
@Override
public RestToolKit getRestToolKit() {
- RestToolKit toolKit = this.toolKit;
- if (toolKit == null) {
- synchronized (this) {
- toolKit = this.toolKit;
- if (toolKit == null) {
- toolKit = new SpringRestToolKit(frameworkModel);
- this.toolKit = toolKit;
- }
- }
- }
return toolKit;
}
diff --git
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/FileUploadPart.java
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/FileUploadPart.java
new file mode 100644
index 0000000000..b6e6bcbfa6
--- /dev/null
+++
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/FileUploadPart.java
@@ -0,0 +1,90 @@
+/*
+ * 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.rpc.protocol.tri.rest.support.servlet;
+
+import org.apache.dubbo.common.io.StreamUtils;
+import org.apache.dubbo.remoting.http12.HttpRequest;
+import org.apache.dubbo.rpc.protocol.tri.rest.RestException;
+
+import javax.servlet.http.Part;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Collections;
+
+public final class FileUploadPart implements Part {
+
+ private final HttpRequest.FileUpload fileUpload;
+
+ public FileUploadPart(HttpRequest.FileUpload fileUpload) {
+ this.fileUpload = fileUpload;
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ return fileUpload.inputStream();
+ }
+
+ @Override
+ public String getContentType() {
+ return fileUpload.contentType();
+ }
+
+ @Override
+ public String getName() {
+ return fileUpload.name();
+ }
+
+ @Override
+ public String getSubmittedFileName() {
+ return fileUpload.filename();
+ }
+
+ @Override
+ public long getSize() {
+ return fileUpload.size();
+ }
+
+ @Override
+ public void write(String fileName) {
+ try (FileOutputStream fos = new FileOutputStream(fileName)) {
+ StreamUtils.copy(fileUpload.inputStream(), fos);
+ } catch (IOException e) {
+ throw new RestException(e);
+ }
+ }
+
+ @Override
+ public void delete() {}
+
+ @Override
+ public String getHeader(String name) {
+ return null;
+ }
+
+ @Override
+ public Collection<String> getHeaders(String name) {
+ return null;
+ }
+
+ @Override
+ public Collection<String> getHeaderNames() {
+ return Collections.emptyList();
+ }
+}
diff --git
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/FilterAdapter.java
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/FilterAdapter.java
index f4a4bc46b0..4cea16fce0 100644
---
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/FilterAdapter.java
+++
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/FilterAdapter.java
@@ -27,6 +27,7 @@ import
org.apache.dubbo.rpc.protocol.tri.rest.filter.RestFilter;
import org.apache.dubbo.rpc.protocol.tri.rest.util.RestUtils;
import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@@ -53,7 +54,7 @@ public final class FilterAdapter implements
RestExtensionAdapter<Filter> {
public RestFilter adapt(Filter extension) {
try {
String filterName = extension.getClass().getSimpleName();
- extension.init(adapterFactory.adaptFilterConfig(filterName));
+ extension.init((FilterConfig)
adapterFactory.adaptFilterConfig(filterName));
} catch (ServletException e) {
throw new RestException(e);
}
diff --git
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/Helper.java
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/Helper.java
index a341fa686a..32ab988b2a 100644
---
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/Helper.java
+++
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/Helper.java
@@ -16,20 +16,12 @@
*/
package org.apache.dubbo.rpc.protocol.tri.rest.support.servlet;
-import org.apache.dubbo.common.io.StreamUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.remoting.http12.HttpCookie;
import org.apache.dubbo.remoting.http12.HttpRequest.FileUpload;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-import org.apache.dubbo.rpc.protocol.tri.rest.RestException;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
import javax.servlet.http.Part;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -70,7 +62,7 @@ final class Helper {
return cookie;
}
- public static Part convert(FileUpload part) {
+ public static FileUploadPart convert(FileUpload part) {
return new FileUploadPart(part);
}
@@ -84,74 +76,4 @@ final class Helper {
}
return result;
}
-
- public static final class FileUploadPart implements Part {
-
- private final FileUpload fileUpload;
-
- public FileUploadPart(FileUpload fileUpload) {
- this.fileUpload = fileUpload;
- }
-
- @Override
- public InputStream getInputStream() {
- return fileUpload.inputStream();
- }
-
- @Override
- public String getContentType() {
- return fileUpload.contentType();
- }
-
- @Override
- public String getName() {
- return fileUpload.name();
- }
-
- @Override
- public String getSubmittedFileName() {
- return fileUpload.filename();
- }
-
- @Override
- public long getSize() {
- return fileUpload.size();
- }
-
- @Override
- public void write(String fileName) {
- try (FileOutputStream fos = new FileOutputStream(fileName)) {
- StreamUtils.copy(fileUpload.inputStream(), fos);
- } catch (IOException e) {
- throw new RestException(e);
- }
- }
-
- @Override
- public void delete() {}
-
- @Override
- public String getHeader(String name) {
- return null;
- }
-
- @Override
- public Collection<String> getHeaders(String name) {
- return null;
- }
-
- @Override
- public Collection<String> getHeaderNames() {
- return Collections.emptyList();
- }
- }
-
- public static ServletContext createDummyServletContext(FrameworkModel
frameworkModel) {
- return new DummyServletContext(frameworkModel);
- }
-
- public static FilterConfig createDummyFilterConfig(
- String filterName, FrameworkModel frameworkModel, ServletContext
servletContext) {
- return new DummyFilterConfig(filterName, frameworkModel,
servletContext);
- }
}
diff --git
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpMessageAdapterFactory.java
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpMessageAdapterFactory.java
index b10579ad81..1861d42beb 100644
---
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpMessageAdapterFactory.java
+++
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpMessageAdapterFactory.java
@@ -24,7 +24,6 @@ import
org.apache.dubbo.remoting.http12.message.HttpMessageAdapterFactory;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension;
-import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
@Activate(order = -100, onClass = "javax.servlet.http.HttpServletRequest")
@@ -37,7 +36,7 @@ public final class ServletHttpMessageAdapterFactory
public ServletHttpMessageAdapterFactory(FrameworkModel frameworkModel) {
this.frameworkModel = frameworkModel;
- servletContext = Helper.createDummyServletContext(frameworkModel);
+ servletContext = (ServletContext)
createDummyServletContext(frameworkModel);
httpSessionFactory = getHttpSessionFactory(frameworkModel);
}
@@ -60,7 +59,11 @@ public final class ServletHttpMessageAdapterFactory
return new ServletHttpResponseAdapter();
}
- public FilterConfig adaptFilterConfig(String filterName) {
- return Helper.createDummyFilterConfig(filterName, frameworkModel,
servletContext);
+ public Object adaptFilterConfig(String filterName) {
+ return new DummyFilterConfig(filterName, frameworkModel,
servletContext);
+ }
+
+ private Object createDummyServletContext(FrameworkModel frameworkModel) {
+ return new DummyServletContext(frameworkModel);
}
}
diff --git
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpRequestAdapter.java
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpRequestAdapter.java
index 46c7b9a637..248fe2e7a3 100644
---
a/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpRequestAdapter.java
+++
b/dubbo-plugin/dubbo-triple-servlet/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/servlet/ServletHttpRequestAdapter.java
@@ -236,7 +236,7 @@ public class ServletHttpRequestAdapter extends
DefaultHttpRequest implements Htt
}
@Override
- public Part getPart(String name) {
+ public FileUploadPart getPart(String name) {
return Helper.convert(part(name));
}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultStreamingDecoder.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultStreamingDecoder.java
index 939bbefc74..3d967c532d 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultStreamingDecoder.java
+++
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultStreamingDecoder.java
@@ -47,12 +47,13 @@ public class DefaultStreamingDecoder implements
StreamingDecoder {
@Override
public void close() {
try {
- if (!closed) {
- closed = true;
- listener.onFragmentMessage(accumulate);
- accumulate.close();
- listener.onClose();
+ if (closed) {
+ return;
}
+ closed = true;
+ listener.onFragmentMessage(accumulate);
+ accumulate.close();
+ listener.onClose();
} catch (IOException e) {
throw new DecodeException(e);
}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/HtmlCodec.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/HtmlCodec.java
index ca3fff4f10..5afc69b028 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/HtmlCodec.java
+++
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/HtmlCodec.java
@@ -17,13 +17,13 @@
package org.apache.dubbo.remoting.http12.message.codec;
import org.apache.dubbo.common.io.StreamUtils;
+import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.remoting.http12.exception.DecodeException;
import org.apache.dubbo.remoting.http12.exception.EncodeException;
import org.apache.dubbo.remoting.http12.exception.HttpStatusException;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
import org.apache.dubbo.remoting.http12.message.MediaType;
-import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
@@ -37,10 +37,12 @@ public class HtmlCodec implements HttpMessageCodec {
os.write((data.toString()).getBytes(charset));
return;
}
- } catch (IOException e) {
- throw new EncodeException(e);
+ os.write(JsonUtils.toJson(data).getBytes(charset));
+ } catch (HttpStatusException e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new EncodeException("Error encoding html", t);
}
- throw new EncodeException("'text/html' media-type only supports String
as return type.");
}
@Override
@@ -51,8 +53,8 @@ public class HtmlCodec implements HttpMessageCodec {
}
} catch (HttpStatusException e) {
throw e;
- } catch (Exception e) {
- throw new DecodeException(e);
+ } catch (Throwable t) {
+ throw new EncodeException("Error decoding html", t);
}
throw new DecodeException("'text/html' media-type only supports String
as method param.");
}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/MultipartDecoder.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/MultipartDecoder.java
deleted file mode 100644
index 2ac2618352..0000000000
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/MultipartDecoder.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * 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.remoting.http12.message.codec;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.remoting.http12.HttpHeaderNames;
-import org.apache.dubbo.remoting.http12.HttpHeaders;
-import org.apache.dubbo.remoting.http12.exception.DecodeException;
-import org.apache.dubbo.remoting.http12.message.HttpMessageDecoder;
-import org.apache.dubbo.remoting.http12.message.MediaType;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
-public class MultipartDecoder implements HttpMessageDecoder {
-
- private final URL url;
-
- private final FrameworkModel frameworkModel;
-
- private final String headerContentType;
-
- private final CodecUtils codecUtils;
-
- private static final String CRLF = "\r\n";
-
- public MultipartDecoder(URL url, FrameworkModel frameworkModel, String
contentType, CodecUtils codecUtils) {
- this.url = url;
- this.frameworkModel = frameworkModel;
- this.headerContentType = contentType;
- this.codecUtils = codecUtils;
- }
-
- @Override
- public Object decode(InputStream inputStream, Class<?> targetType, Charset
charset) throws DecodeException {
- Object[] res = decode(inputStream, new Class[] {targetType}, charset);
- return res.length > 1 ? res : res[0];
- }
-
- @Override
- public Object[] decode(InputStream inputStream, Class<?>[] targetTypes,
Charset charset) throws DecodeException {
- try {
- List<Part> parts = transferToParts(inputStream, headerContentType);
- if (parts.size() != targetTypes.length) {
- throw new DecodeException("The number of method parameters and
multipart request bodies are different");
- }
- Object[] res = new Object[parts.size()];
-
- for (int i = 0; i < parts.size(); i++) {
- Part part = parts.get(i);
-
- if (Byte[].class.equals(targetTypes[i]) ||
byte[].class.equals(targetTypes[i])) {
- res[i] = part.content;
- continue;
- }
- res[i] = codecUtils
- .determineHttpMessageDecoder(url, frameworkModel,
part.headers.getContentType())
- .decode(new ByteArrayInputStream(part.content),
targetTypes[i], charset);
- }
- return res;
- } catch (IOException ioException) {
- throw new DecodeException("Decode multipart body failed:" +
ioException.getMessage());
- }
- }
-
- private List<Part> transferToParts(InputStream inputStream, String
contentType) throws IOException {
- String boundary = getBoundaryFromContentType(contentType);
- if (StringUtils.isEmpty(boundary)) {
- throw new DecodeException("Invalid boundary in Content-Type: " +
contentType);
- }
-
- final String delimiter = "--" + boundary;
-
- List<Part> parts = new ArrayList<>();
- boolean endOfStream = false;
-
- while (!endOfStream) {
- ByteArrayOutputStream partData = new ByteArrayOutputStream();
- HttpHeaders headers = new HttpHeaders();
-
- endOfStream = readPart(inputStream, delimiter, headers, partData);
-
- if (partData.size() > 0) {
- parts.add(new Part(partData.toByteArray(), headers));
- }
- }
-
- return parts;
- }
-
- private String getBoundaryFromContentType(String contentType) {
- String[] parts = contentType.split(";");
- for (String part : parts) {
- part = part.trim();
- if (part.startsWith("boundary=")) {
- return part.substring("boundary=".length()).trim();
- }
- }
- return null;
- }
-
- private boolean readPart(
- InputStream inputStream, String delimiter, HttpHeaders headers,
ByteArrayOutputStream partData)
- throws IOException {
- // read and parse headers
- if (readHeaders(inputStream, headers, delimiter)) {
- // end of stream
- return true;
- }
- return readBody(inputStream, delimiter, partData);
- }
-
- private boolean readHeaders(InputStream inputStream, HttpHeaders
httpHeaders, String delimiter) throws IOException {
-
- StringBuilder fullHeaderBuilder = new StringBuilder();
- String fullHeader = null;
- byte[] buffer = new byte[128];
- int len;
- boolean headerEnd = false;
- boolean streamEnd = true;
- final String endOfHeaderSign = CRLF + CRLF;
-
- byte[] delimiterBuffer = new byte[delimiter.length()];
- if (inputStream.read(delimiterBuffer) == -1) {
- return true;
- }
- String readDelimiter = new String(delimiterBuffer,
StandardCharsets.US_ASCII);
- if (!Objects.equals(readDelimiter, delimiter)) {
- throw new DecodeException("Multipart body boundary are different
from header");
- }
- while (!headerEnd) {
-
- inputStream.mark(Integer.MAX_VALUE);
-
- len = inputStream.read(buffer);
- if (len == -1) {
- break;
- }
-
- // read to 2*CRLF (end of header)
- String currentString = new String(buffer, 0, len,
StandardCharsets.UTF_8);
- fullHeaderBuilder.append(currentString);
-
- // check if currentString contains CRLF
- int endIndex;
- if ((endIndex = fullHeaderBuilder.indexOf(endOfHeaderSign)) != -1)
{
- // make stream reset to body start of current part
- inputStream.reset();
- if (inputStream.skip(endIndex + endOfHeaderSign.length()) ==
endIndex + endOfHeaderSign.length()) {
- streamEnd = false;
- }
- headerEnd = true;
- fullHeader = fullHeaderBuilder.substring(delimiter.length(),
endIndex);
- }
- }
- if (streamEnd && !headerEnd) {
- throw new DecodeException("Broken request: cannot found multipart
body header end");
- }
-
- parseHeaderLine(httpHeaders, fullHeader.split(CRLF));
-
- if (httpHeaders.getContentType() == null) {
- httpHeaders.put(HttpHeaderNames.CONTENT_TYPE.getName(),
Collections.singletonList("text/plain"));
- }
-
- return streamEnd;
- }
-
- private void parseHeaderLine(HttpHeaders headers, String[] headerLines) {
- for (String headerLine : headerLines) {
- int colonIndex = headerLine.indexOf(':');
- if (colonIndex != -1) {
- String name = headerLine.substring(0, colonIndex).trim();
- String value = headerLine.substring(colonIndex + 1).trim();
- headers.put(name, Collections.singletonList(value));
- }
- }
- }
-
- private boolean readBody(InputStream inputStream, String delimiter,
ByteArrayOutputStream partData)
- throws IOException {
- byte[] buffer = new byte[256];
- int len;
-
- while (true) {
- inputStream.mark(Integer.MAX_VALUE);
- len = inputStream.read(buffer);
- if (len == -1) {
- return true;
- }
- String currentString = new String(buffer, 0, len,
StandardCharsets.US_ASCII);
- if (currentString.contains(delimiter)) {
- int indexOfDelimiter = currentString.indexOf(delimiter);
-
- // skip the CRLF of data tail
- byte[] toWrite = new byte[indexOfDelimiter - 2];
- System.arraycopy(buffer, 0, toWrite, 0, indexOfDelimiter - 2);
- partData.write(toWrite);
-
- // check end delimiter (--\r\n) to determine if this part is
the last body part
- // for compatibility with non-standard clients, we won't check
the last CRLF
- if (currentString.length() > indexOfDelimiter +
delimiter.length() + 1
- && currentString.charAt(indexOfDelimiter +
delimiter.length()) == '-'
- && currentString.charAt(indexOfDelimiter +
delimiter.length() + 1) == '-') {
- return true;
- }
-
- // read from stream to check end delimiter
- else if (currentString.length() <= indexOfDelimiter +
delimiter.length() + 1) {
- byte[] endDelimiter = new byte[2];
- if (inputStream.read(endDelimiter) != 2) {
- throw new DecodeException("Boundary end is
incomplete");
- }
- if (endDelimiter[0] == '-' && endDelimiter[1] == '-') {
- return true;
- } else {
- inputStream.reset();
- inputStream.skip(toWrite.length + 2);
- }
- } else {
- inputStream.reset();
- inputStream.skip(toWrite.length + 2);
- }
- return false;
- }
- partData.write(buffer, 0, len);
- }
- }
-
- @Override
- public MediaType mediaType() {
- return MediaType.MULTIPART_FORM_DATA;
- }
-
- private static class Part {
-
- private final byte[] content;
-
- private final HttpHeaders headers;
-
- public Part(byte[] content, HttpHeaders headers) {
- this.content = content;
- this.headers = headers;
- }
- }
-}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/MultipartDecoderFactory.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/MultipartDecoderFactory.java
deleted file mode 100644
index 3cf2972548..0000000000
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/MultipartDecoderFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.remoting.http12.message.codec;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.remoting.http12.message.HttpMessageDecoder;
-import org.apache.dubbo.remoting.http12.message.HttpMessageDecoderFactory;
-import org.apache.dubbo.remoting.http12.message.MediaType;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-
-@Activate
-public final class MultipartDecoderFactory implements
HttpMessageDecoderFactory {
-
- private CodecUtils codecUtils;
-
- public void setCodecUtils(CodecUtils codecUtils) {
- this.codecUtils = codecUtils;
- }
-
- @Override
- public HttpMessageDecoder createCodec(URL url, FrameworkModel
frameworkModel, String mediaType) {
- return new MultipartDecoder(url, frameworkModel, mediaType,
codecUtils);
- }
-
- @Override
- public MediaType mediaType() {
- return MediaType.MULTIPART_FORM_DATA;
- }
-}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/PlainTextCodec.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/PlainTextCodec.java
index 48e41c657d..3ec4a99032 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/PlainTextCodec.java
+++
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/PlainTextCodec.java
@@ -17,13 +17,13 @@
package org.apache.dubbo.remoting.http12.message.codec;
import org.apache.dubbo.common.io.StreamUtils;
+import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.remoting.http12.exception.DecodeException;
import org.apache.dubbo.remoting.http12.exception.EncodeException;
import org.apache.dubbo.remoting.http12.exception.HttpStatusException;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
import org.apache.dubbo.remoting.http12.message.MediaType;
-import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
@@ -40,10 +40,12 @@ public final class PlainTextCodec implements
HttpMessageCodec {
os.write((data.toString()).getBytes(charset));
return;
}
- } catch (IOException e) {
- throw new EncodeException(e);
+ os.write(JsonUtils.toJson(data).getBytes(charset));
+ } catch (HttpStatusException e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new EncodeException("Error encoding plain text", t);
}
- throw new EncodeException("'text/plain' media-type only supports
String as return type.");
}
@Override
@@ -54,8 +56,8 @@ public final class PlainTextCodec implements HttpMessageCodec
{
}
} catch (HttpStatusException e) {
throw e;
- } catch (Exception e) {
- throw new DecodeException(e);
+ } catch (Throwable t) {
+ throw new EncodeException("Error decoding plain text", t);
}
throw new DecodeException("'text/plain' media-type only supports
String as method param.");
}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/UrlEncodeFormCodec.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/UrlEncodeFormCodec.java
deleted file mode 100644
index 643bc6211e..0000000000
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/UrlEncodeFormCodec.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.remoting.http12.message.codec;
-
-import org.apache.dubbo.common.convert.ConverterUtil;
-import org.apache.dubbo.common.io.StreamUtils;
-import org.apache.dubbo.remoting.http12.exception.DecodeException;
-import org.apache.dubbo.remoting.http12.exception.EncodeException;
-import org.apache.dubbo.remoting.http12.exception.HttpStatusException;
-import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
-import org.apache.dubbo.remoting.http12.message.MediaType;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-public class UrlEncodeFormCodec implements HttpMessageCodec {
-
- private final ConverterUtil converterUtil;
-
- public UrlEncodeFormCodec(ConverterUtil converterUtil) {
- this.converterUtil = converterUtil;
- }
-
- @Override
- public void encode(OutputStream outputStream, Object data, Charset
charset) throws EncodeException {
- try {
- if (data instanceof String) {
- outputStream.write(((String) data).getBytes());
- } else if (data instanceof Map) {
- StringBuilder toWrite = new StringBuilder();
- for (Map.Entry<?, ?> e : ((Map<?, ?>) data).entrySet()) {
- String k = e.getKey().toString();
- String v = e.getValue().toString();
- toWrite.append(k)
- .append("=")
- .append(URLEncoder.encode(v,
StandardCharsets.UTF_8.name()))
- .append("&");
- }
- if (toWrite.length() > 1) {
- outputStream.write(
- toWrite.substring(0, toWrite.length() -
1).getBytes(charset));
- }
- } else {
- throw new EncodeException("UrlEncodeFrom media-type only
supports String or Map as return type.");
- }
- } catch (HttpStatusException e) {
- throw e;
- } catch (Exception e) {
- throw new EncodeException(e);
- }
- }
-
- @Override
- public Object decode(InputStream inputStream, Class<?> targetType, Charset
charset) throws DecodeException {
- Object[] res = decode(inputStream, new Class[] {targetType}, charset);
- return res.length > 1 ? res : res[0];
- }
-
- @Override
- public Object[] decode(InputStream inputStream, Class<?>[] targetTypes,
Charset charset) throws DecodeException {
- try {
- boolean toMap;
- // key=value&key2=value2 -> method(map<keys,values>)
- if (targetTypes.length == 1 &&
targetTypes[0].isAssignableFrom(HashMap.class)) {
- toMap = true;
- }
- // key=value&key2=value2 -> method(value,value2)
- else if (Arrays.stream(targetTypes)
- .allMatch(clz -> String.class.isAssignableFrom(clz) ||
Number.class.isAssignableFrom(clz))) {
- toMap = false;
- } else {
- throw new DecodeException(
- "For x-www-form-urlencoded MIME type, please use
Map/String/base-types as method param.");
- }
- String decoded = URLDecoder.decode(
- StreamUtils.toString(inputStream, charset),
StandardCharsets.UTF_8.name())
- .trim();
- Map<String, Object> res = toMap(decoded, targetTypes, toMap);
- if (toMap) {
- return new Object[] {res};
- } else {
- return res.values().toArray();
- }
- } catch (HttpStatusException e) {
- throw e;
- } catch (Exception e) {
- throw new DecodeException(e);
- }
- }
-
- private Map<String, Object> toMap(String formString, Class<?>[]
targetTypes, boolean toMap) {
- Map<String, Object> res = new HashMap<>(1);
- // key1=val1&key2=&key3=&key4=val4
- String[] parts = formString.split("&");
- for (int i = 0; i < parts.length; i++) {
- String pair = parts[i];
- int index = pair.indexOf("=");
- if (index < 1) {
- throw new DecodeException("Broken request:" + formString);
- }
- String key = pair.substring(0, index);
- String val = (index == pair.length() - 1) ? "" :
pair.substring(index + 1);
- res.put(
- key,
- toMap || targetTypes[i].equals(String.class)
- // method params are Map or String, use plain text
as value
- ? val
- // try convert to target types
- : converterUtil.convertIfPossible(val,
targetTypes[i]));
- }
- return res;
- }
-
- @Override
- public MediaType mediaType() {
- return MediaType.APPLICATION_FROM_URLENCODED;
- }
-}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/UrlEncodeFormCodecFactory.java
b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/UrlEncodeFormCodecFactory.java
deleted file mode 100644
index fc54cb3603..0000000000
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/UrlEncodeFormCodecFactory.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.remoting.http12.message.codec;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.convert.ConverterUtil;
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
-import org.apache.dubbo.remoting.http12.message.HttpMessageDecoderFactory;
-import org.apache.dubbo.remoting.http12.message.HttpMessageEncoderFactory;
-import org.apache.dubbo.remoting.http12.message.MediaType;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-
-@Activate
-public final class UrlEncodeFormCodecFactory implements
HttpMessageEncoderFactory, HttpMessageDecoderFactory {
-
- private final UrlEncodeFormCodec instance;
-
- public UrlEncodeFormCodecFactory(FrameworkModel frameworkModel) {
- instance = new
UrlEncodeFormCodec(frameworkModel.getBeanFactory().getBean(ConverterUtil.class));
- }
-
- @Override
- public HttpMessageCodec createCodec(URL url, FrameworkModel
frameworkModel, String mediaType) {
- return instance;
- }
-
- @Override
- public MediaType mediaType() {
- return MediaType.APPLICATION_FROM_URLENCODED;
- }
-}
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageDecoderFactory
b/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageDecoderFactory
index 54d3c089cc..806a3cd182 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageDecoderFactory
+++
b/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageDecoderFactory
@@ -4,5 +4,3 @@
yaml=org.apache.dubbo.remoting.http12.message.codec.YamlCodecFactory
xml=org.apache.dubbo.remoting.http12.message.codec.XmlCodecFactory
html=org.apache.dubbo.remoting.http12.message.codec.HtmlCodecFactory
plaintext=org.apache.dubbo.remoting.http12.message.codec.PlainTextCodecFactory
-multipart=org.apache.dubbo.remoting.http12.message.codec.MultipartDecoderFactory
-urlencoded=org.apache.dubbo.remoting.http12.message.codec.UrlEncodeFormCodecFactory
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageEncoderFactory
b/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageEncoderFactory
index 656b8eff63..806a3cd182 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageEncoderFactory
+++
b/dubbo-remoting/dubbo-remoting-http12/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageEncoderFactory
@@ -4,4 +4,3 @@
yaml=org.apache.dubbo.remoting.http12.message.codec.YamlCodecFactory
xml=org.apache.dubbo.remoting.http12.message.codec.XmlCodecFactory
html=org.apache.dubbo.remoting.http12.message.codec.HtmlCodecFactory
plaintext=org.apache.dubbo.remoting.http12.message.codec.PlainTextCodecFactory
-urlencoded=org.apache.dubbo.remoting.http12.message.codec.UrlEncodeFormCodecFactory
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodeUtilsTest.java
b/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodeUtilsTest.java
index 7178746935..62a635aafa 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodeUtilsTest.java
+++
b/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodeUtilsTest.java
@@ -18,7 +18,6 @@ package org.apache.dubbo.remoting.http12.message.codec;
import org.apache.dubbo.remoting.http12.HttpHeaderNames;
import org.apache.dubbo.remoting.http12.HttpHeaders;
-import
org.apache.dubbo.remoting.http12.exception.UnsupportedMediaTypeException;
import org.apache.dubbo.remoting.http12.message.HttpMessageDecoder;
import org.apache.dubbo.remoting.http12.message.HttpMessageEncoder;
import org.apache.dubbo.remoting.http12.message.MediaType;
@@ -50,20 +49,6 @@ public class CodeUtilsTest {
Assertions.assertNotNull(encoder);
Assertions.assertEquals(JsonPbCodec.class, encoder.getClass());
- HttpHeaders headers1 = new HttpHeaders();
- headers1.put(
- HttpHeaderNames.CONTENT_TYPE.getName(),
-
Collections.singletonList(MediaType.MULTIPART_FORM_DATA.getName()));
- decoder =
- codecUtils.determineHttpMessageDecoder(null,
FrameworkModel.defaultModel(), headers1.getContentType());
- Assertions.assertNotNull(decoder);
- Assertions.assertEquals(MultipartDecoder.class, decoder.getClass());
- Assertions.assertThrows(
- UnsupportedMediaTypeException.class,
- () -> codecUtils.determineHttpMessageEncoder(
- null, FrameworkModel.defaultModel(),
headers1.getContentType()));
-
- headers1.put(HttpHeaderNames.ACCEPT.getName(),
Collections.singletonList(MediaType.APPLICATION_JSON.getName()));
encoder = codecUtils.determineHttpMessageEncoder(
null, FrameworkModel.defaultModel(),
MediaType.APPLICATION_JSON.getName());
Assertions.assertNotNull(encoder);
diff --git
a/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodecTest.java
b/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodecTest.java
index 2902052e52..9d6d573eef 100644
---
a/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodecTest.java
+++
b/dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/codec/CodecTest.java
@@ -17,17 +17,11 @@
package org.apache.dubbo.remoting.http12.message.codec;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
-import org.apache.dubbo.remoting.http12.message.HttpMessageDecoder;
import org.apache.dubbo.rpc.model.FrameworkModel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Random;
import com.google.common.base.Charsets;
import org.junit.jupiter.api.Assertions;
@@ -36,56 +30,6 @@ import org.junit.jupiter.api.Test;
public class CodecTest {
- final String MULTIPART_SAMPLE_1 = "--example-part-boundary\r\n"
- + "Content-Disposition: form-data; name=\"username\"\r\n"
- + "Content-Type: text/plain\r\n"
- + "\r\n"
- + "LuYue\r\n"
- + "--example-part-boundary\r\n"
- + "Content-Disposition: form-data; name=\"userdetail\"\r\n"
- + "Content-Type: application/json\r\n"
- + "\r\n"
- + "{\"location\":\"beijing\",\"username\":\"LuYue\"}\r\n"
- + "--example-part-boundary\r\n"
- + "Content-Disposition: form-data; name=\"userimg\";
filename=\"user.jpeg\"\r\n"
- + "Content-Type: image/jpeg\r\n"
- + "\r\n"
- + "<binary-image data>\r\n"
- + "--example-part-boundary--\r\n";
-
- final String MULTIPART_SAMPLE_2 = "--boundary123\r\n" +
"Content-Disposition: form-data; name=\"text\"\r\n"
- + "Content-Type: text/plain\r\n"
- + "\r\n"
- + "simple text\r\n"
- + "--boundary123\r\n"
- + "Content-Disposition: form-data; name=\"file\";
filename=\"example.txt\"\r\n"
- + "Content-Type: text/plain\r\n"
- + "\r\n"
- + "This is the content of the file.\r\n"
- + "--boundary123--\r\n";
-
- final String MULTIPART_SAMPLE_3 = "--boundaryABC\r\n" +
"Content-Disposition: form-data; name=\"someContent\"\r\n"
- + "\r\n"
- + "这是一些中文内容\r\n"
- + "--boundaryABC\r\n"
- + "Content-Disposition: form-data; name=\"emoji\"\r\n"
- + "\r\n"
- + "\uD83D\uDE0A\r\n"
- + "--boundaryABC--";
-
- final String MULTIPART_SAMPLE_4 = "--longValue\r\n" +
"Content-Disposition: form-data; name=\"long\"\r\n"
- + "\r\n"
- + "This is a really long value that continues for many lines.This
is a really long value that continues for many lines.This is a really long
value that continues for many lines.This is a really long value that continues
for many lines.This is a really long value that continues for many lines.This
is a really long value that continues for many lines.This is a really long
value that continues for many lines.This is a really long value that continues
for many lines.This is a rea [...]
- + "--longValue--\r\n";
-
- final String MULTIPART_SAMPLE_5 = "--specialChar\r\n" +
"Content-Disposition: form-data; name=\"special\"\r\n"
- + "\r\n"
- + "Line 1\n"
- + "Line 2\r\n"
- + "--Line 3--\n"
- + "Line 4\n\r\n"
- + "--specialChar--";
-
CodecUtils codecUtils;
@BeforeEach
@@ -93,254 +37,6 @@ public class CodecTest {
codecUtils =
FrameworkModel.defaultModel().getBeanFactory().getOrRegisterBean(CodecUtils.class);
}
- @Test
- void testMultipartForm1() {
- InputStream in = new
ByteArrayInputStream(MULTIPART_SAMPLE_1.getBytes());
- HttpMessageDecoder decoder = new MultipartDecoder(
- null, FrameworkModel.defaultModel(), "multipart/form-data;
boundary=example-part-boundary", codecUtils);
- Object[] result = decoder.decode(in, new Class[] {String.class,
User.class, byte[].class});
- Assertions.assertEquals("LuYue", result[0]);
- Assertions.assertTrue(result[1] instanceof User);
- Assertions.assertEquals("LuYue", ((User) result[1]).getUsername());
- Assertions.assertEquals("beijing", ((User) result[1]).getLocation());
- Assertions.assertEquals("<binary-image data>", new String((byte[])
result[2], Charsets.UTF_8));
- }
-
- @Test
- void testMultipartForm2() {
- InputStream in = new
ByteArrayInputStream(MULTIPART_SAMPLE_2.getBytes());
- HttpMessageDecoder decoder = new MultipartDecoder(
- null, FrameworkModel.defaultModel(), "multipart/form-data;
boundary=boundary123", codecUtils);
- Object[] result = decoder.decode(in, new Class[] {String.class,
byte[].class});
- Assertions.assertEquals("simple text", result[0]);
- Assertions.assertEquals(
- "This is the content of the file.", new String((byte[])
result[1], StandardCharsets.US_ASCII));
- }
-
- @Test
- void testMultipartForm3() {
- InputStream in = new
ByteArrayInputStream(MULTIPART_SAMPLE_3.getBytes());
- HttpMessageDecoder decoder = new MultipartDecoder(
- null, FrameworkModel.defaultModel(), "multipart/form-data;
boundary=boundaryABC", codecUtils);
- Object[] result = decoder.decode(in, new Class[] {String.class,
String.class});
- Assertions.assertEquals("这是一些中文内容", result[0]);
- Assertions.assertEquals("😊", result[1]);
- }
-
- @Test
- void testMultipartForm4() {
- InputStream in = new
ByteArrayInputStream(MULTIPART_SAMPLE_4.getBytes());
- HttpMessageDecoder decoder = new MultipartDecoder(
- null, FrameworkModel.defaultModel(), "multipart/form-data;
boundary=longValue", codecUtils);
- Object[] result = decoder.decode(in, new Class[] {String.class});
- Assertions.assertEquals(
- "This is a really long value that continues for many
lines.This is a really long value that continues for many lines.This is a
really long value that continues for many lines.This is a really long value
that continues for many lines.This is a really long value that continues for
many lines.This is a really long value that continues for many lines.This is a
really long value that continues for many lines.This is a really long value
that continues for many lines.This is a r [...]
- result[0]);
- }
-
- @Test
- void testMultipartForm5() {
- InputStream in = new
ByteArrayInputStream(MULTIPART_SAMPLE_5.getBytes());
- HttpMessageDecoder decoder = new MultipartDecoder(
- null, FrameworkModel.defaultModel(), "multipart/form-data;
boundary=specialChar", codecUtils);
- Object[] result = decoder.decode(in, new Class[] {String.class});
- Assertions.assertEquals("Line 1\n" + "Line 2\r\n" + "--Line 3--\n" +
"Line 4\n", result[0]);
- }
-
- @Test
- void testMultipartFormBodyBoundary() {
- // check if codec can handle boundary correctly when the end delimiter
just beyond the buffer.
- // header buffer size: 128; body buffer size: 256
- // --example-boundary\r\n [20bytes]
- // Content-Type: plain/text [paddings]\r\n\r\n [108bytes]
- // body1r\n [238bytes, binary data]
- // --example-boundary--\r\n [22bytes] , last --\r\n [4bytes] beyond
buffer
- byte[] boundary = "--example-boundary\r\n".getBytes();
- byte[] header = "Content-Type: plain/text".getBytes();
- byte[] headerPadding = new byte[128 - header.length - boundary.length
- "\r\n\r\n".length()];
- byte[] headerBytes = new byte[128];
- byte[] body1 = new byte[238];
- byte[] end = "--example-boundary--\r\n".getBytes();
- byte[] bodyWithEnd = new byte[260];
-
- Random random = new Random();
- random.nextBytes(body1);
- body1[236] = '\r';
- body1[237] = '\n';
- Arrays.fill(headerPadding, (byte) 0);
-
- System.arraycopy(boundary, 0, headerBytes, 0, boundary.length);
- System.arraycopy(header, 0, headerBytes, boundary.length,
header.length);
-
- System.arraycopy(headerPadding, 0, headerBytes, boundary.length +
header.length, headerPadding.length);
- System.arraycopy(
- "\r\n\r\n".getBytes(),
- 0,
- headerBytes,
- boundary.length + header.length + headerPadding.length,
- "\r\n\r\n".length());
- System.arraycopy(body1, 0, bodyWithEnd, 0, body1.length);
- System.arraycopy(end, 0, bodyWithEnd, body1.length, end.length);
-
- byte[] fullRequestBody = new byte[256 + 128 + 4];
- System.arraycopy(headerBytes, 0, fullRequestBody, 0,
headerBytes.length);
- System.arraycopy(bodyWithEnd, 0, fullRequestBody, headerBytes.length,
bodyWithEnd.length);
-
- HttpMessageDecoder decoder = new MultipartDecoderFactory()
- .createCodec(null, FrameworkModel.defaultModel(),
"multipart/form-data; boundary=example-boundary");
- byte[] res = (byte[]) decoder.decode(new
ByteArrayInputStream(fullRequestBody), byte[].class);
-
- for (int k = 0; k < body1.length - 2; k++) {
- Assertions.assertEquals(body1[k], res[k]);
- }
- }
-
- @Test
- void testMultipartFormBodyBoundary2() {
- // check if codec can handle boundary correctly when the end delimiter
just beyond the buffer.
- // header buffer size: 128; body buffer size: 256
- // --example-boundary-\r\n [21bytes]
- // Content-Type: plain/text [paddings]\r\n\r\n [107bytes]
- // body1r\n [237bytes, binary data]
- // --example-boundary-\r\n [21bytes] , \r\n [2bytes] beyond buffer
- // body2\r\n [7bytes, text data]
- // --example-boundary--- [23bytes]
- byte[] boundary = "--example-boundary-\r\n".getBytes();
- byte[] subHeader = "Content-Type: plain/text".getBytes();
- byte[] subHeaderWithCRLF = "Content-Type:
plain/text\r\n\r\n".getBytes();
- byte[] headerPadding = new byte[128 - subHeader.length -
boundary.length - "\r\n\r\n".length()];
- byte[] headerBytes = new byte[128];
- byte[] body1 = new byte[237];
- byte[] body1WithEnd = new byte[body1.length + boundary.length];
- byte[] body2 = "body2\r\n".getBytes();
- byte[] end = "--example-boundary---\r\n".getBytes();
-
- Random random = new Random();
- random.nextBytes(body1);
- body1[body1.length - 1] = '\n';
- body1[body1.length - 2] = '\r';
- Arrays.fill(headerPadding, (byte) 0);
-
- System.arraycopy(boundary, 0, headerBytes, 0, boundary.length);
- System.arraycopy(subHeader, 0, headerBytes, boundary.length,
subHeader.length);
- System.arraycopy(headerPadding, 0, headerBytes, boundary.length +
subHeader.length, headerPadding.length);
- System.arraycopy(
- "\r\n\r\n".getBytes(),
- 0,
- headerBytes,
- boundary.length + subHeader.length + headerPadding.length,
- "\r\n\r\n".length());
- System.arraycopy(body1, 0, body1WithEnd, 0, body1.length);
- System.arraycopy(boundary, 0, body1WithEnd, body1.length,
boundary.length);
-
- byte[] fullRequestBody = new byte
- [headerBytes.length + body1WithEnd.length +
subHeaderWithCRLF.length + body2.length + end.length];
- System.arraycopy(headerBytes, 0, fullRequestBody, 0,
headerBytes.length);
- System.arraycopy(body1WithEnd, 0, fullRequestBody, headerBytes.length,
body1WithEnd.length);
- System.arraycopy(
- subHeaderWithCRLF,
- 0,
- fullRequestBody,
- headerBytes.length + body1WithEnd.length,
- subHeaderWithCRLF.length);
- System.arraycopy(
- body2,
- 0,
- fullRequestBody,
- headerBytes.length + body1WithEnd.length +
subHeaderWithCRLF.length,
- body2.length);
- System.arraycopy(
- end,
- 0,
- fullRequestBody,
- headerBytes.length + body1WithEnd.length +
subHeaderWithCRLF.length + body2.length,
- end.length);
-
- HttpMessageDecoder decoder = new MultipartDecoder(
- null, FrameworkModel.defaultModel(), "multipart/form-data;
boundary=example-boundary-", codecUtils);
- Object[] r =
- decoder.decode(new ByteArrayInputStream(fullRequestBody), new
Class[] {byte[].class, String.class});
- byte[] res = (byte[]) r[0];
- for (int k = 0; k < body1.length - 2; k++) {
- Assertions.assertEquals(body1[k], res[k]);
- }
- String res2 = (String) r[1];
- Assertions.assertEquals("body2", res2);
- }
-
- @Test
- void testUrlForm() {
- String content = "Hello=World&Apache=Dubbo&id=10086";
- InputStream in = new ByteArrayInputStream(content.getBytes());
- UrlEncodeFormCodecFactory factory = new
UrlEncodeFormCodecFactory(FrameworkModel.defaultModel());
- HttpMessageCodec codec = factory.createCodec(null,
FrameworkModel.defaultModel(), null);
- Object res = codec.decode(in, Map.class);
- Assertions.assertTrue(res instanceof Map);
- Map<String, String> r = (Map<String, String>) res;
- Assertions.assertEquals("World", r.get("Hello"));
- Assertions.assertEquals("Dubbo", r.get("Apache"));
- Assertions.assertEquals("10086", r.get("id"));
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- codec.encode(outputStream, r);
- Assertions.assertEquals(content, outputStream.toString());
- try {
- in.reset();
- } catch (IOException e) {
- }
- Object[] res2 = codec.decode(in, new Class[] {String.class,
String.class, Long.class});
- Assertions.assertEquals("World", res2[0]);
- Assertions.assertEquals("Dubbo", res2[1]);
- Assertions.assertEquals(10086L, res2[2]);
- outputStream = new ByteArrayOutputStream();
- codec.encode(outputStream, content);
- Assertions.assertEquals(content, outputStream.toString());
- }
-
- @Test
- void testUrlForm2() {
- InputStream in = new
ByteArrayInputStream("Hello=World&Apache=Dubbo&empty1=&empty2=".getBytes());
- HttpMessageCodec codec = new
UrlEncodeFormCodecFactory(FrameworkModel.defaultModel())
- .createCodec(null, FrameworkModel.defaultModel(), null);
- Object res = codec.decode(in, Map.class);
- Assertions.assertTrue(res instanceof Map);
- Map<String, String> r = (Map<String, String>) res;
- Assertions.assertEquals("World", r.get("Hello"));
- Assertions.assertEquals("Dubbo", r.get("Apache"));
- Assertions.assertEquals("", r.get("empty1"));
- Assertions.assertEquals("", r.get("empty2"));
- }
-
- @Test
- void testUrlForm3() {
- InputStream in = new
ByteArrayInputStream("empty1=&empty2=&Hello=world&empty3=&Apache=dubbo&".getBytes());
- HttpMessageCodec codec = new
UrlEncodeFormCodecFactory(FrameworkModel.defaultModel())
- .createCodec(null, FrameworkModel.defaultModel(), null);
- Object res = codec.decode(in, Map.class);
- Assertions.assertTrue(res instanceof Map);
- Map<String, String> r = (Map<String, String>) res;
- Assertions.assertEquals("world", r.get("Hello"));
- Assertions.assertEquals("dubbo", r.get("Apache"));
- Assertions.assertEquals("", r.get("empty1"));
- Assertions.assertEquals("", r.get("empty2"));
- Assertions.assertEquals("", r.get("empty3"));
- }
-
- @Test
- void testUrlForm4() {
- InputStream in = new
ByteArrayInputStream("empty1=&empty2=&Hello=world&你好=世界&empty3=&Apache=dubbo&".getBytes());
- HttpMessageCodec codec = new
UrlEncodeFormCodecFactory(FrameworkModel.defaultModel())
- .createCodec(null, FrameworkModel.defaultModel(), null);
- Object res = codec.decode(in, Map.class);
- Assertions.assertTrue(res instanceof Map);
- Map<String, String> r = (Map<String, String>) res;
- Assertions.assertEquals("world", r.get("Hello"));
- Assertions.assertEquals("dubbo", r.get("Apache"));
- Assertions.assertEquals("", r.get("empty1"));
- Assertions.assertEquals("", r.get("empty2"));
- Assertions.assertEquals("", r.get("empty3"));
- Assertions.assertEquals("世界", r.get("你好"));
- }
-
@Test
void testXml() {
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"yes\"?>"
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/CancelableStreamObserver.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/CancelableStreamObserver.java
index 57ceae43fa..6b1548b6e8 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/CancelableStreamObserver.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/CancelableStreamObserver.java
@@ -36,7 +36,7 @@ public abstract class CancelableStreamObserver<T> implements
StreamObserver<T> {
cancellationContext.cancel(throwable);
}
- public void beforeStart(final ClientCallToObserverAdapter<T>
clientCallToObserverAdapter) {
+ public void beforeStart(ClientCallToObserverAdapter<T>
clientCallToObserverAdapter) {
// do nothing
}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/DescriptorUtils.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/DescriptorUtils.java
index c80eb21b66..91c09aa009 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/DescriptorUtils.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/DescriptorUtils.java
@@ -25,7 +25,7 @@ import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
-import
org.apache.dubbo.rpc.protocol.tri.TripleCustomerProtocolWapper.TripleRequestWrapper;
+import
org.apache.dubbo.rpc.protocol.tri.TripleCustomerProtocolWrapper.TripleRequestWrapper;
import org.apache.dubbo.rpc.service.ServiceDescriptorInternalCache;
import org.apache.dubbo.rpc.stub.StubSuppliers;
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
index 6ec87135a1..b9f80116f7 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
@@ -328,7 +328,7 @@ public class ReflectionPackableMethod implements
PackableMethod {
public byte[] pack(Object obj) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
multipleSerialization.serialize(url, requestSerialize,
actualResponseType, obj, bos);
- return
TripleCustomerProtocolWapper.TripleResponseWrapper.Builder.newBuilder()
+ return
TripleCustomerProtocolWrapper.TripleResponseWrapper.Builder.newBuilder()
.setSerializeType(requestSerialize)
.setType(actualResponseType.getName())
.setData(bos.toByteArray())
@@ -359,8 +359,8 @@ public class ReflectionPackableMethod implements
PackableMethod {
}
public Object unpack(byte[] data, boolean isReturnTriException) throws
IOException, ClassNotFoundException {
- TripleCustomerProtocolWapper.TripleResponseWrapper wrapper =
-
TripleCustomerProtocolWapper.TripleResponseWrapper.parseFrom(data);
+ TripleCustomerProtocolWrapper.TripleResponseWrapper wrapper =
+
TripleCustomerProtocolWrapper.TripleResponseWrapper.parseFrom(data);
final String serializeType =
convertHessianFromWrapper(wrapper.getSerializeType());
CodecSupport.checkSerialization(serializeType, allSerialize);
@@ -405,8 +405,8 @@ public class ReflectionPackableMethod implements
PackableMethod {
} else {
arguments = (Object[]) obj;
}
- final TripleCustomerProtocolWapper.TripleRequestWrapper.Builder
builder =
-
TripleCustomerProtocolWapper.TripleRequestWrapper.Builder.newBuilder();
+ TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder builder
=
+
TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder.newBuilder();
builder.setSerializeType(serialize);
for (String type : argumentsType) {
builder.addArgTypes(type);
@@ -457,8 +457,8 @@ public class ReflectionPackableMethod implements
PackableMethod {
}
public Object unpack(byte[] data, boolean isReturnTriException) throws
IOException, ClassNotFoundException {
- TripleCustomerProtocolWapper.TripleRequestWrapper wrapper =
-
TripleCustomerProtocolWapper.TripleRequestWrapper.parseFrom(data);
+ TripleCustomerProtocolWrapper.TripleRequestWrapper wrapper =
+
TripleCustomerProtocolWrapper.TripleRequestWrapper.parseFrom(data);
String wrapperSerializeType =
convertHessianFromWrapper(wrapper.getSerializeType());
CodecSupport.checkSerialization(wrapperSerializeType,
allSerialize);
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStreamObserver.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStreamObserver.java
index f06ecd8408..6dad6aaec4 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStreamObserver.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStreamObserver.java
@@ -18,9 +18,4 @@ package org.apache.dubbo.rpc.protocol.tri;
import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
-public interface ServerStreamObserver<T> extends CallStreamObserver<T> {
-
- default void disableAutoInboundFlowControl() {
- disableAutoFlowControl();
- }
-}
+public interface ServerStreamObserver<T> extends CallStreamObserver<T> {}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWrapper.java
similarity index 99%
rename from
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java
rename to
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWrapper.java
index ace359c3de..c4d833ed6d 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapper.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWrapper.java
@@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-public class TripleCustomerProtocolWapper {
+public class TripleCustomerProtocolWrapper {
static int makeTag(int fieldNumber, int wireType) {
return fieldNumber << 3 | wireType;
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java
index 1bd9545b46..f6743b747e 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleHeaderEnum.java
@@ -127,16 +127,7 @@ public enum TripleHeaderEnum {
"te",
"trailer",
"upgrade",
- "upgrade-insecure-requests",
- "user-agent",
- "x-csrf-token",
- "x-forwarded-for",
- "x-forwarded-host",
- "x-forwarded-proto",
- "x-http-method-override",
- "x-real-ip",
- "x-request-id",
- "x-requested-with"
+ "upgrade-insecure-requests"
};
}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java
index c1810228af..9631b48c56 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java
@@ -99,6 +99,7 @@ public class TripleInvoker<T> extends AbstractInvoker<T> {
CommonConstants.ThirdPartyProperty.SET_FUTURE_IN_SYNC_MODE,
"true"));
private final PackableMethodFactory packableMethodFactory;
private final Map<MethodDescriptor, PackableMethod> packableMethodCache =
new ConcurrentHashMap<>();
+ private static Compressor compressor;
public TripleInvoker(
Class<T> serviceType,
@@ -124,10 +125,15 @@ public class TripleInvoker<T> extends AbstractInvoker<T> {
}
private static Compressor getCompressorFromEnv() {
- Configuration configuration =
ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel());
- String compressorKey = configuration.getString(COMPRESSOR_KEY,
Identity.MESSAGE_ENCODING);
- return Compressor.getCompressor(
-
ScopeModelUtil.getFrameworkModel(ApplicationModel.defaultModel()),
compressorKey);
+ Compressor compressor = TripleInvoker.compressor;
+ if (compressor == null) {
+ ApplicationModel model = ApplicationModel.defaultModel();
+ Configuration configuration =
ConfigurationUtils.getEnvConfiguration(model);
+ String compressorKey = configuration.getString(COMPRESSOR_KEY,
Identity.MESSAGE_ENCODING);
+ compressor =
Compressor.getCompressor(ScopeModelUtil.getFrameworkModel(model),
compressorKey);
+ TripleInvoker.compressor = compressor;
+ }
+ return compressor;
}
@Override
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleScopeModelInitializer.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleScopeModelInitializer.java
deleted file mode 100644
index 1811821438..0000000000
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleScopeModelInitializer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.rpc.protocol.tri;
-
-import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
-import org.apache.dubbo.rpc.model.ApplicationModel;
-import org.apache.dubbo.rpc.model.FrameworkModel;
-import org.apache.dubbo.rpc.model.ModuleModel;
-import org.apache.dubbo.rpc.model.ScopeModelInitializer;
-import
org.apache.dubbo.rpc.protocol.tri.rest.mapping.DefaultRequestMappingRegistry;
-import org.apache.dubbo.rpc.protocol.tri.route.DefaultRequestRouter;
-
-public class TripleScopeModelInitializer implements ScopeModelInitializer {
-
- @Override
- public void initializeFrameworkModel(FrameworkModel frameworkModel) {
- ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory();
- beanFactory.registerBean(DefaultRequestMappingRegistry.class);
- beanFactory.registerBean(DefaultRequestRouter.class);
- }
-
- @Override
- public void initializeApplicationModel(ApplicationModel applicationModel)
{}
-
- @Override
- public void initializeModuleModel(ModuleModel moduleModel) {}
-}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/aot/TripleReflectionTypeDescriberRegistrar.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/aot/TripleReflectionTypeDescriberRegistrar.java
index a0ab8198d4..e561c90f7b 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/aot/TripleReflectionTypeDescriberRegistrar.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/aot/TripleReflectionTypeDescriberRegistrar.java
@@ -19,6 +19,15 @@ package org.apache.dubbo.rpc.protocol.tri.aot;
import org.apache.dubbo.aot.api.MemberCategory;
import org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar;
import org.apache.dubbo.aot.api.TypeDescriber;
+import org.apache.dubbo.remoting.http12.ErrorResponse;
+import org.apache.dubbo.remoting.http12.message.codec.CodecUtils;
+import org.apache.dubbo.rpc.protocol.tri.h12.http2.CompositeExceptionHandler;
+import
org.apache.dubbo.rpc.protocol.tri.rest.argument.CompositeArgumentConverter;
+import
org.apache.dubbo.rpc.protocol.tri.rest.argument.CompositeArgumentResolver;
+import org.apache.dubbo.rpc.protocol.tri.rest.argument.GeneralTypeConverter;
+import org.apache.dubbo.rpc.protocol.tri.rest.mapping.ContentNegotiator;
+import
org.apache.dubbo.rpc.protocol.tri.rest.mapping.DefaultRequestMappingRegistry;
+import org.apache.dubbo.rpc.protocol.tri.route.DefaultRequestRouter;
import
org.apache.dubbo.rpc.protocol.tri.transport.TripleCommandOutBoundHandler;
import org.apache.dubbo.rpc.protocol.tri.transport.TripleGoAwayHandler;
import
org.apache.dubbo.rpc.protocol.tri.transport.TripleHttp2ClientResponseHandler;
@@ -39,6 +48,15 @@ public class TripleReflectionTypeDescriberRegistrar
implements ReflectionTypeDes
typeDescribers.add(buildTypeDescriberWithPublicMethod(TripleServerConnectionHandler.class));
typeDescribers.add(buildTypeDescriberWithPublicMethod(TripleGoAwayHandler.class));
typeDescribers.add(buildTypeDescriberWithPublicMethod(TripleHttp2ClientResponseHandler.class));
+
typeDescribers.add(buildTypeDescriberWithPublicMethod(ErrorResponse.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(DefaultRequestMappingRegistry.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(DefaultRequestRouter.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(ContentNegotiator.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(CompositeArgumentResolver.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(CompositeArgumentConverter.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(CompositeExceptionHandler.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(GeneralTypeConverter.class));
+
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(CodecUtils.class));
return typeDescribers;
}
@@ -48,4 +66,11 @@ public class TripleReflectionTypeDescriberRegistrar
implements ReflectionTypeDes
return new TypeDescriber(
c.getName(), null, new HashSet<>(), new HashSet<>(), new
HashSet<>(), memberCategories);
}
+
+ private TypeDescriber buildTypeDescriberWithDeclaredConstructors(Class<?>
cl) {
+ Set<MemberCategory> memberCategories = new HashSet<>();
+ memberCategories.add(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
+ return new TypeDescriber(
+ cl.getName(), null, new HashSet<>(), new HashSet<>(), new
HashSet<>(), memberCategories);
+ }
}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java
index 24b80585a8..6eadf35ba5 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java
@@ -81,7 +81,7 @@ public class TripleClientCall implements ClientCall,
ClientStream.Listener {
return;
}
try {
- final Object unpacked =
requestMetadata.packableMethod.parseResponse(message, isReturnTriException);
+ Object unpacked =
requestMetadata.packableMethod.parseResponse(message, isReturnTriException);
listener.onMessage(unpacked, message.length);
} catch (Throwable t) {
TriRpcStatus status = TriRpcStatus.INTERNAL
@@ -95,7 +95,7 @@ public class TripleClientCall implements ClientCall,
ClientStream.Listener {
"",
String.format(
"Failed to deserialize triple response,
service=%s, method=%s,connection=%s",
- connectionClient, requestMetadata.service,
requestMetadata.method.getMethodName()),
+ requestMetadata.service, requestMetadata.service,
requestMetadata.method.getMethodName()),
t);
}
}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/Messages.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/Messages.java
index 073aeb403d..6b60aedcc0 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/Messages.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/Messages.java
@@ -46,30 +46,30 @@ public enum Messages {
INTERNAL_ERROR("Rest Internal Error");
private final String message;
- private final String localizedMessage;
+ private final String displayMessage;
private final int statusCode;
Messages(String message) {
this.message = message;
- localizedMessage = null;
+ displayMessage = null;
statusCode = 500;
}
- Messages(String message, String localizedMessage) {
+ Messages(String message, String displayMessage) {
this.message = message;
- this.localizedMessage = localizedMessage;
+ this.displayMessage = displayMessage;
statusCode = 500;
}
Messages(String message, int statusCode) {
this.message = message;
- localizedMessage = null;
+ displayMessage = null;
this.statusCode = statusCode;
}
- Messages(String message, String localizedMessage, int statusCode) {
+ Messages(String message, String displayMessage, int statusCode) {
this.message = message;
- this.localizedMessage = localizedMessage;
+ this.displayMessage = displayMessage;
this.statusCode = statusCode;
}
@@ -81,9 +81,9 @@ public enum Messages {
return ArrayUtils.isEmpty(args) ? message :
MessageFormat.format(message, args);
}
- public String formatLocalized(Object... args) {
- return localizedMessage == null || ArrayUtils.isEmpty(args)
- ? localizedMessage
- : MessageFormat.format(localizedMessage, args);
+ public String formatDisplay(Object... args) {
+ return displayMessage == null || ArrayUtils.isEmpty(args)
+ ? displayMessage
+ : MessageFormat.format(displayMessage, args);
}
}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestException.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestException.java
index 91073a3a47..a94e58b581 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestException.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestException.java
@@ -47,13 +47,13 @@ public class RestException extends HttpStatusException {
public RestException(Messages message, Object... arguments) {
super(message.statusCode(), message.format(arguments));
this.message = message;
- displayMessage = message.formatLocalized(arguments);
+ displayMessage = message.formatDisplay(arguments);
}
public RestException(Throwable cause, Messages message, Object...
arguments) {
super(message.statusCode(), message.format(arguments),
ExceptionUtils.unwrap(cause));
this.message = message;
- displayMessage = message.formatLocalized(arguments);
+ displayMessage = message.formatDisplay(arguments);
}
public String getErrorCode() {
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/NamedValueArgumentResolverSupport.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/NamedValueArgumentResolverSupport.java
index 80deb647b1..f69402fd9e 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/NamedValueArgumentResolverSupport.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/NamedValueArgumentResolverSupport.java
@@ -17,7 +17,6 @@
package org.apache.dubbo.rpc.protocol.tri.rest.argument;
import org.apache.dubbo.common.utils.CollectionUtils;
-import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.http12.HttpRequest;
import org.apache.dubbo.remoting.http12.HttpResponse;
import org.apache.dubbo.rpc.protocol.tri.rest.Messages;
@@ -58,8 +57,8 @@ public abstract class NamedValueArgumentResolverSupport {
}
protected final NamedValueMeta updateNamedValueMeta(ParameterMeta
parameterMeta, NamedValueMeta meta) {
- if (StringUtils.isEmpty(meta.name())) {
- meta.setName(parameterMeta.getRequiredName());
+ if (meta.isNameEmpty()) {
+ meta.setName(parameterMeta.getName());
}
Class<?> type = parameterMeta.getActualType();
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java
index 4efc692012..159b1e7179 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.common.config.Configuration;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
+import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.config.nested.RestConfig;
import org.apache.dubbo.remoting.http12.HttpRequest;
import org.apache.dubbo.remoting.http12.message.MethodMetadata;
@@ -49,6 +50,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -103,15 +105,18 @@ public final class DefaultRequestMappingRegistry
implements RequestMappingRegist
if (sd == null) {
return;
}
+ AtomicInteger counter = new AtomicInteger();
+ long start = System.currentTimeMillis();
new MethodWalker().walk(service.getClass(), (classes, consumer) -> {
for (int i = 0, size = resolvers.size(); i < size; i++) {
RequestMappingResolver resolver = resolvers.get(i);
ServiceMeta serviceMeta = new ServiceMeta(classes, sd,
service, url, resolver.getRestToolKit());
if (LOGGER.isInfoEnabled()) {
LOGGER.info(
- "{} resolve rest mappings from {}",
+ "{} resolving rest mappings for {} at url [{}]",
resolver.getClass().getSimpleName(),
- serviceMeta);
+ serviceMeta,
+ url.toString(""));
}
if (!resolver.accept(serviceMeta)) {
continue;
@@ -141,13 +146,19 @@ public final class DefaultRequestMappingRegistry
implements RequestMappingRegist
}
methodMeta.initParameters();
MethodMetadata methodMetadata =
MethodMetadata.fromMethodDescriptor(md);
- register0(methodMapping, new HandlerMeta(invoker,
methodMeta, methodMetadata, md, sd));
+ register0(methodMapping, new HandlerMeta(invoker,
methodMeta, methodMetadata, md, sd), counter);
});
}
});
+ LOGGER.info(
+ "Registered {} REST mappings for service [{}] at url [{}] in
{}ms",
+ counter,
+ ClassUtils.toShortString(service),
+ url.toString(""),
+ System.currentTimeMillis() - start);
}
- private void register0(RequestMapping mapping, HandlerMeta handler) {
+ private void register0(RequestMapping mapping, HandlerMeta handler,
AtomicInteger counter) {
lock.writeLock().lock();
try {
Registration registration = new Registration();
@@ -157,9 +168,10 @@ public final class DefaultRequestMappingRegistry
implements RequestMappingRegist
Registration exists = tree.addPath(path, registration);
if (exists == null) {
if (LOGGER.isDebugEnabled()) {
- String msg = "Register rest mapping path: '{}' ->
mapping={}, method={}";
+ String msg = "Register rest mapping: '{}' ->
mapping={}, method={}";
LOGGER.debug(msg, path, mapping, handler.getMethod());
}
+ counter.incrementAndGet();
} else if (LOGGER.isWarnEnabled()) {
String msg = Messages.DUPLICATE_MAPPING.format(path,
mapping, handler.getMethod(), exists);
LOGGER.warn(LoggerCodeConstants.INTERNAL_ERROR, "", "",
msg);
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/AnnotationSupport.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/AnnotationSupport.java
index c93a164ed8..776b8ec93d 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/AnnotationSupport.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/AnnotationSupport.java
@@ -129,7 +129,7 @@ public abstract class AnnotationSupport {
return arrayCache.computeIfAbsent(FIND_KEY, k -> {
List<? extends AnnotatedElement> elements = getAnnotatedElements();
List<AnnotationMeta> metas = new ArrayList<>();
- for (int i = 0, len = elements.size(); i < len; i++) {
+ for (int i = 0, size = elements.size(); i < size; i++) {
AnnotatedElement element = elements.get(i);
Annotation[] annotations = element.getAnnotations();
for (Annotation annotation : annotations) {
@@ -146,7 +146,7 @@ public abstract class AnnotationSupport {
public final <A extends Annotation> AnnotationMeta<A>
findAnnotation(Class<A> annotationType) {
return cache.computeIfAbsent(Pair.of(annotationType, FIND_KEY), k -> {
List<? extends AnnotatedElement> elements =
getAnnotatedElements();
- for (int i = 0, len = elements.size(); i < len; i++) {
+ for (int i = 0, size = elements.size(); i < size; i++) {
AnnotatedElement element = elements.get(i);
Annotation annotation =
element.getDeclaredAnnotation(annotationType);
if (annotation != null) {
@@ -173,7 +173,7 @@ public abstract class AnnotationSupport {
public final <A extends Annotation> AnnotationMeta<A>
findMergedAnnotation(Class<A> annotationType) {
return cache.computeIfAbsent(Pair.of(annotationType, FIND_MERGED_KEY),
k -> {
List<? extends AnnotatedElement> elements =
getAnnotatedElements();
- for (int i = 0, len = elements.size(); i < len; i++) {
+ for (int i = 0, size = elements.size(); i < size; i++) {
AnnotatedElement element = elements.get(i);
Annotation[] annotations =
element.getDeclaredAnnotations();
for (Annotation annotation : annotations) {
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/MethodMeta.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/MethodMeta.java
index 2758eb2a52..5e3f7c2eac 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/MethodMeta.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/MethodMeta.java
@@ -63,13 +63,13 @@ public final class MethodMeta extends AnnotationSupport {
int count = rpcType == RpcType.SERVER_STREAM ? 1 :
method.getParameterCount();
List<List<Parameter>> parameterHierarchies = new ArrayList<>(count);
- for (int i = 0, len = hierarchy.size(); i < len; i++) {
+ for (int i = 0, size = hierarchy.size(); i < size; i++) {
Method m = hierarchy.get(i);
Parameter[] mps = m.getParameters();
for (int j = 0; j < count; j++) {
List<Parameter> parameterHierarchy;
if (parameterHierarchies.size() <= j) {
- parameterHierarchy = new ArrayList<>(len);
+ parameterHierarchy = new ArrayList<>(size);
parameterHierarchies.add(parameterHierarchy);
} else {
parameterHierarchy = parameterHierarchies.get(j);
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/NamedValueMeta.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/NamedValueMeta.java
index 1713668acc..69a1af9bb9 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/NamedValueMeta.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/meta/NamedValueMeta.java
@@ -16,6 +16,10 @@
*/
package org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.protocol.tri.rest.Messages;
+import org.apache.dubbo.rpc.protocol.tri.rest.RestException;
+
import java.lang.reflect.Type;
import java.util.Arrays;
@@ -42,6 +46,9 @@ public class NamedValueMeta {
}
public String name() {
+ if (name == null) {
+ throw new RestException(Messages.ARGUMENT_NAME_MISSING, type);
+ }
return name;
}
@@ -49,6 +56,10 @@ public class NamedValueMeta {
this.name = name;
}
+ public boolean isNameEmpty() {
+ return StringUtils.isEmpty(name);
+ }
+
public boolean required() {
return required;
}
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/FallbackArgumentResolver.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/FallbackArgumentResolver.java
index bda38d01e4..4402c30c04 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/FallbackArgumentResolver.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/FallbackArgumentResolver.java
@@ -122,7 +122,7 @@ public class FallbackArgumentResolver extends
AbstractArgumentResolver {
return resolveValue(meta, request, response);
}
- private static class FallbackNamedValueMeta extends NamedValueMeta {
+ private static final class FallbackNamedValueMeta extends NamedValueMeta {
private final boolean noBodyParam;
private final int paramCount;
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/ParamArgumentResolver.java
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/ParamArgumentResolver.java
index 9f6c30355c..14e55e186b 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/ParamArgumentResolver.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/ParamArgumentResolver.java
@@ -205,7 +205,7 @@ public class ParamArgumentResolver extends
AbstractAnnotationBaseArgumentResolve
return RequestUtils.parseMatrixVariableValues(variableMap,
meta.name());
}
- private static class ParamNamedValueMeta extends NamedValueMeta {
+ private static final class ParamNamedValueMeta extends NamedValueMeta {
private final ParamType paramType;
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer
b/dubbo-rpc/dubbo-rpc-triple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer
deleted file mode 100644
index 65af7ec222..0000000000
---
a/dubbo-rpc/dubbo-rpc-triple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.model.ScopeModelInitializer
+++ /dev/null
@@ -1 +0,0 @@
-dubbo-rpc-triple=org.apache.dubbo.rpc.protocol.tri.TripleScopeModelInitializer
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapperTest.java
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWrapperTest.java
similarity index 82%
rename from
dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapperTest.java
rename to
dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWrapperTest.java
index f15b69368a..71f1b023af 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWapperTest.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWrapperTest.java
@@ -25,15 +25,15 @@ import com.google.protobuf.ByteString;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public class TripleCustomerProtocolWapperTest {
+public class TripleCustomerProtocolWrapperTest {
@Test
void testVarInt() {
int seed = 3;
while (seed < Integer.MAX_VALUE && seed > 0) {
- byte[] varIntBytes =
TripleCustomerProtocolWapper.varIntEncode(seed);
+ byte[] varIntBytes =
TripleCustomerProtocolWrapper.varIntEncode(seed);
ByteBuffer buffer = ByteBuffer.wrap(varIntBytes);
- int numDecodeFromVarIntByte =
TripleCustomerProtocolWapper.readRawVarint32(buffer);
+ int numDecodeFromVarIntByte =
TripleCustomerProtocolWrapper.readRawVarint32(buffer);
Assertions.assertEquals(seed, numDecodeFromVarIntByte);
seed = seed * 7;
}
@@ -42,9 +42,9 @@ public class TripleCustomerProtocolWapperTest {
@Test
void testRangeViaInt() {
for (int index = 0; index < 100000; index++) {
- byte[] varIntBytes =
TripleCustomerProtocolWapper.varIntEncode(index);
+ byte[] varIntBytes =
TripleCustomerProtocolWrapper.varIntEncode(index);
ByteBuffer buffer = ByteBuffer.wrap(varIntBytes);
- int numDecodeFromVarIntByte =
TripleCustomerProtocolWapper.readRawVarint32(buffer);
+ int numDecodeFromVarIntByte =
TripleCustomerProtocolWrapper.readRawVarint32(buffer);
Assertions.assertEquals(index, numDecodeFromVarIntByte);
}
}
@@ -52,9 +52,9 @@ public class TripleCustomerProtocolWapperTest {
@Test
void testTripleRequestWrapperWithOnlySerializeType() {
String serialize = "hession";
- TripleCustomerProtocolWapper.TripleRequestWrapper.Builder builder =
-
TripleCustomerProtocolWapper.TripleRequestWrapper.Builder.newBuilder();
- TripleCustomerProtocolWapper.TripleRequestWrapper tripleRequestWrapper
=
+ TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder builder =
+
TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder.newBuilder();
+ TripleCustomerProtocolWrapper.TripleRequestWrapper
tripleRequestWrapper =
builder.setSerializeType(serialize).build();
final TripleWrapper.TripleRequestWrapper.Builder pbbuilder =
TripleWrapper.TripleRequestWrapper.newBuilder().setSerializeType(serialize);
@@ -69,9 +69,9 @@ public class TripleCustomerProtocolWapperTest {
byte[] secondArg = "i am second arg".getBytes(StandardCharsets.UTF_8);
String serialize = "hession";
- TripleCustomerProtocolWapper.TripleRequestWrapper.Builder builder =
-
TripleCustomerProtocolWapper.TripleRequestWrapper.Builder.newBuilder();
- TripleCustomerProtocolWapper.TripleRequestWrapper tripleRequestWrapper
= builder.setSerializeType(serialize)
+ TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder builder =
+
TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder.newBuilder();
+ TripleCustomerProtocolWrapper.TripleRequestWrapper
tripleRequestWrapper = builder.setSerializeType(serialize)
.addArgTypes("com.google.protobuf.ByteString")
.addArgTypes("org.apache.dubbo.common.URL")
.addArgs(firstArg)
@@ -95,9 +95,9 @@ public class TripleCustomerProtocolWapperTest {
byte[] secondArg = "i am second arg".getBytes(StandardCharsets.UTF_8);
String serialize = "hession4";
- TripleCustomerProtocolWapper.TripleRequestWrapper.Builder builder =
-
TripleCustomerProtocolWapper.TripleRequestWrapper.Builder.newBuilder();
- TripleCustomerProtocolWapper.TripleRequestWrapper tripleRequestWrapper
= builder.setSerializeType(serialize)
+ TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder builder =
+
TripleCustomerProtocolWrapper.TripleRequestWrapper.Builder.newBuilder();
+ TripleCustomerProtocolWrapper.TripleRequestWrapper
tripleRequestWrapper = builder.setSerializeType(serialize)
.addArgTypes("com.google.protobuf.ByteString")
.addArgTypes("org.apache.dubbo.common.URL")
.addArgs(firstArg)
@@ -110,8 +110,8 @@ public class TripleCustomerProtocolWapperTest {
.addArgs(ByteString.copyFrom(firstArg))
.addArgs(ByteString.copyFrom(secondArg));
- TripleCustomerProtocolWapper.TripleRequestWrapper parseFrom =
- TripleCustomerProtocolWapper.TripleRequestWrapper.parseFrom(
+ TripleCustomerProtocolWrapper.TripleRequestWrapper parseFrom =
+ TripleCustomerProtocolWrapper.TripleRequestWrapper.parseFrom(
pbbuilder.build().toByteArray());
Assertions.assertEquals(parseFrom.getSerializeType(),
tripleRequestWrapper.getSerializeType());
Assertions.assertArrayEquals(
@@ -125,9 +125,9 @@ public class TripleCustomerProtocolWapperTest {
void testTripleResponseWrapperWithNullData() {
String serializeType = "hession4";
String type = "String";
- TripleCustomerProtocolWapper.TripleResponseWrapper.Builder builder =
-
TripleCustomerProtocolWapper.TripleResponseWrapper.Builder.newBuilder();
- TripleCustomerProtocolWapper.TripleResponseWrapper
tripleResponseWrapper =
+ TripleCustomerProtocolWrapper.TripleResponseWrapper.Builder builder =
+
TripleCustomerProtocolWrapper.TripleResponseWrapper.Builder.newBuilder();
+ TripleCustomerProtocolWrapper.TripleResponseWrapper
tripleResponseWrapper =
builder.setSerializeType(serializeType).setType(type).build();
TripleWrapper.TripleResponseWrapper.Builder pbBuilder =
TripleWrapper.TripleResponseWrapper.newBuilder().setType(type).setSerializeType(serializeType);
@@ -155,9 +155,9 @@ public class TripleCustomerProtocolWapperTest {
+ " */";
byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
- TripleCustomerProtocolWapper.TripleResponseWrapper.Builder builder =
-
TripleCustomerProtocolWapper.TripleResponseWrapper.Builder.newBuilder();
- TripleCustomerProtocolWapper.TripleResponseWrapper
tripleResponseWrapper = builder.setSerializeType(
+ TripleCustomerProtocolWrapper.TripleResponseWrapper.Builder builder =
+
TripleCustomerProtocolWrapper.TripleResponseWrapper.Builder.newBuilder();
+ TripleCustomerProtocolWrapper.TripleResponseWrapper
tripleResponseWrapper = builder.setSerializeType(
serializeType)
.setType(type)
.setData(dataBytes)
@@ -194,8 +194,8 @@ public class TripleCustomerProtocolWapperTest {
.setData(ByteString.copyFrom(dataBytes))
.setSerializeType(serializeType);
byte[] pbRawBytes = pbBuilder.build().toByteArray();
- TripleCustomerProtocolWapper.TripleResponseWrapper
tripleResponseWrapper =
-
TripleCustomerProtocolWapper.TripleResponseWrapper.parseFrom(pbRawBytes);
+ TripleCustomerProtocolWrapper.TripleResponseWrapper
tripleResponseWrapper =
+
TripleCustomerProtocolWrapper.TripleResponseWrapper.parseFrom(pbRawBytes);
Assertions.assertArrayEquals(pbRawBytes,
tripleResponseWrapper.toByteArray());
Assertions.assertArrayEquals(dataBytes,
tripleResponseWrapper.getData());
Assertions.assertEquals(serializeType,
tripleResponseWrapper.getSerializeType());
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/test/TestRunnerImpl.java
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/test/TestRunnerImpl.java
index a0451f3917..47020e51e5 100644
---
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/test/TestRunnerImpl.java
+++
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/test/TestRunnerImpl.java
@@ -30,7 +30,6 @@ import
org.apache.dubbo.remoting.http12.message.HttpMessageDecoder;
import org.apache.dubbo.remoting.http12.message.HttpMessageEncoder;
import org.apache.dubbo.remoting.http12.message.MediaType;
import org.apache.dubbo.remoting.http12.message.codec.JsonCodec;
-import org.apache.dubbo.remoting.http12.message.codec.UrlEncodeFormCodec;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
@@ -172,7 +171,7 @@ final class TestRunnerImpl implements TestRunner {
HttpMessageEncoder encoder;
Object coder;
if (isForm) {
- encoder = new UrlEncodeFormCodec(null);
+ encoder = UrlEncodeFormEncoder.INSTANCE;
coder = context.getHttpMessageDecoder();
} else {
encoder = context.getHttpMessageEncoder();
diff --git
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/test/UrlEncodeFormEncoder.java
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/test/UrlEncodeFormEncoder.java
new file mode 100644
index 0000000000..e1af0bbbc6
--- /dev/null
+++
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/test/UrlEncodeFormEncoder.java
@@ -0,0 +1,73 @@
+/*
+ * 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.rpc.protocol.tri.test;
+
+import org.apache.dubbo.remoting.http12.exception.DecodeException;
+import org.apache.dubbo.remoting.http12.exception.EncodeException;
+import org.apache.dubbo.remoting.http12.exception.HttpStatusException;
+import org.apache.dubbo.remoting.http12.message.HttpMessageEncoder;
+import org.apache.dubbo.remoting.http12.message.MediaType;
+
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+
+public final class UrlEncodeFormEncoder implements HttpMessageEncoder {
+
+ public static final UrlEncodeFormEncoder INSTANCE = new
UrlEncodeFormEncoder();
+
+ @Override
+ public void encode(OutputStream os, Object data, Charset charset) throws
EncodeException {
+ try {
+ if (data instanceof String) {
+ os.write(((String) data).getBytes());
+ return;
+ }
+ if (data instanceof Map) {
+ StringBuilder sb = new StringBuilder(64);
+ for (Map.Entry<?, ?> entry : ((Map<?, ?>) data).entrySet()) {
+ sb.append(encode(entry.getKey()))
+ .append('=')
+ .append(encode(entry.getValue()))
+ .append('&');
+ }
+ int len = sb.length();
+ if (len > 1) {
+ os.write(sb.substring(0, len - 1).getBytes(charset));
+ }
+ return;
+ }
+ } catch (HttpStatusException e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new EncodeException("Error encoding form-urlencoded", t);
+ }
+ throw new DecodeException("Only supports String or Map as return
type.");
+ }
+
+ private static String encode(Object value) throws
UnsupportedEncodingException {
+ return URLEncoder.encode(String.valueOf(value),
StandardCharsets.UTF_8.name());
+ }
+
+ @Override
+ public MediaType mediaType() {
+ return MediaType.APPLICATION_FROM_URLENCODED;
+ }
+}