-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make AnnotatedService public (#5628)
Motivation: - Related issue: #5382 - It'd be nice if a user can access the information provided by `AnnotatredService`, but it is not part of the public API. ### Modifications: - Split `AnnotatedService` into `AnnotatedService` (interface) and `DefaultAnnotatedService` (implementation). ### Result: - Closes #5382 Before: ```java ServiceRequestContext serviceRequestContext = ServiceRequestContext.current(); AnnotatedService service = serviceRequestContext.config().service().as(AnnotatedService.class); // This doesn't compile. // service.method(); // service.defaultStatus(); ``` After: ```java ServiceRequestContext serviceRequestContext = ServiceRequestContext.current(); AnnotatedService service = serviceRequestContext.config().service().as(AnnotatedService.class); // This compiles and provides useful properties. service.method(); service.defaultStatus(); ``` --------- Co-authored-by: Ikhun Um <ih.pert@gmail.com> Co-authored-by: Trustin Lee <t@motd.kr> Co-authored-by: jrhee17 <guins_j@guins.org> Co-authored-by: minux <songmw725@gmail.com>
- Loading branch information
1 parent
7cc27f5
commit 7d562ce
Showing
13 changed files
with
144 additions
and
49 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
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
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
77 changes: 77 additions & 0 deletions
77
core/src/main/java/com/linecorp/armeria/server/annotation/AnnotatedService.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,77 @@ | ||
/* | ||
* Copyright 2017 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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: | ||
* | ||
* https://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 com.linecorp.armeria.server.annotation; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.armeria.common.annotation.Nullable; | ||
import com.linecorp.armeria.server.HttpService; | ||
import com.linecorp.armeria.server.Route; | ||
import com.linecorp.armeria.server.ServerBuilder; | ||
|
||
/** | ||
* An {@link HttpService} which is defined by a {@link Path} or HTTP method annotations. | ||
* This class is designed to provide a common interface and expose as public for Annotated HTTP Service. | ||
* Please check out the documentation at | ||
* <a href="https://armeria.dev/docs/server-annotated-service">Annotated HTTP Service</a> to use this. | ||
*/ | ||
@Nullable | ||
public interface AnnotatedService extends HttpService { | ||
|
||
/** | ||
* Returns the name of this annotated service specified with {@link ServiceName}. | ||
*/ | ||
@Nullable | ||
String name(); | ||
|
||
/** | ||
* Returns the annotated service object specified with {@link ServerBuilder#annotatedService(Object)}. | ||
*/ | ||
Object serviceObject(); | ||
|
||
/** | ||
* Returns the {@link Class} of the annotated service object specified | ||
* with {@link ServerBuilder#annotatedService(Object)}. | ||
*/ | ||
Class<?> serviceClass(); | ||
|
||
/** | ||
* Returns the target {@link Method} invoked when a request is received. | ||
*/ | ||
Method method(); | ||
|
||
/** | ||
* Returns the name of the target method invoked when a request is received. | ||
*/ | ||
default String methodName() { | ||
return method().getName(); | ||
} | ||
|
||
/** | ||
* Returns the {@link Route} for this {@link AnnotatedService}. | ||
*/ | ||
Route route(); | ||
|
||
/** | ||
* Returns the default {@link HttpStatus} specified with {@link StatusCode}. | ||
* If {@link StatusCode} is not given, {@link HttpStatus#OK} is returned by default. | ||
* If the method returns a void type such as {@link Void} or Kotlin Unit, {@link HttpStatus#NO_CONTENT} is | ||
* returned. | ||
*/ | ||
HttpStatus defaultStatus(); | ||
} |
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