Skip to content

Commit 5c0bd7f

Browse files
fixed the issue that the file name of message.proto is not supported (#15655)
* fixed the issue that the file name of message.proto is not supported * add unit test --------- Co-authored-by: earthchen <earthchen1996@gmail.com>
1 parent 8f2b4de commit 5c0bd7f

File tree

8 files changed

+111
-21
lines changed

8 files changed

+111
-21
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
syntax = "proto3";
18+
19+
option java_multiple_files = true;
20+
option java_package = "org.apache.dubbo.demo.message";
21+
option java_outer_classname = "Message";
22+
option objc_class_prefix = "HLW";
23+
24+
package message;
25+
26+
// The request message containing the user's name.
27+
message HelloRequest {
28+
string name = 1;
29+
}
30+
31+
// The response message containing the greetings.
32+
message HelloReply {
33+
string message = 1;
34+
}
35+
36+
// Service definition.
37+
service MessageService {
38+
// Sends a greeting.
39+
rpc sayHello(HelloRequest) returns (HelloReply);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.springboot.idl.demo;
18+
19+
import org.apache.dubbo.demo.message.DubboMessageServiceTriple;
20+
import org.apache.dubbo.rpc.protocol.tri.service.SchemaDescriptorRegistry;
21+
22+
import com.google.protobuf.Descriptors.FileDescriptor;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
25+
26+
public class MessageServiceTest {
27+
28+
@Test
29+
public void testMessageGenerator() {
30+
try {
31+
// load class
32+
Class.forName(DubboMessageServiceTriple.class.getName());
33+
} catch (ClassNotFoundException ignored) {
34+
}
35+
FileDescriptor schemaDescriptor =
36+
SchemaDescriptorRegistry.getSchemaDescriptor(DubboMessageServiceTriple.SERVICE_NAME);
37+
Assertions.assertNotNull(schemaDescriptor);
38+
Assertions.assertEquals("message.proto", schemaDescriptor.getName());
39+
}
40+
}

dubbo-plugin/dubbo-compiler/src/main/resources/Dubbo3TripleInterfaceStub.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import org.apache.dubbo.common.stream.StreamObserver;
2323
import org.apache.dubbo.remoting.http12.HttpMethods;
2424
import org.apache.dubbo.remoting.http12.rest.Mapping;
2525
import org.apache.dubbo.rpc.stub.annotations.GRequest;
26-
import com.google.protobuf.Message;
2726

2827
import java.util.HashMap;
2928
import java.util.Map;
@@ -32,7 +31,12 @@ import java.util.concurrent.CompletableFuture;
3231

3332
public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub {
3433
34+
{{#packageName}}
3535
String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}";
36+
{{/packageName}}
37+
{{^packageName}}
38+
String JAVA_SERVICE_NAME = "{{serviceName}}";
39+
{{/packageName}}
3640
{{#commonPackageName}}
3741
String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}";
3842
{{/commonPackageName}}

dubbo-plugin/dubbo-compiler/src/main/resources/Dubbo3TripleStub.mustache

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import org.apache.dubbo.rpc.stub.StubMethodHandler;
3939
import org.apache.dubbo.rpc.stub.StubSuppliers;
4040
import org.apache.dubbo.rpc.stub.UnaryStubMethodHandler;
4141

42-
import com.google.protobuf.Message;
43-
4442
import java.util.HashMap;
4543
import java.util.Map;
4644
import java.util.function.BiConsumer;
@@ -68,38 +66,38 @@ public final class {{className}} {
6866

6967
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
7068
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.UNARY,
71-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
69+
obj -> ((com.google.protobuf.Message) obj).toByteArray(),obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
7270
{{outputType}}::parseFrom);
7371

7472
private static final StubMethodDescriptor {{methodName}}AsyncMethod = new StubMethodDescriptor("{{originMethodName}}",
7573
{{inputType}}.class, java.util.concurrent.CompletableFuture.class, MethodDescriptor.RpcType.UNARY,
76-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
74+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
7775
{{outputType}}::parseFrom);
7876

7977
private static final StubMethodDescriptor {{methodName}}ProxyAsyncMethod = new StubMethodDescriptor("{{originMethodName}}Async",
8078
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.UNARY,
81-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
79+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
8280
{{outputType}}::parseFrom);
8381
{{/unaryMethods}}
8482
{{#serverStreamingMethods}}
8583

8684
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
8785
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.SERVER_STREAM,
88-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
86+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
8987
{{outputType}}::parseFrom);
9088
{{/serverStreamingMethods}}
9189
{{#clientStreamingMethods}}
9290

9391
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
9492
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.CLIENT_STREAM,
95-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
93+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
9694
{{outputType}}::parseFrom);
9795
{{/clientStreamingMethods}}
9896
{{#biStreamingWithoutClientStreamMethods}}
9997

10098
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
10199
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.BI_STREAM,
102-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
100+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
103101
{{outputType}}::parseFrom);
104102
{{/biStreamingWithoutClientStreamMethods}}
105103

dubbo-plugin/dubbo-compiler/src/main/resources/MutinyDubbo3TripleInterfaceStub.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ import io.smallrye.mutiny.Uni;
2424

2525
public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub {
2626
27+
{{#packageName}}
2728
String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}";
29+
{{/packageName}}
30+
{{^packageName}}
31+
String JAVA_SERVICE_NAME = "{{serviceName}}";
32+
{{/packageName}}
2833
{{#commonPackageName}}
2934
String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}";
3035
{{/commonPackageName}}
3136
{{^commonPackageName}}
32-
String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}";
37+
String SERVICE_NAME = "{{serviceName}}";
3338
{{/commonPackageName}}
3439
{{#methods}}
3540
{{#javaDoc}}

dubbo-plugin/dubbo-compiler/src/main/resources/MutinyDubbo3TripleStub.mustache

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package {{packageName}};
2020
{{/packageName}}
2121

22-
import com.google.protobuf.Message;
2322
import org.apache.dubbo.common.URL;
2423
import org.apache.dubbo.rpc.Invoker;
2524
import org.apache.dubbo.rpc.PathResolver;
@@ -72,7 +71,7 @@ public final class {{className}} {
7271
{{/javaDoc}}
7372
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
7473
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.UNARY,
75-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
74+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
7675
{{outputType}}::parseFrom);
7776
{{/unaryMethods}}
7877

@@ -82,7 +81,7 @@ public final class {{className}} {
8281
{{/javaDoc}}
8382
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
8483
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.SERVER_STREAM,
85-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
84+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
8685
{{outputType}}::parseFrom);
8786
{{/serverStreamingMethods}}
8887

@@ -92,7 +91,7 @@ public final class {{className}} {
9291
{{/javaDoc}}
9392
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
9493
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.CLIENT_STREAM,
95-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
94+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
9695
{{outputType}}::parseFrom);
9796
{{/clientStreamingMethods}}
9897

@@ -102,7 +101,7 @@ public final class {{className}} {
102101
{{/javaDoc}}
103102
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
104103
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.BI_STREAM,
105-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
104+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
106105
{{outputType}}::parseFrom);
107106
{{/biStreamingWithoutClientStreamMethods}}
108107

dubbo-plugin/dubbo-compiler/src/main/resources/ReactorDubbo3TripleInterfaceStub.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ import reactor.core.publisher.Mono;
2424

2525
public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub {
2626
27+
{{#packageName}}
2728
String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}";
29+
{{/packageName}}
30+
{{^packageName}}
31+
String JAVA_SERVICE_NAME = "{{serviceName}}";
32+
{{/packageName}}
2833
{{#commonPackageName}}
2934
String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}";
3035
{{/commonPackageName}}
3136
{{^commonPackageName}}
32-
String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}";
37+
String SERVICE_NAME = "{{serviceName}}";
3338
{{/commonPackageName}}
3439
{{#methods}}
3540
{{#javaDoc}}

dubbo-plugin/dubbo-compiler/src/main/resources/ReactorDubbo3TripleStub.mustache

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package {{packageName}};
2020
{{/packageName}}
2121

22-
import com.google.protobuf.Message;
2322
import org.apache.dubbo.common.URL;
2423
import org.apache.dubbo.rpc.Invoker;
2524
import org.apache.dubbo.rpc.PathResolver;
@@ -72,7 +71,7 @@ public final class {{className}} {
7271
{{/javaDoc}}
7372
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
7473
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.UNARY,
75-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
74+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
7675
{{outputType}}::parseFrom);
7776
{{/unaryMethods}}
7877

@@ -82,7 +81,7 @@ public final class {{className}} {
8281
{{/javaDoc}}
8382
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
8483
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.SERVER_STREAM,
85-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
84+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
8685
{{outputType}}::parseFrom);
8786
{{/serverStreamingMethods}}
8887

@@ -92,7 +91,7 @@ public final class {{className}} {
9291
{{/javaDoc}}
9392
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
9493
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.CLIENT_STREAM,
95-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
94+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
9695
{{outputType}}::parseFrom);
9796
{{/clientStreamingMethods}}
9897

@@ -102,7 +101,7 @@ public final class {{className}} {
102101
{{/javaDoc}}
103102
private static final StubMethodDescriptor {{methodName}}Method = new StubMethodDescriptor("{{originMethodName}}",
104103
{{inputType}}.class, {{outputType}}.class, MethodDescriptor.RpcType.BI_STREAM,
105-
obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), {{inputType}}::parseFrom,
104+
obj -> ((com.google.protobuf.Message) obj).toByteArray(), obj -> ((com.google.protobuf.Message) obj).toByteArray(), {{inputType}}::parseFrom,
106105
{{outputType}}::parseFrom);
107106
{{/biStreamingWithoutClientStreamMethods}}
108107

0 commit comments

Comments
 (0)