Java源码示例:com.google.api.server.spi.config.Nullable
示例1
@Test
public void testJavaxNamed() throws Exception {
class Test {
@SuppressWarnings("unused")
public void foo(
@javax.inject.Named("str") String str,
@Nullable @javax.inject.Named("i") Integer i) {}
}
String requestString = "{\"str\":\"hello\"}";
Method method = Test.class.getDeclaredMethod("foo", String.class, Integer.class);
Object[] params = readParameters(requestString, method);
assertEquals(2, params.length);
assertEquals("hello", params[0]);
assertNull(params[1]);
}
示例2
@Test
public void testCachedNamesAreUsed() throws Exception {
class Test {
@SuppressWarnings("unused")
public void foo(@Named("foo1") String f1, @Nullable @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]);
}
示例3
@Test
public void testNamesAreCached() throws Exception {
class Test {
@SuppressWarnings("unused")
public void foo(
@Nullable @Named("foo1") String f1,
@Nullable @Named("foo2") String f2,
@Nullable @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));
}
示例4
@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);
}
示例5
@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);
}
示例6
@ApiMethod(
name = "foos.execute0",
path = "execute0",
httpMethod = "POST"
)
public Object execute0(@Named("id") String id, @Named("i0") int i0,
@Named("i1") @Nullable Integer i1, @Named("long0") long long0,
@Nullable @Named("long1") Long long1, @Named("b0") boolean b0,
@Nullable @Named("b1") Boolean b1, @Named("f") float f,
@Nullable @Named("d") Double d) {
return null;
}
示例7
@ApiMethod(name = "param", path = "param/{parent}/{child}")
public void param(
@Named("parent") String parent,
@Named("query") @Nullable String query,
@Named("child") String child,
@Named("queryb") String queryB,
@Named("querya") String queryA) { }
示例8
@ApiMethod(
name = "testFormData",
httpMethod = HttpMethod.POST,
path = "testFormData")
public void testFormData(
@Nullable @Named("foo") String foo,
@Nullable @Named("bar") Integer bar) {
}
示例9
/**
* Returns the {@link com.google.appengine.tck.site.endpoints.TestReport} with the given build type id ordered by
* build id in the descendant order.
*
* @param buildTypeId the build type id.
* @param limit the optional fetch limit, by default {@link com.google.appengine.tck.site.endpoints.TestReport#DEFAULT_FETCH_LIMIT}.
* @return the matching test reports list or an empty one if none.
*/
@ApiMethod(
name = "tests.list",
path = "{buildTypeId}/tests",
httpMethod = GET
)
public List<TestReport> listTestReports(@Named("buildTypeId") String buildTypeId, @Nullable @Named("limit") Integer limit) {
return TestReport.findByBuildTypeIdOrderByBuildIdDesc(buildTypeId, Optional.fromNullable(limit), this);
}
示例10
@ApiMethod(name = "foo.list", description = "list desc", path = "foos",
httpMethod = HttpMethod.GET)
public CollectionResponse<FooDescription> listFoos(@Named("n") Integer n, @Nullable @Named("enum") @Description("enum desc") TestEnumDescription testEnum) {
return null;
}
示例11
private boolean isRequiredParameter(EndpointMethod method, int i) {
return AnnotationUtil.getNullableParameter(method.getMethod(), i, Nullable.class) == null
|| method.getParameterTypes()[i].isPrimitive();
}
示例12
private List<Class<? extends Transformer<?, ?>>> tryFindDefaultSerializers(
@Nullable TypeToken<?> type) {
ApiSerializationConfig serializerConfig =
apiMethodConfig.getApiClassConfig().getApiConfig().getSerializationConfig();
return Serializers.getSerializerClasses(type, serializerConfig);
}
示例13
/**
* Endpoint to post the content in users Google+ according the feature
* performed by front-end
*
* @param feature
* is the feature performed by front-end
* @param score
* is the positive or negative recommendation in case of
* recommendation feature
* @param currentUserMail
* is the email of the user logged in.
* @param endorsedMail
* is the email of the endorsed user in case of endorse feature.
* @param technologyName
* is the name of technology performed by feature.
* @param appLink
* is the link to the page that made a endpoint call.
* @param comment
* is the comment in case of comment feature.
* @param user
* is the user logged in
* @param req
* is the current http servlet request
* @throws InternalServerErrorException
* @throws BadRequestException
* @throws NotFoundException
* @throws IOException
*/
@ApiMethod(name = "postComment", path = "googleplus/post", httpMethod = "post")
public void postGooglePlus(@Named("feature") FeatureEnum feature, @Named("score") @Nullable Boolean score,
@Named("comment") @Nullable String comment, @Named("currentUserMail") String currentUserMail,
@Named("endorsedMail") @Nullable String endorsedMail, @Named("technologyName") String technologyName,
@Named("appLink") String appLink, User user, HttpServletRequest req)
throws InternalServerErrorException, BadRequestException, NotFoundException, IOException {
String header = req.getHeader("Authorization");
String accesstoken = header.substring(header.indexOf(' ')).trim();
service.postInUserProfile(feature, score, comment, currentUserMail, endorsedMail, technologyName, appLink, user,
accesstoken);
}
示例14
/**
* Endpointfor gettint a technology by filters
*
* @param user User
* @param titleContains technology title part.
* @param shortDescriptionContains technology short description part.
* @param recommendationIs technology Ci&T recomendation
* @param orderOptionIs sort type for the list of technologies
* @return list of technologies
* @throws ServiceException in case of exception in service
*/
@ApiMethod(name = "findByFilter", path = "technology/search", httpMethod = "get")
public Response findTechnologyByFilter(User user,
@Named("titleContains") @Nullable String titleContains,
@Named("shortDescriptionContains") @Nullable String shortDescriptionContains,
@Named("recommendationIs") @Nullable String recommendationIs,
@Named("dateFilter") @Nullable Integer dateFilter,
@Named("orderOptionIs") @Nullable String orderOptionIs) throws ServiceException {
return service.findTechnologiesByFilter(new TechnologyFilter(titleContains,
shortDescriptionContains, recommendationIs, dateFilter, orderOptionIs), user);
}
示例15
/**
* Echoes the received message back. If n is a non-negative integer, the message is copied that
* many times in the returned message.
*
* Note that name is specified and will override the default name of "{class name}.{method
* name}". For example, the default is "echo.echo".
*
* Note that httpMethod is not specified. This will default to a reasonable HTTP method
* depending on the API method name. In this case, the HTTP method will default to POST.
*/
@ApiMethod(name = "echo")
public Message echo(Message message, @Named("n") @Nullable Integer n) {
return doEcho(message, n);
}
示例16
/**
* Echoes the received message back. If n is a non-negative integer, the message is copied that
* many times in the returned message.
*
* Note that name is specified and will override the default name of "{class name}.{method
* name}". For example, the default is "echo.echo".
*
* Note that httpMethod is not specified. This will default to a reasonable HTTP method
* depending on the API method name. In this case, the HTTP method will default to POST.
*/
@ApiMethod(name = "echo_api_key", path = "echo_api_key", apiKeyRequired = AnnotationBoolean.TRUE)
public Message echoApiKey(Message message, @Named("n") @Nullable Integer n) {
return doEcho(message, n);
}
示例17
/**
* Echoes the received message back. If n is a non-negative integer, the message is copied that
* many times in the returned message.
*
* <p>Note that name is specified and will override the default name of "{class name}.{method
* name}". For example, the default is "echo.echo".
*
* <p>Note that httpMethod is not specified. This will default to a reasonable HTTP method
* depending on the API method name. In this case, the HTTP method will default to POST.
*/
// [START echo_method]
@ApiMethod(name = "echo")
public Message echo(Message message, @Named("n") @Nullable Integer n) {
return doEcho(message, n);
}
示例18
/**
* Echoes the received message back. If n is a non-negative integer, the message is copied that
* many times in the returned message.
*
* <p>Note that name is specified and will override the default name of "{class name}.{method
* name}". For example, the default is "echo.echo".
*
* <p>Note that httpMethod is not specified. This will default to a reasonable HTTP method
* depending on the API method name. In this case, the HTTP method will default to POST.
*/
// [START echo_api_key]
@ApiMethod(name = "echo_api_key", path = "echo_api_key", apiKeyRequired = AnnotationBoolean.TRUE)
public Message echoApiKey(Message message, @Named("n") @Nullable Integer n) {
return doEcho(message, n);
}