-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Furer
committed
Oct 27, 2021
1 parent
8f6bca6
commit ded2743
Showing
35 changed files
with
958 additions
and
255 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
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
101 changes: 101 additions & 0 deletions
101
...ring-boot-starter-demo/src/main/java/org/lognet/springboot/grpc/demo/GrpcTaskService.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,101 @@ | ||
package org.lognet.springboot.grpc.demo; | ||
|
||
import io.grpc.examples.tasks.Assignment; | ||
import io.grpc.examples.tasks.Person; | ||
import io.grpc.examples.tasks.TaskServiceGrpc; | ||
import io.grpc.stub.StreamObserver; | ||
import org.lognet.springboot.grpc.GRpcService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.prepost.PostAuthorize; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
|
||
import java.util.Optional; | ||
|
||
@GRpcService | ||
public class GrpcTaskService extends TaskServiceGrpc.TaskServiceImplBase { | ||
|
||
|
||
private ITaskService service; | ||
|
||
@Autowired | ||
public void setService(Optional<ITaskService> service) { | ||
this.service = service.orElse(new ITaskService() { | ||
@Override | ||
public Assignment findAssignment(Person person) { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
@PreAuthorize("hasAuthority('1') && #person.age<12") | ||
@PostAuthorize("returnObject.description.length()>0") | ||
public void findAssignmentUnary(Person person, StreamObserver<Assignment> responseObserver) { | ||
final Assignment assignment = service.findAssignment(person); | ||
responseObserver.onNext(assignment); | ||
responseObserver.onCompleted(); | ||
|
||
} | ||
|
||
@Override | ||
@PreAuthorize("#p0.age<12") | ||
@PostAuthorize("returnObject.description.length()>0") | ||
public StreamObserver<Person> findAssignmentsBidiStream(StreamObserver<Assignment> responseObserver) { | ||
return new StreamObserver<Person>() { | ||
@Override | ||
public void onNext(Person person) { | ||
final Assignment assignment = service.findAssignment(person); | ||
responseObserver.onNext(assignment); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
|
||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
responseObserver.onCompleted(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
@PreAuthorize("#person.age<12") | ||
@PostAuthorize("returnObject.description.length()>0") | ||
public void findAssignmentOutStream(Person person, StreamObserver<Assignment> responseObserver) { | ||
responseObserver.onNext(service.findAssignment(person)); | ||
responseObserver.onNext(service.findAssignment(person)); | ||
responseObserver.onCompleted(); | ||
} | ||
|
||
@Override | ||
@PreAuthorize("#p0.getAge()<12") | ||
@PostAuthorize("returnObject.description.length()>0") | ||
public StreamObserver<Person> findAssignmentInStream(StreamObserver<Assignment> responseObserver) { | ||
return new StreamObserver<Person>() { | ||
private final StringBuilder assignment = new StringBuilder(); | ||
|
||
@Override | ||
public void onNext(Person person) { | ||
if(0!=assignment.length()){ | ||
assignment.append(System.lineSeparator()); | ||
} | ||
assignment.append(service.findAssignment(person).getDescription()); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
|
||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
responseObserver.onNext(Assignment.newBuilder() | ||
.setDescription(assignment.toString()) | ||
.build()); | ||
responseObserver.onCompleted(); | ||
} | ||
}; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...-spring-boot-starter-demo/src/main/java/org/lognet/springboot/grpc/demo/ITaskService.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,9 @@ | ||
package org.lognet.springboot.grpc.demo; | ||
|
||
|
||
import io.grpc.examples.tasks.Assignment; | ||
import io.grpc.examples.tasks.Person; | ||
|
||
public interface ITaskService { | ||
Assignment findAssignment(Person person); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2015 The gRPC Authors | ||
// | ||
// 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. | ||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "io.grpc.examples.tasks"; | ||
|
||
|
||
|
||
package task; | ||
|
||
service TaskService { | ||
|
||
rpc FindAssignmentUnary(Person) returns ( Assignment) {} | ||
|
||
rpc FindAssignmentsBidiStream(stream Person) returns (stream Assignment) {} | ||
|
||
rpc FindAssignmentOutStream( Person) returns (stream Assignment) {} | ||
|
||
rpc FindAssignmentInStream(stream Person) returns ( Assignment) {} | ||
|
||
|
||
} | ||
|
||
|
||
message Person { | ||
string name = 1; | ||
int32 age = 2; | ||
} | ||
|
||
message Assignment { | ||
string description = 1; | ||
} |
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
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
Oops, something went wrong.