-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from wiremock/any-type-issue
Added support for Any type in a slightly hacky way
- Loading branch information
Showing
13 changed files
with
211 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/wiremock/grpc/internal/BaseCallHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2023-2024 Thomas Akehurst | ||
* | ||
* Licensed 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.wiremock.grpc.internal; | ||
|
||
import com.github.tomakehurst.wiremock.http.StubRequestHandler; | ||
import com.google.protobuf.Descriptors; | ||
|
||
public abstract class BaseCallHandler { | ||
|
||
protected final StubRequestHandler stubRequestHandler; | ||
protected final Descriptors.ServiceDescriptor serviceDescriptor; | ||
protected final Descriptors.MethodDescriptor methodDescriptor; | ||
|
||
protected final JsonMessageConverter jsonMessageConverter; | ||
|
||
protected BaseCallHandler( | ||
StubRequestHandler stubRequestHandler, | ||
Descriptors.ServiceDescriptor serviceDescriptor, | ||
Descriptors.MethodDescriptor methodDescriptor, | ||
JsonMessageConverter jsonMessageConverter) { | ||
this.stubRequestHandler = stubRequestHandler; | ||
this.serviceDescriptor = serviceDescriptor; | ||
this.methodDescriptor = methodDescriptor; | ||
this.jsonMessageConverter = jsonMessageConverter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/wiremock/grpc/internal/JsonMessageConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2023-2024 Thomas Akehurst | ||
* | ||
* Licensed 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.wiremock.grpc.internal; | ||
|
||
import com.github.tomakehurst.wiremock.common.Exceptions; | ||
import com.google.protobuf.Message; | ||
import com.google.protobuf.MessageOrBuilder; | ||
import com.google.protobuf.TypeRegistry; | ||
import com.google.protobuf.util.JsonFormat; | ||
|
||
public class JsonMessageConverter { | ||
|
||
private final JsonFormat.Printer jsonPrinter; | ||
private final JsonFormat.Parser jsonParser; | ||
|
||
public JsonMessageConverter(TypeRegistry typeRegistry) { | ||
jsonPrinter = JsonFormat.printer().usingTypeRegistry(typeRegistry); | ||
jsonParser = JsonFormat.parser().usingTypeRegistry(typeRegistry); | ||
} | ||
|
||
public String toJson(MessageOrBuilder message) { | ||
return Exceptions.uncheck(() -> jsonPrinter.print(message), String.class); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T extends Message, B extends Message.Builder> T toMessage(String json, B builder) { | ||
Exceptions.uncheck(() -> jsonParser.merge(json, builder)); | ||
return (T) builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.