com.google.api.server.spi.config.Nullable Java Examples

The following examples show how to use com.google.api.server.spi.config.Nullable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiConfigAnnotationReaderTest.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: ApiConfigAnnotationReaderTest.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: ServletRequestParamReaderTest.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #4
Source File: ServletRequestParamReaderTest.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
@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]);
}
 
Example #5
Source File: ServletRequestParamReaderTest.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
@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]);
}
 
Example #6
Source File: Reports.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: RestServletRequestParamReaderTest.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@ApiMethod(
    name = "testFormData",
    httpMethod = HttpMethod.POST,
    path = "testFormData")
public void testFormData(
    @Nullable @Named("foo") String foo,
    @Nullable @Named("bar") Integer bar) {
}
 
Example #8
Source File: MultipleParameterEndpoint.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@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) { }
 
Example #9
Source File: Endpoint1.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: ApiParameterConfig.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
private List<Class<? extends Transformer<?, ?>>> tryFindDefaultSerializers(
    @Nullable TypeToken<?> type) {
  ApiSerializationConfig serializerConfig =
      apiMethodConfig.getApiClassConfig().getApiConfig().getSerializationConfig();
  return Serializers.getSerializerClasses(type, serializerConfig);
}
 
Example #11
Source File: ServletRequestParamReader.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
private boolean isRequiredParameter(EndpointMethod method, int i) {
  return AnnotationUtil.getNullableParameter(method.getMethod(), i, Nullable.class) == null
      || method.getParameterTypes()[i].isPrimitive();
}
 
Example #12
Source File: FooDescriptionEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example #13
Source File: SocialNetworkCommunicationEndpoint.java    From tech-gallery with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example #14
Source File: TechnologyEndpoint.java    From tech-gallery with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example #15
Source File: Echo.java    From java-docs-samples with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example #16
Source File: Echo.java    From java-docs-samples with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source File: Echo.java    From java-docs-samples with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: Echo.java    From java-docs-samples with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}