Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help for gRPC sample implementation. #235

Open
mukundv18 opened this issue May 11, 2022 · 1 comment
Open

Need help for gRPC sample implementation. #235

mukundv18 opened this issue May 11, 2022 · 1 comment

Comments

@mukundv18
Copy link

I have written the sample code for authorisation using gRPC service. I was unable to find an easy way to implement the service.

import io.grpc.Server;
import io.grpc.ServerBuilder;

public class AuthServer {

    public static void main(String[] args) throws Exception {
        // Create a new server to listen on port 8081
        Server server = ServerBuilder.forPort(5051)
            .addService(new ExtAuthService())
            .build();

        // Start the server
        server.start();

        // Server threads are running in the background.
        System.out
            .println("+++++++++++++++++++++++ gRPC server started ++++++++++++++++++++++++++++");
        // Don't exit the main thread. Wait until server is terminated.
        server.awaitTermination();
    }
}

The external authorisation service is follows.

import com.google.rpc.Status;
import io.envoyproxy.envoy.service.auth.v3.AuthorizationGrpc;
import io.envoyproxy.envoy.service.auth.v3.CheckRequest;
import io.envoyproxy.envoy.service.auth.v3.CheckResponse;
import io.envoyproxy.envoy.service.auth.v3.OkHttpResponse;
import io.grpc.stub.StreamObserver;

public class ExtAuthService extends AuthorizationGrpc.AuthorizationImplBase {

    @Override
    public void check (CheckRequest request, StreamObserver<CheckResponse> responseObserver) {

        System.out.println("++++++++++hit+++++++++++++++");

        System.out.println(request);

        CheckResponse response = CheckResponse.newBuilder()
            .setStatus(Status.newBuilder().build())
            .setOkResponse(OkHttpResponse.newBuilder().build())
            .build();

        // Use responseObserver to send a single response back
        responseObserver.onNext(response);

        // When you are done, you must call onCompleted.
        responseObserver.onCompleted();
    }
}

Request:

curl -X POST -vs -H "Authorization: Bearer foo" -H 'Content-Type: application/grpc' -H 'Accept: application/grpc' -H 'TE: trailers' -w "\n" --http2-prior-knowledge http://localhost:5051/check

Response:

* Connection state changed (MAX_CONCURRENT_STREAMS == 2147483647)!
< HTTP/2 200 
< content-type: application/grpc
< grpc-status: 12
< grpc-message: Method not found: check

What am I missing?

@mukundv18 mukundv18 changed the title Need help for gRPC implementation. Need help for gRPC sample implementation. May 11, 2022
@liangyuanpeng
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants