本文整理汇总了Java中com.google.api.server.spi.config.ApiMethod类的典型用法代码示例。如果您正苦于以下问题:Java ApiMethod类的具体用法?Java ApiMethod怎么用?Java ApiMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApiMethod类属于com.google.api.server.spi.config包,在下文中一共展示了ApiMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: list
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "user",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<User> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<User> query = ofy().load().type(User.class).limit(limit);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<User> queryIterator = query.iterator();
List<User> userList = new ArrayList<User>(limit);
while (queryIterator.hasNext()) {
userList.add(queryIterator.next());
}
return CollectionResponse.<User>builder().setItems(userList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例2: list
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "joke",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Joke> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
Integer limitParam = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<Joke> query = ofy().load().type(Joke.class).limit(limitParam);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<Joke> queryIterator = query.iterator();
List<Joke> jokeList = new ArrayList<>(limitParam);
while (queryIterator.hasNext()) {
jokeList.add(queryIterator.next());
}
return CollectionResponse.<Joke>builder().setItems(jokeList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例3: get
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* Responds with the {@link WaxDataItem} resource requested.
*
* @throws NotFoundException if the session doesn't exist or has no {@link WaxDataItem} with the
* requested id
*/
@ApiMethod(
name = "items.get",
path = "sessions/{sessionId}/items/{itemId}")
public WaxDataItem get(@Named("sessionId") String sessionId, @Named("itemId") String itemId)
throws NotFoundException {
try {
WaxDataItem item = store.get(sessionId, itemId);
if (item != null) {
return item;
}
throw new NotFoundException("Invalid itemId: " + itemId);
} catch (InvalidSessionException e) {
throw new NotFoundException(e.getMessage());
}
}
示例4: getUserEmailFirebase
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* Gets the authenticated user's email. If the user is not authenticated, this will return an HTTP
* 401.
* <p>
* Note that name is not specified. This will default to "{class name}.{method name}". For
* example, the default is "echo.getUserEmail".
* <p>
* Note that httpMethod is not required here. Without httpMethod, this will default to GET due
* to the API method name. httpMethod is added here for example purposes.
*/
// [START firebase_auth]
@ApiMethod(
path = "firebase_user",
httpMethod = ApiMethod.HttpMethod.GET,
authenticators = {EspAuthenticator.class},
issuerAudiences = {
@ApiIssuerAudience(
name = "firebase",
// audiences = {"YOUR-PROJECT-ID"}
audiences = {"cryptonomica-server"}
)
}
)
public Email getUserEmailFirebase(User user) throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Invalid credentials");
}
Email response = new Email();
response.setEmail(user.getEmail());
return response;
}
示例5: list
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "users",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Users> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<Users> query = ofy().load().type(Users.class).limit(limit);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<Users> queryIterator = query.iterator();
List<Users> usersList = new ArrayList<Users>(limit);
while (queryIterator.hasNext()) {
usersList.add(queryIterator.next());
}
return CollectionResponse.<Users>builder().setItems(usersList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例6: echo
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
@ApiMethod(
name = "echo",
path = "echo",
httpMethod = ApiMethod.HttpMethod.GET)
/* >>>>>>>>>>>>>> this is for testing only
* curl -H "Content-Type: application/json" -X GET -d '{"message":"hello world"}' https://cryptonomica-server.appspot.com/_ah/api/userSearchAndViewAPI/v1/echo
* */
public StringWrapperObject echo(
@Named("message") String message,
@Named("n") @Nullable Integer n
) {
StringWrapperObject stringWrapperObject = new StringWrapperObject();
if (n != null && n >= 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i > 0) {
sb.append(" ");
}
sb.append(message);
}
stringWrapperObject.setMessage(sb.toString());
}
return stringWrapperObject;
}
示例7: insert
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* Inserts a new {@code Users}.
*/
@ApiMethod(
name = "insert",
path = "users",
httpMethod = ApiMethod.HttpMethod.POST)
public Users insert(Users users) {
// Typically in a RESTful API a POST does not have a known ID (assuming the ID is used in the resource path).
// You should validate that users.id has not been set. If the ID type is not supported by the
// Objectify ID generator, e.g. long or String, then you should generate the unique ID yourself prior to saving.
//
// If your client provides the ID then you should probably use PUT instead.
ofy().save().entity(users).now();
logger.info("Created Users with ID: " + users.getId());
return ofy().load().entity(users).now();
}
示例8: testParamsPath
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
@ApiMethod(httpMethod = HttpMethod.GET, path = "testparamspath/{anint}/{along}/{afloat}/{adouble}"
+ "/{aboolean}/{astring}/{asimpledate}/{adateandtime}/{adate}/{anenum}")
public FieldContainer testParamsPath(
@Named("anint") int anInt,
@Named("along") long aLong,
@Named("afloat") float aFloat,
@Named("adouble") double aDouble,
@Named("aboolean") boolean aBoolean,
@Named("astring") String aString,
@Named("asimpledate") SimpleDate aSimpleDate,
@Named("adateandtime") DateAndTime aDateAndTime,
@Named("adate") Date aDate,
@Named("anenum") TestEnum anEnum) {
FieldContainer ret = new FieldContainer();
ret.anInt = anInt;
ret.aLong = aLong;
ret.aFloat = aFloat;
ret.aDouble = aDouble;
ret.aBoolean = aBoolean;
ret.aString = aString;
ret.aSimpleDate = aSimpleDate;
ret.aDateAndTime = aDateAndTime;
ret.aDate = aDate;
ret.anEnum = anEnum;
return ret;
}
示例9: createSession
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* Creates a new session from {@link WaxNewSessionRequest}.
*
* @return {@link WaxNewSessionResponse} with the created session id
* @throws InternalServerErrorException if the session creation failed
* @throws BadRequestException if the requested session name is bad
*/
@ApiMethod(
name = "sessions.create",
path = "newsession",
httpMethod = HttpMethod.POST)
public WaxNewSessionResponse createSession(WaxNewSessionRequest request)
throws InternalServerErrorException, BadRequestException {
if (Strings.isNullOrEmpty(request.getSessionName())) {
throw new BadRequestException("Name must be non-empty");
}
String sessionId =
store.createSession(request.getSessionName(), request.getDurationInMillis());
if (sessionId != null) {
return new WaxNewSessionResponse(sessionId);
}
throw new InternalServerErrorException("Error while adding session");
}
示例10: testMethodPaths_apiAndMethodsAtCustomPaths
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
@Test
public void testMethodPaths_apiAndMethodsAtCustomPaths() throws Exception {
@Api(resource = "foo")
class AcmeCo {
@ApiMethod(path = "foos")
public List<Foo> list() { return null; }
@SuppressWarnings("unused")
public List<Foo> listAllTheThings() { return null; }
@ApiMethod(path = "give")
public Foo giveMeOne() { return null; }
}
String apiConfigSource = g.generateConfig(AcmeCo.class).get("myapi-v1.api");
ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
verifyMethodPathAndHttpMethod(root, "myapi.foo.list", "foos", "GET");
verifyMethodPathAndHttpMethod(root, "myapi.foo.listAllTheThings", "foo", "GET");
verifyMethodPathAndHttpMethod(root, "myapi.foo.giveMeOne", "give", "POST");
}
示例11: list
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "orders",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Orders> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<Orders> query = ofy().load().type(Orders.class).limit(limit);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<Orders> queryIterator = query.iterator();
List<Orders> ordersList = new ArrayList<Orders>(limit);
while (queryIterator.hasNext()) {
ordersList.add(queryIterator.next());
}
return CollectionResponse.<Orders>builder().setItems(ordersList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例12: testNonuniqueRestSignatures_multiClass
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
@Test
public void testNonuniqueRestSignatures_multiClass() throws Exception {
@Api
class Foo {
@ApiMethod(path = "path")
public void foo() {}
}
ApiConfig config1 = configLoader.loadConfiguration(ServiceContext.create(), Foo.class);
@Api
class Bar {
@ApiMethod(path = "path")
public void bar() {}
}
ApiConfig config2 = configLoader.loadConfiguration(ServiceContext.create(), Bar.class);
try {
validator.validate(Lists.newArrayList(config1, config2));
fail();
} catch (DuplicateRestPathException expected) {
}
}
示例13: testApiMethodConfigWithApiMethodNameContainingSpecialCharacter
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
@Test
public void testApiMethodConfigWithApiMethodNameContainingSpecialCharacter() throws Exception {
@Api(name = "testApi", version = "v1", resource = "bar")
final class Test {
@ApiMethod(name = "Api.Test#Method")
public void test() {
}
}
ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), Test.class);
try {
validator.validate(config);
fail("Expected InvalidMethodNameException.");
} catch (InvalidMethodNameException expected) {
}
}
示例14: testParamsQuery
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
@ApiMethod(httpMethod = HttpMethod.GET, path = "testparamsquery")
public FieldContainer testParamsQuery(
@Named("anint") Integer anInt,
@Named("along") Long aLong,
@Named("afloat") Float aFloat,
@Named("adouble") Double aDouble,
@Named("aboolean") Boolean aBoolean,
@Named("astring") String aString,
@Named("asimpledate") SimpleDate aSimpleDate,
@Named("adateandtime") DateAndTime aDateAndTime,
@Named("adate") Date aDate,
@Named("anenum") TestEnum anEnum) {
FieldContainer ret = new FieldContainer();
ret.anInt = anInt;
ret.aLong = aLong;
ret.aFloat = aFloat;
ret.aDouble = aDouble;
ret.aBoolean = aBoolean;
ret.aString = aString;
ret.aSimpleDate = aSimpleDate;
ret.aDateAndTime = aDateAndTime;
ret.aDate = aDate;
ret.anEnum = anEnum;
return ret;
}
示例15: getTokens
import com.google.api.server.spi.config.ApiMethod; //导入依赖的package包/类
@ApiMethod(name = "getTokens", path = "getTokens",
httpMethod = HttpMethod.GET)
public List<String> getTokens(@Named("name") String queryString) {
// add Ads data
AdsData ads1 = new AdsData((long) 1231, (long) 66, "basketball kobe shoe nike", 0.37f, 6.0f);
ofy().save().entity(ads1).now();
AdsData ads2 = new AdsData((long) 1232, (long) 66, "soccer shoe nike", 0.23f, 4.0f);
ofy().save().entity(ads2).now();
AdsData ads3 = new AdsData((long) 1233, (long) 67, "running shoe adidas", 0.53f, 7.5f);
ofy().save().entity(ads3).now();
AdsData ads4 = new AdsData((long) 1234, (long) 67, "soccer shoe adidas", 0.19f, 3.5f);
ofy().save().entity(ads4).now();
AdsData ads5 = new AdsData((long) 1235, (long) 67, "basketball shoe adidas", 0.29f, 5.5f);
ofy().save().entity(ads5).now();
// add Campaign data
CampaignData cmp1 = new CampaignData((long) 66, 1500f);
ofy().save().entity(cmp1).now();
CampaignData cmp2 = new CampaignData((long) 67, 2800f);
ofy().save().entity(cmp2).now();
CampaignData cmp3 = new CampaignData((long) 68, 900f);
ofy().save().entity(cmp3).now();
return QUERY_PARSER.parseQuery(queryString);
}