本文整理汇总了Java中org.apache.olingo.odata2.api.commons.HttpStatusCodes.NO_CONTENT属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodes.NO_CONTENT属性的具体用法?Java HttpStatusCodes.NO_CONTENT怎么用?Java HttpStatusCodes.NO_CONTENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.olingo.odata2.api.commons.HttpStatusCodes
的用法示例。
在下文中一共展示了HttpStatusCodes.NO_CONTENT属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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;
}
示例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();
}
示例4: 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;
}
示例5: 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;
}
示例6: deleteUri
protected void deleteUri(final String uri, final HttpStatusCodes expectedStatusCode)
throws Exception, AssertionError {
final HttpResponse response = callUri(ODataHttpMethod.DELETE, uri, null, null, null, null, expectedStatusCode);
if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
response.getEntity().getContent().close();
}
}
示例7: putUri
protected void putUri(final String uri,
final String requestBody, final String requestContentType,
final HttpStatusCodes expectedStatusCode) throws Exception {
final HttpResponse response =
callUri(ODataHttpMethod.PUT, uri, null, null, requestBody, requestContentType, expectedStatusCode);
if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
response.getEntity().getContent().close();
}
}