當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHeaders類代碼示例

本文整理匯總了Java中com.google.api.client.http.HttpHeaders的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders類的具體用法?Java HttpHeaders怎麽用?Java HttpHeaders使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpHeaders類屬於com.google.api.client.http包,在下文中一共展示了HttpHeaders類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createThumbnail

import com.google.api.client.http.HttpHeaders; //導入依賴的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

示例2: initiateResumableUpload

import com.google.api.client.http.HttpHeaders; //導入依賴的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

示例3: setUpMocksAndFakes

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Before
public void setUpMocksAndFakes() throws IOException {
  fakeRequest =
      Request.builder()
          .setAccept(Arrays.asList("fake.accept", "another.fake.accept"))
          .setBody(new BlobHttpContent(Blobs.from("crepecake"), "fake.content.type"))
          .setAuthorization(Authorizations.withBasicToken("fake-token"))
          .build();

  Mockito.when(
          mockHttpRequestFactory.buildRequest(
              Mockito.any(String.class), Mockito.eq(fakeUrl), Mockito.any(BlobHttpContent.class)))
      .thenReturn(mockHttpRequest);

  Mockito.when(mockHttpRequest.setHeaders(Mockito.any(HttpHeaders.class)))
      .thenReturn(mockHttpRequest);
  Mockito.when(mockHttpRequest.execute()).thenReturn(mockHttpResponse);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:minikube-build-tools-for-java,代碼行數:19,代碼來源:ConnectionTest.java

示例4: hasMetadataServer

import com.google.api.client.http.HttpHeaders; //導入依賴的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

示例5: build

import com.google.api.client.http.HttpHeaders; //導入依賴的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

示例6: shouldHandleTooManyKeysCreated

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void shouldHandleTooManyKeysCreated() throws IOException {
  when(serviceAccountKeyManager.serviceAccountExists(anyString())).thenReturn(true);

  final GoogleJsonResponseException resourceExhausted = new GoogleJsonResponseException(
      new HttpResponseException.Builder(429, "RESOURCE_EXHAUSTED", new HttpHeaders()),
      new GoogleJsonError().set("status", "RESOURCE_EXHAUSTED"));

  doThrow(resourceExhausted).when(serviceAccountKeyManager).createJsonKey(any());
  doThrow(resourceExhausted).when(serviceAccountKeyManager).createP12Key(any());

  exception.expect(InvalidExecutionException.class);
  exception.expectMessage("Maximum number of keys on service account reached: " + SERVICE_ACCOUNT);

  sut.ensureServiceAccountKeySecret(WORKFLOW_ID.toString(), SERVICE_ACCOUNT);
}
 
開發者ID:spotify,項目名稱:styx,代碼行數:17,代碼來源:KubernetesGCPServiceAccountSecretManagerTest.java

示例7: testGetTemplate

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void testGetTemplate() throws DnsimpleException, IOException {
  Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates/1", HttpMethods.GET, new HttpHeaders(), null, resource("getTemplate/success.http"));

  String accountId = "1010";
  String templateId = "1";

  GetTemplateResponse response = client.templates.getTemplate(accountId, templateId);

  Template template = response.getData();
  assertEquals(1, template.getId().intValue());
  assertEquals(1010, template.getAccountId().intValue());
  assertEquals("Alpha", template.getName());
  assertEquals("alpha", template.getShortName());
  assertEquals("An alpha template.", template.getDescription());
  assertEquals("2016-03-22T11:08:58Z", template.getCreatedAt());
  assertEquals("2016-03-22T11:08:58Z", template.getUpdatedAt());
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:19,代碼來源:TemplatesTest.java

示例8: testRegisterDomain

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void testRegisterDomain() throws DnsimpleException, IOException {
  String accountId = "1010";
  String name = "example.com";
  HashMap<String, Object> attributes = new HashMap<String, Object>();
  attributes.put("registrant_id", "10");

  Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/registrations", HttpMethods.POST, new HttpHeaders(), attributes, resource("registerDomain/success.http"));

  RegisterDomainResponse response = client.registrar.registerDomain(accountId, name, attributes);
  DomainRegistration registration = response.getData();
  assertEquals(1, registration.getId().intValue());
  assertEquals(999, registration.getDomainId().intValue());
  assertEquals(2, registration.getRegistrantId().intValue());
  assertEquals("new", registration.getState());
  assertFalse(registration.hasAutoRenew());
  assertFalse(registration.hasWhoisPrivacy());
  assertEquals("2016-12-09T19:35:31Z", registration.getCreatedAt());
  assertEquals("2016-12-09T19:35:31Z", registration.getUpdatedAt());
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:21,代碼來源:RegistrarTest.java

示例9: testGetWhoisPrivacy

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void testGetWhoisPrivacy() throws DnsimpleException, IOException {
  String accountId = "1010";
  String domainId = "example.com";

  Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/whois_privacy", HttpMethods.GET, new HttpHeaders(), null, resource("getWhoisPrivacy/success.http"));

  GetWhoisPrivacyResponse response = client.registrar.getWhoisPrivacy(accountId, domainId);
  WhoisPrivacy whoisPrivacy = response.getData();
  assertEquals(1, whoisPrivacy.getId().intValue());
  assertEquals(2, whoisPrivacy.getDomainId().intValue());
  assertEquals("2017-02-13", whoisPrivacy.getExpiresOn());
  assertTrue(whoisPrivacy.getEnabled().booleanValue());
  assertEquals("2016-02-13T14:34:50Z", whoisPrivacy.getCreatedAt());
  assertEquals("2016-02-13T14:34:52Z", whoisPrivacy.getUpdatedAt());
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:17,代碼來源:RegistrarWhoisPrivacyTest.java

示例10: testChangeDomainDelegation

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void testChangeDomainDelegation() throws DnsimpleException, IOException {
  String accountId = "1010";
  String domainId = "example.com";
  List<String> nameServerNames = new ArrayList<String>();
  nameServerNames.add("ns1.example.com");

  Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/delegation", HttpMethods.PUT, new HttpHeaders(), nameServerNames, resource("changeDomainDelegation/success.http"));

  ChangeDomainDelegationResponse response = client.registrar.changeDomainDelegation(accountId, domainId, nameServerNames);
  List<String> delegatedTo = response.getData();
  assertEquals("ns1.dnsimple.com", delegatedTo.get(0));
  assertEquals("ns2.dnsimple.com", delegatedTo.get(1));
  assertEquals("ns3.dnsimple.com", delegatedTo.get(2));
  assertEquals("ns4.dnsimple.com", delegatedTo.get(3));
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:17,代碼來源:RegistrarDelegationTest.java

示例11: testChangeDomainDelegationToVanity

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void testChangeDomainDelegationToVanity() throws DnsimpleException, IOException {
  String accountId = "1010";
  String domainId = "example.com";
  List<String> nameServerNames = new ArrayList<String>();
  nameServerNames.add("ns1.example.com");
  nameServerNames.add("ns2.example.com");

  Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/delegation/vanity", HttpMethods.PUT, new HttpHeaders(), nameServerNames, resource("changeDomainDelegationToVanity/success.http"));

  ChangeDomainDelegationToVanityResponse response = client.registrar.changeDomainDelegationToVanity(accountId, domainId, nameServerNames);
  List<NameServer> delegatedTo = response.getData();
  assertEquals(2, delegatedTo.size());

  NameServer nameServer = delegatedTo.get(0);
  assertEquals("ns1.example.com", nameServer.getName());
  assertEquals("127.0.0.1", nameServer.getIpv4());
  assertEquals("::1", nameServer.getIpv6());
  assertEquals("2016-07-11T09:40:19Z", nameServer.getCreatedAt());
  assertEquals("2016-07-11T09:40:19Z", nameServer.getUpdatedAt());
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:22,代碼來源:RegistrarDelegationTest.java

示例12: testGetTldExtendedAttributes

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void testGetTldExtendedAttributes() throws DnsimpleException, IOException {
  Client client = mockAndExpectClient("https://api.dnsimple.com/v2/tlds/uk/extended_attributes", HttpMethods.GET, new HttpHeaders(), null, resource("getTldExtendedAttributes/success.http"));

  String tldString = "uk";

  GetTldExtendedAttributesResponse response = client.tlds.getTldExtendedAttributes(tldString);

  List<TldExtendedAttribute> extendedAttributes = response.getData();
  assertEquals(4, extendedAttributes.size());
  assertEquals("uk_legal_type", extendedAttributes.get(0).getName());
  assertEquals("Legal type of registrant contact", extendedAttributes.get(0).getDescription());
  assertEquals(false, extendedAttributes.get(0).getRequired().booleanValue());

  List<TldExtendedAttributeOption> options = extendedAttributes.get(0).getOptions();
  assertEquals(17, options.size());
  assertEquals("UK Individual", options.get(0).getTitle());
  assertEquals("IND", options.get(0).getValue());
  assertEquals("UK Individual (our default value)", options.get(0).getDescription());
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:21,代碼來源:TldsTest.java

示例13: testExchangeAuthorizationForToken

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void testExchangeAuthorizationForToken() throws DnsimpleException, IOException {
  String clientId = "super-client-id";
  String clientSecret = "super-client-secret";
  String code = "super-code";

  HashMap<String, Object> attributes = new HashMap<String, Object>();
  attributes.put("code", code);
  attributes.put("client_id", clientId);
  attributes.put("client_secret", clientSecret);
  attributes.put("grant_type", "authorization_code");

  Client client = mockAndExpectClient("https://api.dnsimple.com/v2/oauth/access_token", HttpMethods.POST, new HttpHeaders(), attributes, resource("oauthAccessToken/success.http"));

  OauthToken token = client.oauth.exchangeAuthorizationForToken(code, clientId, clientSecret);
  assertEquals("zKQ7OLqF5N1gylcJweA9WodA000BUNJD", token.getAccessToken());
  assertEquals("Bearer", token.getTokenType());
  assertTrue(Data.isNull(token.getScope()));
  assertEquals(1, token.getAccountId().intValue());
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:21,代碼來源:OauthTest.java

示例14: sendPostMultipart

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
public static int sendPostMultipart(String urlString, Map<String, String> parameters)
    throws IOException {

  MultipartContent postBody = new MultipartContent()
      .setMediaType(new HttpMediaType("multipart/form-data"));
  postBody.setBoundary(MULTIPART_BOUNDARY);

  for (Map.Entry<String, String> entry : parameters.entrySet()) {
    HttpContent partContent = ByteArrayContent.fromString(  // uses UTF-8 internally
        null /* part Content-Type */, entry.getValue());
    HttpHeaders partHeaders = new HttpHeaders()
        .set("Content-Disposition",  "form-data; name=\"" + entry.getKey() + "\"");

    postBody.addPart(new MultipartContent.Part(partHeaders, partContent));
  }

  GenericUrl url = new GenericUrl(new URL(urlString));
  HttpRequest request = transport.createRequestFactory().buildPostRequest(url, postBody);
  request.setHeaders(new HttpHeaders().setUserAgent(CloudToolsInfo.USER_AGENT));
  request.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
  request.setReadTimeout(DEFAULT_READ_TIMEOUT_MS);

  HttpResponse response = request.execute();
  return response.getStatusCode();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-eclipse,代碼行數:26,代碼來源:HttpUtil.java

示例15: create_adminApiNotEnabled

import com.google.api.client.http.HttpHeaders; //導入依賴的package包/類
@Test
public void create_adminApiNotEnabled() throws IOException {
  ErrorInfo error = new ErrorInfo();
  error.setReason(SslSocketFactory.ADMIN_API_NOT_ENABLED_REASON);
  GoogleJsonError details = new GoogleJsonError();
  details.setErrors(ImmutableList.of(error));
  when(adminApiInstancesGet.execute())
      .thenThrow(
          new GoogleJsonResponseException(
              new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
              details));

  SslSocketFactory sslSocketFactory =
      new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
  try {
    sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
    fail("Expected RuntimeException");
  } catch (RuntimeException e) {
    // TODO(berezv): should we throw something more specific than RuntimeException?
    assertThat(e.getMessage()).contains("Cloud SQL API is not enabled");
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-sql-jdbc-socket-factory,代碼行數:23,代碼來源:SslSocketFactoryTest.java


注:本文中的com.google.api.client.http.HttpHeaders類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。