Skip to content

Commit

Permalink
feat(transcoding): added support for path parameter and query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Apr 24, 2024
1 parent 3fe1e11 commit 44ac07c
Show file tree
Hide file tree
Showing 30 changed files with 291 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import org.jboss.logging.Logger;

import com.google.protobuf.*;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import com.google.protobuf.util.JsonFormat;

import io.grpc.MethodDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.jboss.jandex.DotName;

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.grpc.deployment.GrpcClientBuildItem.ClientInfo;
import io.quarkus.grpc.deployment.GrpcClientBuildItem.ClientType;

public final class GrpcClientBuildItem extends MultiBuildItem {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@
import io.grpc.stub.AbstractBlockingStub;
import io.grpc.stub.AbstractStub;
import io.quarkus.gizmo.MethodDescriptor;
import io.quarkus.grpc.*;
import io.quarkus.grpc.GlobalInterceptor;
import io.quarkus.grpc.GrpcClient;
import io.quarkus.grpc.GrpcService;
import io.quarkus.grpc.GrpcTranscodingMethod;
import io.quarkus.grpc.MutinyBean;
import io.quarkus.grpc.MutinyClient;
import io.quarkus.grpc.MutinyGrpc;
import io.quarkus.grpc.MutinyService;
import io.quarkus.grpc.MutinyStub;
import io.quarkus.grpc.MutinyTranscodingService;
import io.quarkus.grpc.RegisterClientInterceptor;
import io.quarkus.grpc.RegisterInterceptor;
import io.quarkus.grpc.RegisterInterceptors;
import io.quarkus.grpc.runtime.supports.Channels;
import io.quarkus.grpc.runtime.supports.GrpcClientConfigProvider;
import io.smallrye.common.annotation.Blocking;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package io.quarkus.grpc.deployment;

import java.util.*;

import org.jboss.jandex.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,7 +22,10 @@
import io.quarkus.arc.processor.BuiltinScope;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.annotations.*;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { QwcHotReloadElement, html, css} from 'qwc-hot-reload-element';
import { JsonRpc } from 'jsonrpc';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import { gridRowDetailsRenderer } from '@vaadin/grid/lit.js';
import { observeState } from 'lit-element-state';
import { themeState } from 'theme-state';
import {css, html, QwcHotReloadElement} from 'qwc-hot-reload-element';
import {JsonRpc} from 'jsonrpc';
import {columnBodyRenderer, gridRowDetailsRenderer} from '@vaadin/grid/lit.js';
import {observeState} from 'lit-element-state';
import {themeState} from 'theme-state';
import '@quarkus-webcomponents/codeblock';
import '@vaadin/progress-bar';
import '@vaadin/grid';
Expand All @@ -18,7 +17,7 @@ import '@vaadin/button';
/**
* This component shows the Grpc Services
*/
export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
jsonRpc = new JsonRpc(this);
streamsMap = new Map();

Expand Down Expand Up @@ -64,7 +63,7 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
_testerButtons: {state: true}
};

constructor() {
constructor() {
super();
this._detailsOpenedItem = [];
this._streamsMap = new Map();
Expand All @@ -85,13 +84,13 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
}

hotReload(){
this.jsonRpc.getServices().then(jsonRpcResponse => {
this.jsonRpc.getServices().then(jsonRpcResponse => {
this._services = jsonRpcResponse.result;
this._forceUpdate();
});
}

render() {
render() {
if(this._services){
return html`<vaadin-grid .items="${this._services}" class="table" theme="no-border"
.detailsOpenedItems="${this._detailsOpenedItem}"
Expand Down Expand Up @@ -132,12 +131,12 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
${columnBodyRenderer(this._testRenderer, [])}>
</vaadin-grid-column>
</vaadin-grid>`;
</vaadin-grid>`;
}else{
return html`<vaadin-progress-bar class="progress" indeterminate></vaadin-progress-bar>`;
}
}

_statusRenderer(service){
if(service.status === "SERVING"){
return html`<vaadin-icon style="color: var(--lumo-success-text-color);" icon="font-awesome-solid:check"></vaadin-icon>`;
Expand All @@ -147,36 +146,36 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
return html`<vaadin-icon icon="font-awesome-solid:circle-question"></vaadin-icon>`;
}
}

_nameRenderer(service){
return html`<code>${service.name}</code>`;
}

_serviceClassRenderer(service){
return html`<qui-ide-link fileName='${service.serviceClass}'
lineNumber=0><code>${service.serviceClass}</code></qui-ide-link>`;
}

_methodsRenderer(service){
return html`<div class="methods">${service.methods.map(method =>
html`${this._methodRenderer(method)}`
)}</div>`;
}

_methodRenderer(method){
return html`<span><qui-badge level="contrast" pill small><span>${method.type}</span></qui-badge> ${method.bareMethodName}</span>`;
}

_testRenderer(service){
if(service.hasTestableMethod){
return html`<vaadin-icon icon="font-awesome-solid:chevron-down"></vaadin-icon>`;
}
}

_testerRenderer(service){

if(service.methods.length > 1 ){

return html`<vaadin-tabs @selected-changed="${(e) => this._tabSelectedChanged(service, e.detail.value)}">
${service.methods.map(method =>
html`${this._methodTesterTabHeadingRenderer(service.name, method)}`
Expand All @@ -193,21 +192,21 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
`;
}
}

_tabSelectedChanged(service, n){
let method = service.methods[n];
this._testerContent = this._methodTesterRenderer(service, method);
this._testerButtons = this._renderCommandButtons(service, method);
this._forceUpdate();
}

_methodTesterTabHeadingRenderer(serviceName,method) {
return html`<vaadin-tab id="${this._id(serviceName,method)}">
<span>${method.bareMethodName}</span>
<span><qui-badge level="contrast" pill small><span>${method.type}</span></qui-badge><span>
</vaadin-tab>`;
}

_methodTesterRenderer(service, method){
return html`<vaadin-split-layout>
<master-content style="width: 50%;">
Expand All @@ -230,7 +229,7 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
</detail-content>
</vaadin-split-layout>`;
}

_renderCommandButtons(service, method){
if(this._streamsMap.size >=0){
if(method.type == 'UNARY'){
Expand All @@ -244,34 +243,34 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
}
}
}

_keypress(e, service, method){
if(method.type == 'UNARY' || !this._isRunning(service.name, method)){
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){ // ctlr-enter
this._test(service, method);
}
}
}

_isRunning(serviceName, method){
let id = this._id(serviceName, method);
return this._streamsMap.has(id);
}

_id(serviceName, method){
return serviceName + "_" + method.bareMethodName + "_" + method.type;
return serviceName + "_" + method.bareMethodName + "_" + method.type;
}

_clear(serviceName, method){
this._requestTextArea(serviceName, method).clear();
this._responseTextArea(serviceName, method).clear();
}

_default(serviceName, method){
let pv = JSON.parse(method.prototype);
this._requestTextArea(serviceName, method).populatePrettyJson(JSON.stringify(pv));
}

_test(service, method){
let textArea = this._requestTextArea(service.name, method);
let content = textArea.getAttribute('value');
Expand Down Expand Up @@ -306,29 +305,29 @@ export class QwcGrpcServices extends observeState(QwcHotReloadElement) {
this._forceUpdate();
}
}

_forceUpdate(){
if(this._detailsOpenedItem.length > 0){
let itemZero = this._detailsOpenedItem[0];
this._detailsOpenedItem = [];
this._detailsOpenedItem.push(itemZero);
}
}

_requestTextArea(serviceName, method){
return this.shadowRoot.getElementById(this._requestId(serviceName, method));
}

_responseTextArea(serviceName, method){
return this.shadowRoot.getElementById(this._responseId(serviceName, method));
}

_requestId(serviceName, method){
return serviceName + '/' + method.bareMethodName + '_request';
}

_responseId(serviceName, method){
return serviceName + '/' + method.bareMethodName + '_response';
}
}
customElements.define('qwc-grpc-services', QwcGrpcServices);
customElements.define('qwc-grpc-services', QwcGrpcServices);
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package io.quarkus.grpc.protoc.plugin;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import static io.quarkus.vertx.http.runtime.security.QuarkusHttpUser.DEFERRED_IDENTITY_KEY;
import static io.smallrye.common.vertx.VertxContext.isDuplicatedContext;

import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
import java.io.UncheckedIOException;
import java.net.BindException;
import java.time.Duration;
import java.util.*;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand All @@ -22,7 +30,13 @@
import org.jboss.logging.Logger;

import grpc.health.v1.HealthOuterClass;
import io.grpc.*;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.ServerInterceptor;
import io.grpc.ServerInterceptors;
import io.grpc.ServerMethodDefinition;
import io.grpc.ServerServiceDefinition;
import io.grpc.netty.NettyServerBuilder;
import io.quarkus.arc.Arc;
import io.quarkus.arc.InstanceHandle;
Expand All @@ -48,8 +62,13 @@
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.vertx.http.runtime.PortSystemProperties;
import io.quarkus.virtual.threads.VirtualThreadsRecorder;
import io.vertx.core.*;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import io.quarkus.grpc.GrpcTranscodingDescriptor;
import io.quarkus.grpc.MutinyTranscodingService;
import io.quarkus.grpc.auth.GrpcSecurityInterceptor;
import io.quarkus.grpc.runtime.transcoding.*;
import io.quarkus.grpc.runtime.transcoding.GrpcTranscodingBridge;
import io.quarkus.grpc.runtime.transcoding.GrpcTranscodingContainer;
import io.quarkus.grpc.runtime.transcoding.GrpcTranscodingMetadata;
import io.quarkus.grpc.runtime.transcoding.GrpcTranscodingMethod;
import io.quarkus.grpc.runtime.transcoding.GrpcTranscodingServer;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.quarkus.grpc.runtime;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.spi.Prioritized;
Expand Down
Loading

0 comments on commit 44ac07c

Please sign in to comment.