当前位置: 首页>>代码示例>>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;未经允许,请勿转载。