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


Java GenericUrl类代码示例

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


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

示例1: deleteInstanceId

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
private Task<Void> deleteInstanceId(final String instanceId) {
  checkArgument(!Strings.isNullOrEmpty(instanceId), "instance ID must not be null or empty");
  return ImplFirebaseTrampolines.submitCallable(app, new Callable<Void>(){
    @Override
    public Void call() throws Exception {
      String url = String.format(
          "%s/project/%s/instanceId/%s", IID_SERVICE_URL, projectId, instanceId);
      HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(url));
      request.setParser(new JsonObjectParser(jsonFactory));
      request.setResponseInterceptor(interceptor);
      HttpResponse response = null;
      try {
        response = request.execute();
        ByteStreams.exhaust(response.getContent());
      } catch (Exception e) {
        handleError(instanceId, e);
      } finally {
        if (response != null) {
          response.disconnect();
        }
      }
      return null;
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:FirebaseInstanceId.java

示例2: signInWithCustomToken

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
private String signInWithCustomToken(String customToken) throws IOException {
  GenericUrl url = new GenericUrl(ID_TOOLKIT_URL + "?key="
      + IntegrationTestUtils.getApiKey());
  Map<String, Object> content = ImmutableMap.<String, Object>of(
      "token", customToken, "returnSecureToken", true);
  HttpRequest request = transport.createRequestFactory().buildPostRequest(url,
      new JsonHttpContent(jsonFactory, content));
  request.setParser(new JsonObjectParser(jsonFactory));
  HttpResponse response = request.execute();
  try {
    GenericJson json = response.parseAs(GenericJson.class);
    return json.get("idToken").toString();
  } finally {
    response.disconnect();
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:FirebaseAuthIT.java

示例3: getPublicKeysJson

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
/**
 *
 * @return
 * @throws IOException
 */
private JsonObject getPublicKeysJson() throws IOException {
    // get public keys
    URI uri = URI.create(pubKeyUrl);
    GenericUrl url = new GenericUrl(uri);
    HttpTransport http = new NetHttpTransport();
    HttpResponse response = http.createRequestFactory().buildGetRequest(url).execute();

    // store json from request
    String json = response.parseAsString();
    // disconnect
    response.disconnect();

    // parse json to object
    JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();

    return jsonObject;
}
 
开发者ID:rvep,项目名称:dev_backend,代码行数:23,代码来源:FirebaseAuthVerifier.java

示例4: createThumbnail

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
/**
 * Richiede ad Alfresco la creazione di una <i>thumbnail</i>.
 * <p>
 * Si tenga presente che in caso di creazione asincrona la <i>thumbnail</i> potrebbe non essere
 * subito disponibile anche se il metodo ha restituito informazioni valide.
 * 
 * @param pContentId
 *            L'id del contenuto.
 * @param pThumbDefinition
 *            Il nome della <i>thumbnail</i> di cui si richiede la crezione.
 * @param pAsync
 *            Se la crazione deve essere sincrona ({@code true} o asincrona ({@false}).
 * 
 * @return La <i>thumbnail</i> richiesta o {@code null} se il tipo di <i>thumbnail</i> di cui si
 *         è richiesta la creazione non è valido per il contenuto specificato.
 * 
 * @throws IOException
 */
public Thumbnail createThumbnail(String pContentId, String pThumbDefinition, boolean pAsync) throws IOException {
	/*
	 * POST <base>/content{property}/thumbnails?as={async?}
	 * 
	 * {
	 *     "thumbnailName": <name>
	 * }
	 */
	GenericUrl lUrl = getContentUrl(pContentId);
	lUrl.appendRawPath(URL_RELATIVE_THUMBNAILS);
	lUrl.set("as", pAsync);

	// Recupero delle definizioni valide
	// Purtroppo Alfresco restituisce successo anche se viene richiesta la generazione di una
	// thumbnail non possibile. Controllando preventivamente si può restituire null.
	List<String> lThumbDefinitions = getThumbnailDefinitions(pContentId);
	if (!lThumbDefinitions.contains(pThumbDefinition)) {
		return null;
	}

	JsonHttpContent lContent = new JsonHttpContent(JSON_FACTORY, new Thumbnail(pThumbDefinition));

	HttpHeaders lRequestHeaders = new HttpHeaders().setContentType("application/json");
	HttpRequest lRequest =
	        mHttpRequestFactory.buildPostRequest(lUrl, lContent).setHeaders(lRequestHeaders);

	HttpResponse lResponse = lRequest.execute();
	Thumbnail lThumbnail = lResponse.parseAs(Thumbnail.class);

	return lThumbnail;
}
 
开发者ID:MakeITBologna,项目名称:zefiro,代码行数:50,代码来源:NodeService.java

示例5: initiateResumableUpload

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
/**
 * Initiate a resumable upload direct to the cloud storage API. Providing an origin will enable
 * CORS requests to the upload URL from the specified origin.
 *
 * @param bucket      the cloud storage bucket to upload to
 * @param name        the name of the resource that will be uploaded
 * @param contentType the resource's content/mime type
 * @param origin      the origin to allow for CORS requests
 * @return the upload URL
 * @see <a href="https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload">Performing a Resumable Upload</a>
 */
public String initiateResumableUpload(String bucket, String name, String contentType, String origin) {
    String uploadUrl = String.format("%s/upload/storage/v1/b/%s/o", BASE_GOOGLE_API_URL, bucket);

    GenericUrl url = new GenericUrl(uploadUrl);
    url.put("uploadType", "resumable");
    url.put("name", name);

    HttpHeaders headers = new HttpHeaders();
    headers.put("X-Upload-Content-Type", contentType);
    if (origin != null) {
        headers.put("Origin", origin);  // Add origin header for CORS support
    }

    HttpResponse response;
    try {
        response = httpRequestFactory
            .buildPostRequest(url, null)
            .setHeaders(headers)
            .execute();
    } catch (IOException e) {
        throw new GoogleCloudStorageException(e, "Cannot initiate upload: %s", e.getMessage());
    }

    return response.getHeaders().getLocation();
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:37,代码来源:GoogleCloudStorageJsonApiClient.java

示例6: testSimpleRetry

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
public void testSimpleRetry() throws Exception {
    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 3);

    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();
    MockSleeper mockSleeper = new MockSleeper();

    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
        TimeValue.timeValueSeconds(5));

    Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    HttpResponse response = request.execute();

    assertThat(mockSleeper.getCount(), equalTo(3));
    assertThat(response.getStatusCode(), equalTo(200));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:RetryHttpInitializerWrapperTests.java

示例7: testIOExceptionRetry

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
public void testIOExceptionRetry() throws Exception {
    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1, true);

    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();
    MockSleeper mockSleeper = new MockSleeper();
    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
        TimeValue.timeValueMillis(500));

    Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    HttpResponse response = request.execute();

    assertThat(mockSleeper.getCount(), equalTo(1));
    assertThat(response.getStatusCode(), equalTo(200));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RetryHttpInitializerWrapperTests.java

示例8: getUserInfoJson

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
private User getUserInfoJson(final String authCode) throws IOException {
    try {
        final GoogleTokenResponse response = flow.newTokenRequest(authCode)
                .setRedirectUri(getCallbackUri())
                .execute();
        final Credential credential = flow.createAndStoreCredential(response, null);
        final HttpRequest request = HTTP_TRANSPORT.createRequestFactory(credential)
                .buildGetRequest(new GenericUrl(USER_INFO_URL));
        request.getHeaders().setContentType("application/json");
        final JSONObject identity = 
                new JSONObject(request.execute().parseAsString());
        return new User(
                identity.getString("id"),
                identity.getString("email"),
                identity.getString("name"),
                identity.getString("picture"));
    } catch (JSONException ex) {
        Logger.getLogger(AuthenticationResource.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:22,代码来源:AuthenticationResource.java

示例9: hasMetadataServer

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
private static boolean hasMetadataServer(HttpTransport transport) {
  try {
    HttpRequest request = transport.createRequestFactory()
        .buildGetRequest(new GenericUrl(METADATA_SERVER_URL));
    HttpResponse response = request.execute();
    HttpHeaders headers = response.getHeaders();
    return "Google".equals(headers.getFirstHeaderStringValue("Metadata-Flavor"));
  } catch (IOException | RuntimeException expected) {
    // If an error happens, it's probably safe to say the metadata service isn't available where
    // the code is running. We have to catch ApiProxyException due to the new dev server returning
    // a different error for unresolvable hostnames. Due to not wanting to put a required
    // dependency on the App Engine SDK here, we catch the generic RuntimeException and do a
    // class name check.
    if (expected instanceof RuntimeException
        && !API_PROXY_EXCEPTION_CLASS_NAME.equals(expected.getClass().getName())
        && !REMOTE_API_EXCEPTION_CLASS_NAME.equals(expected.getClass().getName())) {
      throw (RuntimeException) expected;
    }
  }
  return false;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:22,代码来源:ControlFilter.java

示例10: supply

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
@Override
public JsonWebKeySet supply(String issuer) {
  Preconditions.checkNotNull(issuer);

  Optional<GenericUrl> jwksUri = this.keyUriSupplier.supply(issuer);
  if (!jwksUri.isPresent()) {
    String message = String.format("Cannot find the jwks_uri for issuer %s: "
        + "either the issuer is unknown or the OpenID discovery failed", issuer);
    throw new UnauthenticatedException(message);
  }
  String rawJson = retrieveJwksJson(jwksUri.get());

  Map<String, Object> rawMap = parse(rawJson, new TypeReference<Map<String, Object>>() {});
  if (rawMap.containsKey("keys")) {
    // De-serialize the JSON string as a JWKS object.
    return extractJwks(rawJson);
  }
  // Otherwise try to de-serialize the JSON string as a map mapping from key
  // id to X.509 certificate.
  return extractX509Certificate(rawJson);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:22,代码来源:DefaultJwksSupplier.java

示例11: build

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
public OAuthAccessToken build() throws IOException {
  Url = new GenericUrl(config.getAccessTokenUrl());

  transport = new ApacheHttpTransport();

  HttpRequestFactory requestFactory = transport.createRequestFactory();
  request = requestFactory.buildRequest(HttpMethods.GET, Url, null);

  HttpHeaders headers = new HttpHeaders();
  headers.setUserAgent(config.getUserAgent());
  headers.setAccept(config.getAccept());

  request.setHeaders(headers);
  createRefreshParameters().intercept(request);

  return this;
}
 
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:18,代码来源:OAuthAccessToken.java

示例12: OAuthRequestResource

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
private OAuthRequestResource(Config config, SignerFactory signerFactory, String resource, String method, Map<? extends String, ?> params) {
	this.config = config;
	this.signerFactory = signerFactory;

	Url = new GenericUrl(config.getApiUrl() + resource);
	this.httpMethod = method;
	if(method.equals("POST") || method.equals("PUT")){
		usePost = true;
	}

	if (params != null) {
		Url.putAll(params);
	}
	
	connectTimeout = config.getConnectTimeout() * 1000;
	readTimeout = config.getReadTimeout() * 1000;
	
	//Proxy Service Setup
	if(!"".equals(config.getProxyHost()) && config.getProxyHost() != null) {
		String host = config.getProxyHost();
		boolean httpsEnabled = config.getProxyHttpsEnabled();
		int port = (int) (config.getProxyPort() == 80 && httpsEnabled ? 443 : config.getProxyPort());
		
		this.setProxy(host, port, httpsEnabled);
	}
}
 
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:27,代码来源:OAuthRequestResource.java

示例13: postRequest

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
protected <E> E postRequest(String path, Object body, Class<E> responseType){
    try {
        URI uri = uri(path);
        GenericUrl url = new GenericUrl(uri);

        if ( logger.isDebugEnabled() ){
            logger.debug("Request POSTed into botframework api " + uri + ":");
            logger.debug(JSON_FACTORY.toPrettyString(body));
        }
        HttpContent content = new JsonHttpContent(JSON_FACTORY,body);
        HttpRequest request = requestFactory.buildPostRequest(url,content);
        E response = (E) request.execute().parseAs(responseType);
        if ( logger.isDebugEnabled() ){
            logger.debug("Response back from botframework api:");
            logger.debug(JSON_FACTORY.toPrettyString(response));
        }
        return response;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:bots4j,项目名称:msbotframework,代码行数:22,代码来源:ConnectorClient.java

示例14: postRequestAsync

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
protected Future<HttpResponse> postRequestAsync(String path, Object body){
    try {
        URI uri = uri(path);
        GenericUrl url = new GenericUrl();
        if ( logger.isDebugEnabled() ){
            logger.debug("Request POSTed into botframework api " + uri + ":");
            logger.debug(JSON_FACTORY.toPrettyString(body));
        }
        HttpContent content = new JsonHttpContent(JSON_FACTORY,body);
        HttpRequest request = requestFactory.buildPostRequest(url,content);
        if ( this.executor != null ){
            return request.executeAsync(this.executor);
        }
        else{
            return request.executeAsync();
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:bots4j,项目名称:msbotframework,代码行数:22,代码来源:ConnectorClient.java

示例15: getThumbnailDefinitions

import com.google.api.client.http.GenericUrl; //导入依赖的package包/类
/**
 * Recupera le definizioni di thumbnail valide per il contenuto.
 * 
 * @param pContentId
 *            L'id del contenuto.
 * 
 * @return La lista delle definizioni valide.
 * 
 * @throws IOException
 */
public List<String> getThumbnailDefinitions(String pContentId) throws IOException {
	/*
	 * GET <base>/content{property}/thumbnaildefinitions
	 */

	GenericUrl lUrl = getContentUrl(pContentId);
	lUrl.appendRawPath(URL_RELATIVE_THUMBNAIL_DEFINITIONS);

	HttpRequest lRequest = mHttpRequestFactory.buildGetRequest(lUrl);
	TypeReference<List<String>> lType = new TypeReference<List<String>>() {};
	@SuppressWarnings("unchecked")
	List<String> lResponse = (List<String>) lRequest.execute().parseAs(lType.getType());

	return lResponse;
}
 
开发者ID:MakeITBologna,项目名称:zefiro,代码行数:26,代码来源:NodeService.java


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