当前位置: 首页>>代码示例>>Java>>正文


Java Named类代码示例

本文整理汇总了Java中com.google.api.server.spi.config.Named的典型用法代码示例。如果您正苦于以下问题:Java Named类的具体用法?Java Named怎么用?Java Named使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Named类属于com.google.api.server.spi.config包,在下文中一共展示了Named类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getParameterNames

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
protected static List<String> getParameterNames(EndpointMethod endpointMethod)
    throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
  List<String> parameterNames = endpointMethod.getParameterNames();
  if (parameterNames == null) {
    Method method = endpointMethod.getMethod();
    parameterNames = new ArrayList<>();
    for (int parameter = 0; parameter < method.getParameterTypes().length; parameter++) {
      Annotation annotation = AnnotationUtil.getNamedParameter(method, parameter, Named.class);
      if (annotation == null) {
        parameterNames.add(null);
      } else {
        parameterNames.add((String) annotation.getClass().getMethod("value").invoke(annotation));
      }
    }
    endpointMethod.setParameterNames(parameterNames);
  }
  return parameterNames;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:19,代码来源:ServletRequestParamReader.java

示例2: testCachedNamesAreUsed

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
@Test
public void testCachedNamesAreUsed() throws Exception {
  class Test {
    @SuppressWarnings("unused")
    public void foo(@Named("foo1") String f1, @Named("foo2") String f2,
        @Named("foo3") String f3) {}
  }

  Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
  EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);
  endpointMethod.setParameterNames(ImmutableList.of("name1", "name2", "name3"));

  String requestString = "{\"name1\":\"v1\", \"foo2\":\"v2\", \"name3\":\"v3\"}";

  Object[] params = readParameters(requestString, endpointMethod);

  assertEquals(3, params.length);
  assertEquals("v1", params[0]);
  assertNull(params[1]);
  assertEquals("v3", params[2]);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:22,代码来源:ServletRequestParamReaderTest.java

示例3: testNamesAreCached

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
@Test
public void testNamesAreCached() throws Exception {
  class Test {
    @SuppressWarnings("unused")
    public void foo(@Named("foo1") String f1, @Named("foo2") String f2,
        @Named("foo3") String f3) {}
  }

  Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
  EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);

  readParameters("{}", endpointMethod);
  List<String> parameterNames = endpointMethod.getParameterNames();

  assertEquals(3, parameterNames.size());
  assertEquals("foo1", parameterNames.get(0));
  assertEquals("foo2", parameterNames.get(1));
  assertEquals("foo3", parameterNames.get(2));
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:20,代码来源:ServletRequestParamReaderTest.java

示例4: testSerializedParameter

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
@Test
public void testSerializedParameter() throws Exception {
  @Api
  final class Test {
    @SuppressWarnings("unused")
    public void method(@Named("serialized") TestBean tb) {}
  }

  ApiConfig config = createConfig(Test.class);
  annotationReader.loadEndpointClass(serviceContext, Test.class, config);
  annotationReader.loadEndpointMethods(serviceContext, Test.class,
      config.getApiClassConfig().getMethods());

  ApiMethodConfig methodConfig =
      config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test.class.getMethod(
          "method", TestBean.class)));
  validateMethod(methodConfig, "Test.method", "method/{serialized}", ApiMethod.HttpMethod.POST,
      DEFAULT_SCOPES,
      DEFAULT_AUDIENCES,
      DEFAULT_CLIENTIDS,
      null,
      null);
  validateParameter(methodConfig.getParameterConfigs().get(0), "serialized", false, null,
      TestBean.class, TestSerializer.class, String.class);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:26,代码来源:ApiConfigAnnotationReaderTest.java

示例5: testParameterAnnotations

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
@Test
public void testParameterAnnotations() throws Exception {
  @Api
  class Endpoint {
    @SuppressWarnings("unused")
    public void method(@Named("foo") @Nullable @DefaultValue("4") int foo) {}
  }

  ApiConfig config = createConfig(Endpoint.class);
  annotationReader.loadEndpointClass(serviceContext, Endpoint.class, config);
  annotationReader.loadEndpointMethods(serviceContext, Endpoint.class,
      config.getApiClassConfig().getMethods());

  ApiMethodConfig methodConfig =
      Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
  ApiParameterConfig parameterConfig =
      Iterables.getOnlyElement(methodConfig.getParameterConfigs());
  validateParameter(parameterConfig, "foo", true, "4", int.class, null, int.class);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:20,代码来源:ApiConfigAnnotationReaderTest.java

示例6: testParameterAnnotations_javax

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
@Test
public void testParameterAnnotations_javax() throws Exception {
  @Api
  class Endpoint {
    @SuppressWarnings("unused")
    public void method(@javax.inject.Named("foo") @javax.annotation.Nullable int foo) {}
  }

  ApiConfig config = createConfig(Endpoint.class);
  annotationReader.loadEndpointClass(serviceContext, Endpoint.class, config);
  annotationReader.loadEndpointMethods(serviceContext, Endpoint.class,
      config.getApiClassConfig().getMethods());

  ApiMethodConfig methodConfig =
      Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
  ApiParameterConfig parameterConfig =
      Iterables.getOnlyElement(methodConfig.getParameterConfigs());
  validateParameter(parameterConfig, "foo", true, null, int.class, null, int.class);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:20,代码来源:ApiConfigAnnotationReaderTest.java

示例7: testParamsPath

import com.google.api.server.spi.config.Named; //导入依赖的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;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:27,代码来源:TestEndpoint.java

示例8: testParamsQuery

import com.google.api.server.spi.config.Named; //导入依赖的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;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:26,代码来源:TestEndpoint.java

示例9: getTokens

import com.google.api.server.spi.config.Named; //导入依赖的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);
}
 
开发者ID:mzdu,项目名称:AdSearch_Endpoints,代码行数:27,代码来源:AdSearchEndpoints.java

示例10: echo

import com.google.api.server.spi.config.Named; //导入依赖的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;
}
 
开发者ID:Cryptonomica,项目名称:cryptonomica,代码行数:26,代码来源:UserSearchAndViewAPI.java

示例11: sendTestSms

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
@ApiMethod(
        name = "sendTestSms",
        path = "sendTestSms",
        httpMethod = ApiMethod.HttpMethod.POST
)
@SuppressWarnings("unused")
public StringWrapperObject sendTestSms(
        // final HttpServletRequest httpServletRequest,
        final User googleUser,
        final @Named("phoneNumber") String phoneNumber,
        final @Named("smsMessage") String smsMessage
        // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
) throws UnauthorizedException, BadRequestException, NotFoundException, NumberParseException,
        IllegalArgumentException, TwilioRestException {

    /* --- Check authorization: */
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);

    /* --- Send SMS */
    Message message = TwilioUtils.sendSms(phoneNumber, smsMessage);

    return new StringWrapperObject(message.toJSON());

}
 
开发者ID:Cryptonomica,项目名称:cryptonomica,代码行数:25,代码来源:OnlineVerificationAPI.java

示例12: addWaitlistedSession

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
/**
 * Add a waitlisted session for the specified user. If the session is already in the user's feed,
 * it will be annotated with status=WAITLISTED.
 *
 * @param user         Service account making the request (injected by Endpoints)
 * @param userId       User ID of user that reserved a session.
 * @param sessionId    Session ID to mark as reserved.
 * @param timestampUTC The time (in millis, UTC) when the user performed this action. May be
 *                     different than the time this method is called if offline sync is
 *                     implemented. MUST BE ACCURATE - COMPENSATE FOR CLOCK DRIFT!
 * @return The list of reserved sessions for the user
 */
@ApiMethod(name = "addWaitlistedSession", path = "reservations/waitlist",
    httpMethod = ApiMethod.HttpMethod.PUT, clientIds = {Ids.SERVICE_ACCOUNT_CLIENT_ID})
public Map<String, ReservedSession> addWaitlistedSession (
    User user,
    @Named("userId") String userId,
    @Named("sessionId") String sessionId,
    @Named("timestampUTC") long timestampUTC)
    throws UnauthorizedException {
    UserData data = getUser(user, userId);
    ReservedSession s = new ReservedSession(sessionId, Status.WAITLISTED, timestampUTC);
    data.reservedSessions.put(sessionId, s);
    save(data);
    // notify user's clients of reservation change change
    new GCMPing().notifyUserSync(data.userId);
    return data.reservedSessions;
}
 
开发者ID:google,项目名称:iosched,代码行数:29,代码来源:UserdataEndpoint.java

示例13: addReservedSession

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
/**
 * Add a reserved session for the specified user. If the session is already in the user's feed,
 * it will be annotated with status=RESERVED.
 *
 * @param user         Service account making the request (injected by Endpoints)
 * @param userId       User ID of user that reserved a session.
 * @param sessionId    Session ID to mark as reserved.
 * @param timestampUTC The time (in millis, UTC) when the user performed this action. May be
 *                     different than the time this method is called if offline sync is
 *                     implemented. MUST BE ACCURATE - COMPENSATE FOR CLOCK DRIFT!
 * @return The list of reserved sessions for the user
 */
@ApiMethod(name = "addReservedSession", path = "reservations",
    httpMethod = ApiMethod.HttpMethod.PUT, clientIds = {Ids.SERVICE_ACCOUNT_CLIENT_ID})
public Map<String, ReservedSession> addReservedSession(
        User user,
        @Named("userId") String userId,
        @Named("sessionId") String sessionId,
        @Named("timestampUTC") long timestampUTC)
        throws UnauthorizedException {
    UserData data = getUser(user, userId);
    ReservedSession s = new ReservedSession(sessionId, Status.RESERVED, timestampUTC);
    data.reservedSessions.put(sessionId, s);
    save(data);
    // notify user's clients of reservation change change
    new GCMPing().notifyUserSync(data.userId);
    return data.reservedSessions;
}
 
开发者ID:google,项目名称:iosched,代码行数:29,代码来源:UserdataEndpoint.java

示例14: register

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
/**
 * Register a user's device. Each client instance has a token that identifies it, there is usually
 * one instance per device so in most cases the token represents a device. The token is stored
 * against the user's ID to allow messages to be sent to all the user's devices.
 *
 * @param user Current user (injected by Endpoints)
 * @param deviceId FCM token representing the device.
 * @throws BadRequestException Thrown when there is no device ID in the request.
 */
@ApiMethod(path = "register", httpMethod = HttpMethod.POST)
public void register(User user, @Named(PARAMETER_DEVICE_ID) String deviceId)
    throws BadRequestException {

  // Check to see if deviceId.
  if (Strings.isNullOrEmpty(deviceId)) {
    // Drop request.
    throw new BadRequestException("Invalid request: Request must contain " +
        PARAMETER_DEVICE_ID);
  }

  // Check that user making requests is non null.
  if (user != null && !Strings.isNullOrEmpty(user.getId())) {
    DeviceStore.register(deviceId, user.getId());
  } else {
    // If user is null still register device so it can still get session update ping.
    DeviceStore.register(deviceId, null);
  }
}
 
开发者ID:google,项目名称:iosched,代码行数:29,代码来源:FcmRegistrationEndpoint.java

示例15: getVendorEventRelationship

import com.google.api.server.spi.config.Named; //导入依赖的package包/类
/**
 * This method gets the entity having primary key id. It uses HTTP GET
 * method.
 * 
 * @param id
 *            the primary key of the java bean.
 * @return The entity with primary key id.
 * @throws OAuthRequestException
 */

@ApiMethod(name = "getVendorEventRelationship", path = "getVendorEventRelationship")
public VendorEventRelationship getVendorEventRelationship(@Named("id") Long id,
		@Named("idToken") String tokenString) throws UnauthorizedException {

	// Fetch Authorized Zeppa User
	ZeppaUser user = ClientEndpointUtility.getAuthorizedZeppaUser(tokenString);
	if (user == null) {
		throw new UnauthorizedException("No matching user found for this token");
	}

	PersistenceManager mgr = getPersistenceManager();
	VendorEventRelationship vendorEventRelationship = null;
	try {
		vendorEventRelationship = mgr.getObjectById(VendorEventRelationship.class, id);

	} finally {
		mgr.close();
	}
	return vendorEventRelationship;
}
 
开发者ID:pschuette22,项目名称:Zeppa-AppEngine,代码行数:31,代码来源:VendorEventRelationshipEndpoint.java


注:本文中的com.google.api.server.spi.config.Named类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。