本文整理汇总了Java中org.fcrepo.client.FcrepoResponse类的典型用法代码示例。如果您正苦于以下问题:Java FcrepoResponse类的具体用法?Java FcrepoResponse怎么用?Java FcrepoResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FcrepoResponse类属于org.fcrepo.client包,在下文中一共展示了FcrepoResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterBinaryReferences
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
/**
* Filter out the binary resource references from the model
* @param uri the URI for the resource
* @param model the RDF Model of the resource
* @return the RDF model with no binary references
* @throws FcrepoOperationFailedException
* @throws IOException
*/
private void filterBinaryReferences(final URI uri, final Model model) throws IOException,
FcrepoOperationFailedException {
final List<Statement> removeList = new ArrayList<>();
for (final StmtIterator it = model.listStatements(); it.hasNext();) {
final Statement s = it.nextStatement();
final RDFNode obj = s.getObject();
if (obj.isResource() && obj.toString().startsWith(repositoryRoot.toString())
&& !s.getPredicate().toString().equals(REPOSITORY_NAMESPACE + "hasTransactionProvider")) {
try (final FcrepoResponse resp = client().head(URI.create(obj.toString())).disableRedirects()
.perform()) {
checkValidResponse(resp, URI.create(obj.toString()), config.getUsername());
final List<URI> linkHeaders = resp.getLinkHeaders("type");
if (linkHeaders.contains(binaryURI)) {
removeList.add(s);
}
}
}
}
model.remove(removeList);
}
示例2: 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;
}
}
示例3: 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());
}
}
示例4: 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);
}
}
}
示例5: isRepositoryRoot
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
/**
* Utility method to determine whether the current uri is repository root or not. The repository root is the
* container with type fcrepo:RepositoryRoot
* @param uri the URI for the resource
* @param client the FcrepoClient to query the repository
* @param config the Config for import/export
* @throws IOException if there is a error with the network connection
* @throws FcrepoOperationFailedException if there is a error with Fedora
* @return True if the URI is the root of the repository
*/
public static boolean isRepositoryRoot(final URI uri, final FcrepoClient client, final Config config)
throws IOException, FcrepoOperationFailedException {
final String userName = config.getUsername();
final String rdfLanguage = config.getRdfLanguage();
try (FcrepoResponse response = client.head(uri).disableRedirects().perform()) {
checkValidResponse(response, uri, userName);
// The repository root will not be a binary
if (response.getLinkHeaders("type").contains(URI.create(NON_RDF_SOURCE.getURI()))) {
return false;
}
try (FcrepoResponse resp = client.get(uri).accept(rdfLanguage).disableRedirects()
.perform()) {
final Model model = createDefaultModel().read(resp.getBody(), null, rdfLanguage);
if (model.contains(null, RDF_TYPE, REPOSITORY_ROOT)) {
return true;
}
}
}
return false;
}
示例6: testRoundtripOverwriteBinary
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void testRoundtripOverwriteBinary() throws Exception {
final URI fileURI = URI.create(serverAddress + UUID.randomUUID());
final File binaryFile = new File("src/test/resources/binary.txt");
final String binaryContent = IOUtils.toString(new FileInputStream(binaryFile));
final FcrepoResponse response = createBody(fileURI, new FileInputStream(binaryFile), "text/plain");
assertEquals(SC_CREATED, response.getStatusCode());
assertEquals(fileURI, response.getLocation());
roundtrip(fileURI, false);
// verify that the resources have been created
assertTrue(exists(fileURI));
assertEquals(binaryContent, getAsString(fileURI));
}
示例7: testRoundtripRdfBinary
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void testRoundtripRdfBinary() throws Exception {
final URI fileURI = URI.create(serverAddress + UUID.randomUUID());
final File binaryFile = new File("src/test/resources/binary.txt");
final String binaryContent = IOUtils.toString(new FileInputStream(binaryFile));
// create a binary with an RDF content type
final FcrepoResponse response = clientBuilder.build().put(fileURI)
.body(new FileInputStream(binaryFile), "text/turtle").filename(null).perform();
assertEquals(SC_CREATED, response.getStatusCode());
assertEquals(fileURI, response.getLocation());
roundtrip(fileURI, true);
// verify that the resources have been created
assertTrue(exists(fileURI));
assertEquals(binaryContent, getAsString(fileURI));
}
示例8: testExport
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void testExport() throws Exception {
// Create a repository resource
final FcrepoResponse response = create(url);
assertEquals(SC_CREATED, response.getStatusCode());
assertEquals(url, response.getLocation());
// Run an export process
final Config config = new Config();
config.setMode("export");
config.setBaseDirectory(TARGET_DIR);
config.setResource(url);
config.setRdfLanguage(DEFAULT_RDF_LANG);
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
config.setPredicates(new String[]{ CONTAINS.toString() });
final Exporter exporter = new Exporter(config, clientBuilder);
exporter.run();
// Verify
assertTrue(new File(TARGET_DIR, url.getPath() + DEFAULT_RDF_EXT).exists());
}
示例9: testJarExport
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void testJarExport() throws Exception {
// Create a repository resource
final FcrepoResponse response = create(url);
assertEquals(SC_CREATED, response.getStatusCode());
assertEquals(url, response.getLocation());
// Run an export process
final Process process = startJarProcess("-m", "export",
"-d", TARGET_DIR,
"-r", url.toString(),
"-u", "fedoraAdmin:password");
// Verify
assertTrue("Process did not exit before timeout!", process.waitFor(TIMEOUT_SECONDS, TimeUnit.SECONDS));
assertEquals("Did not exit with success status!", 0, process.exitValue());
assertTrue(new File(TARGET_DIR, url.getPath() + DEFAULT_RDF_EXT).exists());
}
示例10: testImportBagVerifyBinaryDigest
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void testImportBagVerifyBinaryDigest() throws Exception {
final URI badBinURI = new URI("http://example.org:9999/rest/bad_bin1");
// mock bad binary interactions
final PutBuilder badBinBuilder = mock(PutBuilder.class);
final FcrepoResponse badBinResponse = mock(FcrepoResponse.class);
when(client.put(isA(URI.class))).thenReturn(badBinBuilder);
when(badBinBuilder.body(isA(InputStream.class), isA(String.class))).thenReturn(badBinBuilder);
when(badBinBuilder.digest(isA(String.class))).thenReturn(badBinBuilder);
when(badBinBuilder.filename(any())).thenReturn(badBinBuilder);
when(badBinBuilder.ifUnmodifiedSince(any())).thenReturn(badBinBuilder);
when(badBinBuilder.preferLenient()).thenReturn(badBinBuilder);
when(badBinBuilder.perform()).thenReturn(badBinResponse);
when(badBinResponse.getStatusCode()).thenReturn(409);
when(badBinResponse.getBody()).thenReturn(new ByteArrayInputStream("Checksum Mismatch".getBytes()));
final Importer importer = new Importer(bagItArgs, clientBuilder);
importer.run();
verify(client).put(badBinURI);
// verify that the checksum from the manifest-sha1 file is used
verify(badBinBuilder).digest(eq("c537ab534deef7493140106c2151eccf2a219b8e"));
}
示例11: mockGetResponse
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
/**
* Mocks a successful GET request response
*
* @param client client
* @param uri uri of destination being mocked
* @param typeLinks type links
* @param describedbyLinks described by links
* @param body body of response
* @throws FcrepoOperationFailedException client failures
*/
public static void mockGetResponse(final FcrepoClient client, final URI uri, final List<URI> typeLinks,
final List<URI> describedbyLinks, final String body) throws FcrepoOperationFailedException {
final GetBuilder getBuilder = mock(GetBuilder.class);
final FcrepoResponse getResponse = mock(FcrepoResponse.class);
when(client.get(eq(uri))).thenReturn(getBuilder);
when(getBuilder.accept(isA(String.class))).thenReturn(getBuilder);
when(getBuilder.disableRedirects()).thenReturn(getBuilder);
when(getBuilder.perform()).thenReturn(getResponse);
when(getResponse.getBody()).thenAnswer(new Answer<InputStream>() {
@Override
public InputStream answer(final InvocationOnMock invocation) throws Throwable {
return new ByteArrayInputStream(body.getBytes());
}
});
when(getResponse.getUrl()).thenReturn(uri);
when(getResponse.getLinkHeaders(eq("describedby"))).thenReturn(describedbyLinks);
when(getResponse.getStatusCode()).thenReturn(200);
when(getResponse.getLinkHeaders(eq("type"))).thenReturn(typeLinks);
}
示例12: getDatasetGraph
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
private Optional<DatasetGraph> getDatasetGraph(final String url) {
try (final FcrepoResponse head = headResource(url)) {
final List<URI> types = head.getLinkHeaders("type");
LOGGER.debug("Link headers: " + types);
if (types.contains(URI.create(LDP + "NonRDFSource"))) {
// Is this a NonRDFSource?
LOGGER.debug("Get NonRdfSource Description for: {}", url);
verifyNonRdfSourceDescription(head);
return Optional.empty();
} else {
// This is a container
LOGGER.debug("Get triples for: {}", url);
try (final FcrepoResponse get = getResource(url)) {
final Model model = createDefaultModel();
final Dataset d = new DatasetImpl(model.read(get.getBody(), "", TEXT_TURTLE));
return Optional.of(d.asDatasetGraph());
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: serviceLinkHeaderTest
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void serviceLinkHeaderTest() throws Exception {
final URI object = client.post(objectContainer).slug(testMethodName()).perform().getLocation();
attempt(60, () -> {
try (final FcrepoResponse response = client.get(
routing.of(REQUEST_URI).interceptUriFor(object)).perform()) {
assertEquals(1, response.getLinkHeaders("service").size());
assertEquals(routing.of(REQUEST_URI).serviceDocFor(object),
response.getLinkHeaders("service").get(0));
return true;
}
});
}
示例14: incomingInterceptRespomseCodeTest
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void incomingInterceptRespomseCodeTest() throws Exception {
registerExtension(testResource("objects/extension_InterceptingModalityIT.ttl"));
registerService(testResource("objects/service_InterceptingServiceIT.ttl"));
final String LOCATION = "http://example.org/Location";
final int RESPONSE_CODE = 418;
responseFromService.setHeader(Exchange.HTTP_RESPONSE_CODE, RESPONSE_CODE);
responseFromService.setHeader("Location", LOCATION);
final URI objectContainer_intercept = routing.of(REQUEST_URI).interceptUriFor(objectContainer);
final URI object = postFromTestResource("objects/object_InterceptingServiceIT.ttl",
objectContainer_intercept);
try (FcrepoResponse response = FcrepoClient.client().build().get(object).perform()) {
assertEquals(RESPONSE_CODE, response.getStatusCode());
assertEquals(LOCATION, response.getHeaderValue("Location"));
}
}
示例15: incomingInterceptHeaderResponseTest
import org.fcrepo.client.FcrepoResponse; //导入依赖的package包/类
@Test
public void incomingInterceptHeaderResponseTest() throws Exception {
registerExtension(testResource("objects/extension_InterceptingModalityIT.ttl"));
registerService(testResource("objects/service_InterceptingServiceIT.ttl"));
final URI objectContainer_intercept = routing.of(REQUEST_URI).interceptUriFor(objectContainer);
// Have our extension service set an implausible If-Match header for the request
onServiceRequest(ex -> {
if (MODALITY_INTERCEPT_INCOMING.equals(ex.getIn().getHeader(HTTP_HEADER_MODALITY))) {
ex.getOut().setHeader("foo", "bar");
ex.getOut().setBody(ex.getIn().getBody());
} else {
ex.setOut(ex.getIn());
}
});
final URI object = postFromTestResource("objects/object_InterceptingServiceIT.ttl",
objectContainer_intercept);
try (final FcrepoResponse response = client.get(object).accept("application/n-triples").perform()) {
final String body = IOUtils.toString(response.getBody(), "UTF-8");
assertTrue(body.contains(TEST_OBJECT_TYPE));
}
}