fix h1 and grpc status code (#12994)

This commit is contained in:
icodening 2023-09-01 17:05:45 +08:00 committed by GitHub
parent 059b75c533
commit cfd0be3a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 1 deletions

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.remoting.http12;
import org.apache.dubbo.remoting.http12.exception.EncodeException;
import org.apache.dubbo.remoting.http12.exception.HttpStatusException;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
@ -119,6 +120,8 @@ public abstract class AbstractServerHttpChannelObserver implements CustomizableH
HttpOutputMessage httpOutputMessage = encodeHttpOutputMessage(errorResponse);
this.httpMessageCodec.encode(httpOutputMessage.getBody(), errorResponse);
getHttpChannel().writeMessage(httpOutputMessage);
} catch (Throwable ex) {
throwable = new EncodeException(ex);
} finally {
doOnCompleted(throwable);
}

View File

@ -161,7 +161,7 @@ public abstract class AbstractServerTransportListener<HEADER extends RequestMeta
throw new UnsupportedMediaTypeException(contentType);
}
this.httpMessageCodec = httpMessageCodec;
this.serviceDescriptor = findServiceDescriptor(invoker, serviceName, hasStub);
setServiceDescriptor(findServiceDescriptor(invoker, serviceName, hasStub));
setHttpMessageListener(newHttpMessageListener());
onMetadataCompletion(metadata);
}

View File

@ -29,6 +29,7 @@ import org.apache.dubbo.remoting.http12.message.MethodMetadata;
import org.apache.dubbo.remoting.http12.message.StreamingDecoder;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.TriRpcStatus;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
@ -66,10 +67,16 @@ public class GrpcHttp2ServerTransportListener extends GenericHttp2ServerTranspor
private void grpcTrailersCustomize(HttpHeaders httpHeaders, Throwable throwable) {
httpHeaders.set(GrpcHeaderNames.GRPC_STATUS.getName(), "0");
if (throwable != null) {
httpHeaders.set(GrpcHeaderNames.GRPC_STATUS.getName(), httpStatusToGrpcStatus(throwable));
httpHeaders.set(GrpcHeaderNames.GRPC_MESSAGE.getName(), throwable.getMessage());
}
}
private static String httpStatusToGrpcStatus(Throwable throwable) {
//http status code map to grpc status code
return String.valueOf(TriRpcStatus.INTERNAL.code.code);
}
@Override
protected RpcInvocation buildRpcInvocation(Invoker<?> invoker, ServiceDescriptor serviceDescriptor, MethodDescriptor methodDescriptor) {
RpcInvocation rpcInvocation = super.buildRpcInvocation(invoker, serviceDescriptor, methodDescriptor);

View File

@ -81,6 +81,8 @@ public class DefaultHttp11ServerTransportListener extends AbstractServerTranspor
MethodDescriptor methodDescriptor = findMethodDescriptor(getServiceDescriptor(), originalMethodName, hasStub);
MethodMetadata methodMetadata = MethodMetadata.fromMethodDescriptor(methodDescriptor);
RpcInvocation rpcInvocation = buildRpcInvocation(getInvoker(), getServiceDescriptor(), methodDescriptor);
setMethodDescriptor(methodDescriptor);
setMethodMetadata(methodMetadata);
setRpcInvocation(rpcInvocation);
HttpMessageCodec httpMessageCodec = getHttpMessageCodec();
ListeningDecoder listeningDecoder = newListeningDecoder(httpMessageCodec, methodMetadata.getActualRequestTypes());