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


Java HttpStatusCodes.CREATED属性代码示例

本文整理汇总了Java中org.apache.olingo.odata2.api.commons.HttpStatusCodes.CREATED属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodes.CREATED属性的具体用法?Java HttpStatusCodes.CREATED怎么用?Java HttpStatusCodes.CREATED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.olingo.odata2.api.commons.HttpStatusCodes的用法示例。


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

示例1: writeEntity

private void writeEntity(String absoluteUri, String content, String contentType, String httpMethod)
    throws IOException, URISyntaxException {

  print(httpMethod + " request on uri: " + absoluteUri + ":\n  " + content + "\n");
  //
  HttpURLConnection connection = initializeConnection(absoluteUri, contentType, httpMethod);
  byte[] buffer = content.getBytes("UTF-8");
  connection.getOutputStream().write(buffer);

  // if a entity is created (via POST request) the response body contains the new created entity
  HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(connection.getResponseCode());
  if(statusCode == HttpStatusCodes.CREATED) {
    // get the content as InputStream and de-serialize it into an ODataEntry object
    InputStream responseContent = connection.getInputStream();
    logRawContent(httpMethod + " response:\n  ", responseContent, "\n");
  } else if(statusCode == HttpStatusCodes.NO_CONTENT) {
    print("No content.");
  } else {
    checkStatus(connection);
  }

  //
  connection.disconnect();
}
 
开发者ID:mirchiseth,项目名称:cf-cars-svc,代码行数:24,代码来源:AnnotationSampleDataGenerator.java

示例2: executeValidated

public HttpResponse executeValidated(HttpStatusCodes expectedStatusCode) throws IOException {
  HttpResponse response = this.execute();
  assertNotNull(response);
  assertEquals(expectedStatusCode.getStatusCode(), response.getStatusLine().getStatusCode());

  if (expectedStatusCode == HttpStatusCodes.OK) {
    assertNotNull(response.getEntity());
    assertNotNull(response.getEntity().getContent());
  } else if (expectedStatusCode == HttpStatusCodes.CREATED) {
    assertNotNull(response.getEntity());
    assertNotNull(response.getEntity().getContent());
    assertNotNull(response.getFirstHeader(HttpHeaders.LOCATION));
  } else if (expectedStatusCode == HttpStatusCodes.NO_CONTENT) {
    assertTrue(response.getEntity() == null || response.getEntity().getContent() == null);
  }

  return response;
}
 
开发者ID:mibo,项目名称:janos,代码行数:18,代码来源:AbstractRefTest.java

示例3: getStatusCode

private HttpStatusCodes getStatusCode(final ODataResponse odataResponse, final ODataHttpMethod method,
    final UriType uriType) {
  if (odataResponse.getStatus() == null) {
    if (method == ODataHttpMethod.POST) {
      if (uriType == UriType.URI9) {
        return HttpStatusCodes.OK;
      } else if (uriType == UriType.URI7B) {
        return HttpStatusCodes.NO_CONTENT;
      }
      return HttpStatusCodes.CREATED;
    } else if (method == ODataHttpMethod.PUT
        || method == ODataHttpMethod.PATCH
        || method == ODataHttpMethod.MERGE
        || method == ODataHttpMethod.DELETE) {
      return HttpStatusCodes.NO_CONTENT;
    }
    return HttpStatusCodes.OK;
  }
  return odataResponse.getStatus();
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:ODataRequestHandler.java

示例4: testURI_1_ForIssue

@Test
public void testURI_1_ForIssue() throws Exception {
  // create test set
  UriType uriType = UriType.URI1;
  String httpMethod = "POST";
  String path = "/Employees";
  String queryOption = "";
  String acceptHeader = "*";
  String content = "IMAGE_;o)";
  String requestContentType = "image/jpeg";
  HttpStatusCodes expectedStatusCode = HttpStatusCodes.CREATED;
  String expectedContentType = "application/atom+xml; charset=utf-8; type=entry";

  FitTest test =
      FitTest.create(uriType, httpMethod, path, queryOption, acceptHeader, content, requestContentType,
          expectedStatusCode, expectedContentType);

  test.execute(getEndpoint());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:19,代码来源:ContentNegotiationPostRequestTest.java

示例5: testURI_2_ForIssue

@Test
@Ignore("What is expected service behavior?")
public void testURI_2_ForIssue() throws Exception {
  // create test set
  UriType uriType = UriType.URI2;
  String httpMethod = "PUT";
  String path = "/Employees('1')";
  String queryOption = "";
  String acceptHeader = "*";
  String content = "IMAGE_;o)";
  String requestContentType = "image/jpeg";
  HttpStatusCodes expectedStatusCode = HttpStatusCodes.CREATED;
  String expectedContentType = "image/jpeg";

  FitTest test =
      FitTest.create(uriType, httpMethod, path, queryOption, acceptHeader, content, requestContentType,
          expectedStatusCode, expectedContentType);

  test.execute(getEndpoint());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:ContentNegotiationPostRequestTest.java

示例6: writeEntity

private String writeEntity(String absoluteUri, String content, String contentType, String httpMethod)
    throws IOException, URISyntaxException {

  String location = null;
  print(httpMethod + " request on uri: " + absoluteUri + ":\n  " + content + "\n");
  //
  HttpURLConnection connection = initializeConnection(absoluteUri, contentType, httpMethod);
  byte[] buffer = content.getBytes("UTF-8");
  connection.getOutputStream().write(buffer);

  // if a entity is created (via POST request) the response body contains the new created entity
  HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(connection.getResponseCode());
  if (statusCode == HttpStatusCodes.CREATED) {
    // get the content as InputStream and de-serialize it into an ODataEntry object
    InputStream responseContent = connection.getInputStream();
    logRawContent(httpMethod + " response:\n  ", responseContent, "\n");
    location = connection.getHeaderField("Location");
  } else if (statusCode == HttpStatusCodes.NO_CONTENT) {
    print("No content.");
  } else {
    checkStatus(connection);
  }

  //
  connection.disconnect();
  return location;
}
 
开发者ID:mibo,项目名称:janos,代码行数:27,代码来源:JpaSampleDataGenerator.java

示例7: callUri

protected HttpResponse callUri(
    final ODataHttpMethod httpMethod, final String uri,
    final String additionalHeader, final String additionalHeaderValue,
    final String requestBody, final String requestContentType,
    final HttpStatusCodes expectedStatusCode) throws Exception {

  HttpRequestBase request =
      httpMethod == ODataHttpMethod.GET ? new HttpGet() :
          httpMethod == ODataHttpMethod.DELETE ? new HttpDelete() :
              httpMethod == ODataHttpMethod.POST ? new HttpPost() :
                  httpMethod == ODataHttpMethod.PUT ? new HttpPut() : new HttpPatch();
  request.setURI(URI.create(getEndpoint() + uri));
  if (additionalHeader != null) {
    request.addHeader(additionalHeader, additionalHeaderValue);
  }
  if (requestBody != null) {
    ((HttpEntityEnclosingRequest) request).setEntity(new StringEntity(requestBody));
    request.setHeader(HttpHeaders.CONTENT_TYPE, requestContentType);
  }

  final HttpResponse response = getHttpClient().execute(request);

  assertNotNull(response);
  assertEquals(expectedStatusCode.getStatusCode(), response.getStatusLine().getStatusCode());

  if (expectedStatusCode == HttpStatusCodes.OK) {
    assertNotNull(response.getEntity());
    assertNotNull(response.getEntity().getContent());
  } else if (expectedStatusCode == HttpStatusCodes.CREATED) {
    assertNotNull(response.getEntity());
    assertNotNull(response.getEntity().getContent());
    assertNotNull(response.getFirstHeader(HttpHeaders.LOCATION));
  } else if (expectedStatusCode == HttpStatusCodes.NO_CONTENT) {
    assertTrue(response.getEntity() == null || response.getEntity().getContent() == null);
  }

  return response;
}
 
开发者ID:mibo,项目名称:janos,代码行数:38,代码来源:AbstractRefTest.java

示例8: createWithAcceptHeaderEntry

@Test
public void createWithAcceptHeaderEntry() throws Exception {
  // Create an entry for a type that has no media resource.
  String requestBody = getBody(callUri("Teams('1')"))
      .replace("'1'", "'9'")
      .replace("Id>1", "Id>9")
      .replace("Team 1", "Team X")
      .replaceAll("<link.+?/>", "");
  String requestContentType = HttpContentType.APPLICATION_ATOM_XML_ENTRY;
  HttpStatusCodes expectedStatusCode = HttpStatusCodes.CREATED;
  String headerName = "Accept";
  String headerValue = "application/atom+xml;type=entry";
  HttpResponse response =
      callUri(ODataHttpMethod.POST, "Teams()", headerName, headerValue, requestBody, requestContentType,
          expectedStatusCode);

  checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
  assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
  assertNull(response.getFirstHeader(HttpHeaders.ETAG));
  assertXpathEvaluatesTo("Team X", "/atom:entry/atom:content/m:properties/d:Name", getBody(response));

  // Create an entry for a type that has no media resource.
  // Add navigation to Employee('4') and Employee('5').
  requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n"
      + "       xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n"
      + "       xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n"
      + "  <author><name>no author</name></author>" + "\n"
      + "  <content type=\"application/xml\">" + "\n"
      + "    <m:properties>" + "\n"
      + "      <d:Id>109</d:Id>" + "\n"
      + "      <d:Name/>" + "\n"
      + "      <d:Seats>4</d:Seats>" + "\n"
      + "      <d:Version>2</d:Version>" + "\n"
      + "    </m:properties>" + "\n"
      + "  </content>" + "\n"
      + "  <id>Rooms('104')</id>" + "\n"
      + "  <title>Room 104</title>" + "\n"
      + "  <updated>2011-08-10T12:00:23Z</updated>" + "\n"
      + "  <link href=\"Employees('4')\"" + "\n"
      + "        rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
      + "        type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
      + "  <link href=\"Employees('5')\"" + "\n"
      + "        rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
      + "        type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
      + "</entry>";
  response = postUri("Rooms", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
  assertEquals(getEndpoint() + "Rooms('104')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
  checkEtag(response, "W/\"2\"");
  assertXpathEvaluatesTo("4", "/atom:entry/atom:content/m:properties/d:Seats", getBody(response));
  checkUri("Rooms('104')/nr_Employees('4')");
  checkUri("Rooms('104')/nr_Employees('5')");
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:53,代码来源:EntryXmlChangeTest.java


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