Feature/3.2 beta7 rest formdata fix (#12040)
* Fix conflict
* Fix header
* fix import
* fix import
* fix import
* fix import
* fix import
* Fix json
* revert some change
* Remove jsonfactory
* Remove jsonfactory
* Simplify rest client
* Fix protocol
* fix codec
* tmp disable test
* rest metadata resolver add interface judge
* add rest metadata resolve unit test & fix AbstractServiceRestMetadataResolver
* org.apache.dubbo.metadata.rest.ParamType null exclude & add default accept header
* RestProtocolTest
refer add context path
unit test
* some fix
* ADD TODO
* RESOLVE HTTP client java.net.SocketException: socket closed
* RESOLVE HTTP client java.net.SocketException: socket closed
* add spring mvc rest protocol unit test
* rest protocol http response code deal
* rest protocol http response message
* fix some review advice
* fix some review advice
* add rest metadata resolve unit test & fix AbstractServiceRestMetadataResolver
* org.apache.dubbo.metadata.rest.ParamType null exclude & add default accept header
* RestProtocolTest
refer add context path
unit test
* some fix
* fix some review advice
* add spring mvc rest protocol unit test
* rest protocol http response code deal
* rest protocol http response message
* URLConnectionRestClient getMessage
* remove unused import
* import fix
* code merge
* remove unused import
* code merge
* code merge
* some fix
* code merge
* code merge
* code merge
* code merge
* Rest http server
* rest protocol do export
* code merge
* rest protocol provider
* rest protocol provider
* rest protocol response
* rest protocol netty request
* Fix conflicts
* change restResult InputStream to bytes protect from fd leak
* merge code
* Fix import
* Fix import
* Fix uts
* Remove unused code
* Fix logger
* Update okhttp version
* Update okhttp version
* rest protocol add AnotherUserRestService service ut
* rest protocol add String & byteArray codec
* Fix version
* Fix uts
* rest protocol add XMLCodec
* stream release
* ServiceRestMetadata port change int to Integer
* service RestMetadata service map init
* xml codec change for xxe
* Fix import
* code style
* code style
* Fix shade
* change for rest client recreate & destroy bugs
* remove recreate double check for code merge
* rest client destroy check
* add todo
* consumer merge code
* rest response
* BodyProviderParamParser bytes
* merge upstream 3.2 to 3.2_consumer_proxy_invocation_handler
* merge upstream 3.2 to feature/3.2-rest_protocol_provider
* fix rest provider ut
* path compare
* path compare
* fix provider rest ut
* fix provider rest ut
* fix provider rest ut
* testJaxrsPathPattern ut
* JAXRSServiceRestMetadataResolverTest ut
* JAXRSServiceRestMetadataResolverTest ut
* add netty http server
* add netty http server response encode
* rest netty http server codec
* rest netty http server codec
* some fix netty http server
* add spring mvc ut for netty http server
* okhttp_version to 3.14.2 to resolve dependency conflict
* Fix license
* add rest protocol exception mapper
* add TODO ExceptionMapper should be static or instance
* add TODO OKHttpRestClient implements of version >=4.0
* fix licence format
* fix ut
* fix testPathMatcher
* url context path
* format context path from url
* fix illegal logger method invocations:
* remove org.jetbrains.annotations.NotNull
* add Newly created SPI interface to dubbo-all
* some format
* merge 3.2
* merge 3.2
* merge 3.2
* Revert "merge 3.2"
This reverts commit ad19804437.
* merge upstream 3.2
* change HttpHandler throws IOException
* deal with RPCInvocation build error
* request is present
* remove request facade unused code
* remove thirdpart web server code
* remove thirdpart web server code
* remove unused imports
* remove unused code
* rest protocol directly implement AbstractProtocol
* code style
* change method modifier
* form body java bean convert
* change header name to RestHeaderEnum
* attachment header
* http handler error info
* rest header distinguish from attachment
* some log & double path check
* remove RestMethodMetadata ServiceRestMetadata refer
* reconstruct http handler
* content-type judge
* add RestInvoker
* setTargetServiceUniqueName
* path mapper & http handler
* remove unused code
* netty thread pool
* RestHttpRequestDecoder @ChannelHandler.Sharable
* add rest client ut
* fix metadata resolver test
* fix metadata resolver test
* add some description to code
* add error test
* error message append
* add request address
* request address
* http netty server reconstruct
* http netty server TODO add SslServerTlsHandler
* replace all pair use
* pair fix
* add NumberUtils ut
* add hex number ut
* add no annotation primitive ut
* remove unsed code
* throw exception
* add ut
* rename constants & remove unused code
* add ut
* add ut
* add ut
* add ut
* remove ut
* add restClient ut
* add restClient ut
* add DataParseUtils ut
* add path matcher ut
* add request template ut
* add request template ut
* fix xml codec
* some fix
* Class to Class<?>
* media type judge fix and add codec ut
* remove print
* add header map param ut
* add header map param null ut
* MediaTypeUtil ut
* add param & header & multimap ut
* remove unused import
* fix error log format
* test header param
* test header number param
* add MediaType ut
* add MediaType & metadata resolve ut
* imports
* add netty request facade ut
* some format
* add ExceptionMapperTest
* add hasExceptionMapper pre judge
* fix exception mapper throws
* change static ExceptionMapper to instance
* resolve Java_Zulu_jdk/17.0.6-10/x64 param is not throwable , exception
mapper ut
* fix reflects util some detail
* remove unused code
* add null arg ut
* rest invoker response future complete Exceptionally
* fix http netty server executor
* set rpc context request & response
* add rest token attachment
* add http method ut
* remove unused code
* some fix
* remove keep-alive header
* remove unused code
* close channel
* add response connection:close head
* fix no content-type
* fix no content-type form
---------
Co-authored-by: Albumen Kevin <jhq0812@gmail.com>
Co-authored-by: suncr <suncairong@moresec.cn>
This commit is contained in:
parent
bbb151b0dc
commit
5cd5b32b8b
|
|
@ -39,6 +39,10 @@ public enum ParamType {
|
|||
FORM(addSupportTypes(JAXRSClassConstants.FORM_PARAM_ANNOTATION_CLASS,
|
||||
SpringMvcClassConstants.REQUEST_BODY_ANNOTATION_CLASS)),
|
||||
|
||||
PROVIDER_BODY(addSupportTypes(
|
||||
JAXRSClassConstants.REST_EASY_BODY_ANNOTATION_CLASS,JAXRSClassConstants.FORM_PARAM_ANNOTATION_CLASS,
|
||||
SpringMvcClassConstants.REQUEST_BODY_ANNOTATION_CLASS, BodyTag.class)),
|
||||
|
||||
EMPTY(addSupportTypes());
|
||||
private List<Class> annotationClasses;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,13 +17,17 @@
|
|||
package org.apache.dubbo.rpc.protocol.rest.annotation.param.parse.consumer;
|
||||
|
||||
import org.apache.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.ReflectUtils;
|
||||
import org.apache.dubbo.metadata.rest.ArgInfo;
|
||||
import org.apache.dubbo.metadata.rest.ParamType;
|
||||
import org.apache.dubbo.metadata.rest.media.MediaType;
|
||||
import org.apache.dubbo.remoting.http.RequestTemplate;
|
||||
import org.apache.dubbo.rpc.protocol.rest.constans.RestConstant;
|
||||
import org.apache.dubbo.rpc.protocol.rest.util.DataParseUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -64,6 +68,11 @@ public class FormConsumerParamParser implements BaseConsumerParamParser {
|
|||
requestTemplate.body(tmp, Map.class);
|
||||
}
|
||||
|
||||
Collection<String> headers = requestTemplate.getHeaders(RestConstant.CONTENT_TYPE);
|
||||
if (CollectionUtils.isEmpty(headers)) {
|
||||
requestTemplate.addHeader(RestConstant.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE.value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class HeaderConsumerParamParser implements BaseConsumerParamParser {
|
|||
}
|
||||
} else {
|
||||
// others
|
||||
requestTemplate.addHeader(argInfo.getParamName(), headerValue);
|
||||
requestTemplate.addHeader(argInfo.getAnnotationNameAttribute(), headerValue);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class ParameterConsumerParamParser implements BaseConsumerParamParser {
|
|||
requestTemplate.addParam(String.valueOf(name), paramValues.get(name));
|
||||
}
|
||||
} else {
|
||||
requestTemplate.addParam(argInfo.getParamName(), paramValue);
|
||||
requestTemplate.addParam(argInfo.getAnnotationNameAttribute(), paramValue);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,6 @@ public class BodyProviderParamParser extends ProviderParamParser {
|
|||
|
||||
@Override
|
||||
protected ParamType getParamType() {
|
||||
return ParamType.BODY;
|
||||
return ParamType.PROVIDER_BODY;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class NettyHttpHandler implements HttpHandler<NettyRequestFacade, NettyHt
|
|||
RpcContext.getServiceContext().setLocalAddress(requestFacade.getLocalAddr(), requestFacade.getLocalPort());
|
||||
|
||||
// set request
|
||||
RpcContext.getServiceContext().setRequest(requestFacade.getRequest());
|
||||
RpcContext.getServiceContext().setRequest(requestFacade);
|
||||
|
||||
// set response
|
||||
RpcContext.getServiceContext().setResponse(nettyHttpResponse);
|
||||
|
|
@ -149,7 +149,7 @@ public class NettyHttpHandler implements HttpHandler<NettyRequestFacade, NettyHt
|
|||
* @throws Exception
|
||||
*/
|
||||
private void writeResult(NettyHttpResponse nettyHttpResponse, RequestFacade request, Invoker invoker, Object value, Class returnType) throws Exception {
|
||||
MediaType mediaType = getAcceptMediaType(request);
|
||||
MediaType mediaType = getAcceptMediaType(request,returnType);
|
||||
|
||||
MessageCodecResultPair booleanMediaTypePair = HttpMessageCodecManager.httpMessageEncode(nettyHttpResponse.getOutputStream(), value, invoker.getUrl(), mediaType, returnType);
|
||||
|
||||
|
|
@ -162,9 +162,9 @@ public class NettyHttpHandler implements HttpHandler<NettyRequestFacade, NettyHt
|
|||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private MediaType getAcceptMediaType(RequestFacade request) {
|
||||
private MediaType getAcceptMediaType(RequestFacade request,Class<?> returnType) {
|
||||
String accept = request.getHeader(RestHeaderEnum.ACCEPT.getHeader());
|
||||
MediaType mediaType = MediaTypeUtil.convertMediaType(null, accept);
|
||||
MediaType mediaType = MediaTypeUtil.convertMediaType(returnType, accept);
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ public class NettyHttpHandler implements HttpHandler<NettyRequestFacade, NettyHt
|
|||
private void acceptSupportJudge(RequestFacade requestFacade, Class<?> returnType) {
|
||||
try {
|
||||
// media type judge
|
||||
getAcceptMediaType(requestFacade);
|
||||
getAcceptMediaType(requestFacade,returnType);
|
||||
} catch (UnSupportContentTypeException e) {
|
||||
// return type judge
|
||||
MediaType mediaType = HttpMessageCodecManager.typeSupport(returnType);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ public class HttpMessageCodecManager {
|
|||
|
||||
|
||||
public static Object httpMessageDecode(byte[] body, Class<?> type, MediaType mediaType) throws Exception {
|
||||
if (body == null || body.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (HttpMessageCodec httpMessageCodec : httpMessageCodecs) {
|
||||
if (httpMessageCodec.contentTypeSupport(mediaType, type) || typeJudge(mediaType, type, httpMessageCodec)) {
|
||||
return httpMessageCodec.decode(body, type);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public class JsonCodec implements HttpMessageCodec<byte[], OutputStream> {
|
|||
static {
|
||||
|
||||
unSupportClasses.add(byte[].class);
|
||||
unSupportClasses.add(String.class);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ public class StringCodec implements HttpMessageCodec<byte[], OutputStream> {
|
|||
|
||||
@Override
|
||||
public Object decode(byte[] body, Class<?> targetType) throws Exception {
|
||||
if (body == null || body.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return new String(body);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@ public interface DemoService {
|
|||
|
||||
@POST
|
||||
@Path("number")
|
||||
@Produces({MediaType.TEXT_PLAIN})
|
||||
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
|
||||
Long testFormBody(@FormParam("number") Long number);
|
||||
|
||||
boolean isCalled();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import javax.ws.rs.Consumes;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
|
@ -46,10 +45,6 @@ public class DemoServiceImpl implements DemoService {
|
|||
return "Hello, " + name;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("number")
|
||||
@Produces({javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED})
|
||||
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
|
||||
@Override
|
||||
public Long testFormBody(Long number) {
|
||||
return number;
|
||||
|
|
|
|||
Loading…
Reference in New Issue