本文整理汇总了Java中org.fcrepo.client.FcrepoResponse.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java FcrepoResponse.getStatusCode方法的具体用法?Java FcrepoResponse.getStatusCode怎么用?Java FcrepoResponse.getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fcrepo.client.FcrepoResponse
的用法示例。
在下文中一共展示了FcrepoResponse.getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importBinary
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
private FcrepoResponse importBinary(final URI binaryURI, final Model model)
throws FcrepoOperationFailedException, IOException {
final String contentType = model.getProperty(createResource(binaryURI.toString()), HAS_MIME_TYPE).getString();
final File binaryFile = fileForBinaryURI(binaryURI, external(contentType));
final FcrepoResponse binaryResponse = binaryBuilder(binaryURI, binaryFile, contentType, model).perform();
if (binaryResponse.getStatusCode() == 201 || binaryResponse.getStatusCode() == 204) {
logger.info("Imported binary: {}", binaryURI);
importLogger.info("import {} to {}", binaryFile.getAbsolutePath(), binaryURI);
successCount.incrementAndGet();
final URI descriptionURI = binaryResponse.getLinkHeaders("describedby").get(0);
return client().put(descriptionURI).body(modelToStream(sanitize(model)), config.getRdfLanguage())
.preferLenient().perform();
} else if (binaryResponse.getStatusCode() == 410 && config.overwriteTombstones()) {
deleteTombstone(binaryResponse);
return binaryBuilder(binaryURI, binaryFile, contentType, model).perform();
} else {
logger.error("Error while importing {} ({}): {}", binaryFile.getAbsolutePath(),
binaryResponse.getStatusCode(), IOUtils.toString(binaryResponse.getBody()));
return null;
}
}
示例2: makePlaceholder
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
private void makePlaceholder(final URI uri) throws IOException, FcrepoOperationFailedException {
ensureExists(parent(uri));
final FcrepoResponse response;
if (fileForBinaryURI(uri, false).exists() || fileForBinaryURI(uri, true).exists()) {
response = client().put(uri).body(new ByteArrayInputStream(new byte[]{})).perform();
} else if (fileForContainerURI(uri).exists()) {
response = client().put(uri).body(new ByteArrayInputStream(
"<> a <http://www.w3.org/ns/ldp#Container> .".getBytes()), "text/turtle").perform();
} else {
return;
}
if (response.getStatusCode() != 201) {
logger.error("Unexpected response when creating {} ({}): {}", uri,
response.getStatusCode(), response.getBody());
}
}
示例3: checkValidResponse
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
/**
* Checks the response code and throws a RuntimeException with a helpful
* message (when possible) for non 2xx codes.
* @param response the response from a REST call to Fedora
* @param uri the URI against which the request was made
* @param user the user name for authorization
*/
public static void checkValidResponse(final FcrepoResponse response, final URI uri, final String user) {
switch (response.getStatusCode()) {
case 401:
throw new AuthenticationRequiredRuntimeException();
case 403:
throw new AuthorizationDeniedRuntimeException(user, uri);
case 404:
throw new ResourceNotFoundRuntimeException(uri);
default:
if (response.getStatusCode() < 200 || response.getStatusCode() > 307) {
throw new RuntimeException("Export operation failed: unexpected status "
+ response.getStatusCode() + " for " + uri);
}
}
}
示例4: importContainer
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
private FcrepoResponse importContainer(final URI uri, final Model model) throws FcrepoOperationFailedException {
final FcrepoResponse response = containerBuilder(uri, model).preferLenient().perform();
if (response.getStatusCode() == 410 && config.overwriteTombstones()) {
deleteTombstone(response);
return containerBuilder(uri, model).preferLenient().perform();
} else {
return response;
}
}
示例5: getResource
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
private FcrepoResponse getResource(final String url) {
FcrepoResponse response;
try {
LOGGER.trace("GET: {}", url);
response = client.get(URI.create(url)).accept(TEXT_TURTLE).disableRedirects().perform();
final int statusCode = response.getStatusCode();
if (OK.getStatusCode() != statusCode && TEMPORARY_REDIRECT.getStatusCode() != statusCode) {
throw new RuntimeException("Unexpected response status: " + statusCode + ", " + url);
}
} catch (FcrepoOperationFailedException e) {
throw new RuntimeException(e);
}
return response;
}
示例6: headResource
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
private FcrepoResponse headResource(final String url) {
FcrepoResponse response;
try {
LOGGER.trace("HEAD: {}", url);
response = client.head(URI.create(url)).disableRedirects().perform();
final int statusCode = response.getStatusCode();
if (OK.getStatusCode() != statusCode && TEMPORARY_REDIRECT.getStatusCode() != statusCode) {
throw new RuntimeException("Unexpected response status: " + statusCode + ", " + url);
}
} catch (FcrepoOperationFailedException e) {
throw new RuntimeException(e);
}
return response;
}
示例7: testPostBinary
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testPostBinary() throws Exception {
final String slug = "hello1";
final String filename = "hello.txt";
final String mimetype = "text/plain";
final String bodyContent = "Hello world";
final FcrepoResponse response = client.post(new URI(serverAddress))
.body(new ByteArrayInputStream(bodyContent.getBytes()), mimetype)
.filename(filename)
.slug(slug)
.perform();
final String content = IOUtils.toString(response.getBody(), "UTF-8");
final int status = response.getStatusCode();
assertEquals("Didn't get a CREATED response! Got content:\n" + content,
CREATED.getStatusCode(), status);
assertEquals("Location did not match slug", serverAddress + slug, response.getLocation().toString());
assertNotNull("Didn't find linked description!", response.getLinkHeaders("describedby").get(0));
final FcrepoResponse getResponse = client.get(response.getLocation()).perform();
final Map<String, String> contentDisp = getResponse.getContentDisposition();
assertEquals(filename, contentDisp.get(CONTENT_DISPOSITION_FILENAME));
assertEquals(mimetype, getResponse.getContentType());
final String getContent = IOUtils.toString(getResponse.getBody(), "UTF-8");
assertEquals(bodyContent, getContent);
}
示例8: testAuthUserCanPut
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testAuthUserCanPut() throws Exception {
final InputStream body = new ByteArrayInputStream(rdfTtl.getBytes());
final FcrepoResponse response = authClient.put(new URI(serverAddress + "testobj1"))
.body(body, TEXT_TURTLE)
.perform();
final String content = IOUtils.toString(response.getBody(), "UTF-8");
final int status = response.getStatusCode();
assertEquals("Didn't get a CREATED response! Got content:\n" + content,
CREATED.getStatusCode(), status);
}
示例9: testUnAuthUserCannotPut
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testUnAuthUserCannotPut() throws Exception {
final InputStream body = new ByteArrayInputStream(rdfTtl.getBytes());
final FcrepoResponse response = client.put(new URI(serverAddress + "testobj2"))
.body(body, TEXT_TURTLE)
.perform();
final String content = IOUtils.toString(response.getBody(), "UTF-8");
final int status = response.getStatusCode();
assertEquals("Unauthenticated user should be forbidden! Got content:\n" + content,
FORBIDDEN.getStatusCode(), status);
}
示例10: testAuthUserCanPatch
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testAuthUserCanPatch() throws Exception {
final InputStream body = new ByteArrayInputStream(sparqlUpdate.getBytes());
final FcrepoResponse response = authClient.patch(new URI(serverAddress + "testobj1"))
.body(body)
.perform();
final int status = response.getStatusCode();
assertEquals("Didn't get a successful PATCH response! Got content:\n",
NO_CONTENT.getStatusCode(), status);
}
示例11: testUnAuthUserCannotPatch
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testUnAuthUserCannotPatch() throws Exception {
final InputStream body = new ByteArrayInputStream(sparqlUpdate.getBytes());
final FcrepoResponse response = client.patch(new URI(serverAddress + "testobj1"))
.body(body)
.perform();
final String content = IOUtils.toString(response.getBody(), "UTF-8");
final int status = response.getStatusCode();
assertEquals("Unauthenticated user should be forbidden! Got content:\n" + content,
FORBIDDEN.getStatusCode(), status);
}
示例12: testAuthUserCanPost
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testAuthUserCanPost() throws Exception {
final InputStream body = new ByteArrayInputStream(rdfTtl.getBytes());
final FcrepoResponse response = authClient.post(new URI(serverAddress))
.body(body, TEXT_TURTLE)
.perform();
final String content = IOUtils.toString(response.getBody(), "UTF-8");
final int status = response.getStatusCode();
assertEquals("Didn't get a CREATED response! Got content:\n" + content,
CREATED.getStatusCode(), status);
}
示例13: testUnAuthUserCannotPost
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testUnAuthUserCannotPost() throws Exception {
final InputStream body = new ByteArrayInputStream(rdfTtl.getBytes());
final FcrepoResponse response = client.post(new URI(serverAddress))
.body(body, TEXT_TURTLE)
.perform();
final String content = IOUtils.toString(response.getBody(), "UTF-8");
final int status = response.getStatusCode();
assertEquals("Unauthenticated user should be forbidden! Got content:\n" + content,
FORBIDDEN.getStatusCode(), status);
}
示例14: testAuthUserCanGet
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testAuthUserCanGet()
throws Exception {
final FcrepoResponse response = authClient.get(new URI(serverAddress)).perform();
final int status = response.getStatusCode();
assertEquals("Authenticated user can not read root!", OK
.getStatusCode(), status);
}
示例15: testUnAuthUserCannotGet
import org.fcrepo.client.FcrepoResponse; //导入方法依赖的package包/类
@Test
public void testUnAuthUserCannotGet()
throws Exception {
final FcrepoResponse response = client.get(new URI(serverAddress)).perform();
final int status = response.getStatusCode();
assertEquals("Unauthenticated user should be forbidden!", FORBIDDEN
.getStatusCode(), status);
}