@Override public List<URI> getChildren(URI resource) { try (final FcrepoResponse response = client.get(resource) .accept("application/n-triples") .preferRepresentation(asList(PREFER_CONTAINMENT), emptyList()).perform()) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getBody(), UTF_8))) { final List<URI> children = new ArrayList<>(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { final Matcher aclFinder = childPattern.matcher(line); if (aclFinder.matches()) { children.add(URI.create(aclFinder.group(1))); } } return children; } } catch (final Exception e) { throw new RuntimeException("Error getting children of " + resource, e); } } }
/** * Retrieve the resource location from a HEAD request. */ private URI getMetadataUri(final String url) throws FcrepoOperationFailedException { final FcrepoResponse headResponse = fcrepoClient.head(URI.create(url)).perform(); if (headResponse.getLocation() != null) { return headResponse.getLocation(); } else { return URI.create(url); } }
/** * Get the client * * @return the client constructed by this builder */ public FcrepoClient build() { return new FcrepoClient(authUser, authPassword, authHost, throwExceptionOnFailure); } }
response = fcrepoClient.patch(getMetadataUri(url)).body(in.getBody(InputStream.class)).perform(); exchange.getIn().setBody(extractResponseBodyAsStream(response.getBody(), exchange)); break; case PUT: response = fcrepoClient.put(URI.create(url)).body(in.getBody(InputStream.class), contentType).perform(); exchange.getIn().setBody(extractResponseBodyAsStream(response.getBody(), exchange)); break; case POST: response = fcrepoClient.post(URI.create(url)).body(in.getBody(InputStream.class), contentType).perform(); exchange.getIn().setBody(extractResponseBodyAsStream(response.getBody(), exchange)); break; case DELETE: response = fcrepoClient.delete(URI.create(url)).perform(); exchange.getIn().setBody(extractResponseBodyAsStream(response.getBody(), exchange)); break; case HEAD: response = fcrepoClient.head(URI.create(url)).perform(); exchange.getIn().setBody(null); break; case GET: default: final GetBuilder get = fcrepoClient.get(getUri(endpoint, url)).accept(accept); final String preferHeader = in.getHeader(FCREPO_PREFER, "", String.class); if (!preferHeader.isEmpty()) {
/** * @param destinationURI URI * @param resourceFile ByteArrayInputStream * @param contentType String * @throws ModellerClientFailedException Throwable */ public static void doStreamPut(final URI destinationURI, final ByteArrayInputStream resourceFile, final String contentType) throws ModellerClientFailedException { final FcrepoClient testClient; testClient = FcrepoClient.client().throwExceptionOnFailure().build(); try { final FcrepoResponse response = testClient.put(destinationURI).body(resourceFile, contentType).perform(); log.info(String.valueOf(response.getStatusCode())); } catch (FcrepoOperationFailedException e) { log.info(getMessage(e)); throw new ModellerClientFailedException(e); } }
/** * @param containerURI URI * @return resources * @throws ModellerClientFailedException Throwable */ public static String doGetContainerResources(final URI containerURI) throws ModellerClientFailedException { final FcrepoClient testClient; testClient = FcrepoClient.client().throwExceptionOnFailure().build(); try (FcrepoResponse response = testClient.get(containerURI).accept("text/turtle").perform()) { return IOUtils.toString(response.getBody(), "UTF-8"); } catch (FcrepoOperationFailedException e) { log.info(getMessage(e)); throw new ModellerClientFailedException(e); } catch (IOException e) { e.printStackTrace(); } return null; } }
private FcrepoClient getClient() { if (fcrepoClient == null) { return client().credentials(authUsername, authPassword).authScope(authHost) .throwExceptionOnFailure().build(); } return fcrepoClient; } }
/** * @param destinationURI URI * @param rdfBody InputStream * @throws ModellerClientFailedException Throwable */ public static void doPatch(final URI destinationURI, final InputStream rdfBody) throws ModellerClientFailedException { final FcrepoClient testClient; testClient = FcrepoClient.client().throwExceptionOnFailure().build(); try { final FcrepoResponse response = testClient.patch(destinationURI).body(rdfBody).perform(); log.info(String.valueOf(response.getStatusCode())); } catch (FcrepoOperationFailedException e) { log.info(getMessage(e)); throw new ModellerClientFailedException(e); } }
roleBase = ofNullable(root.get("role-base").asText()).map(URI::create).orElse(null); try (FcrepoResponse response = client.head(getAclBase()).perform()) { if (response.getStatusCode() == 404) { try (FcrepoResponse createResp = client.put(getAclBase()).perform()) { System.err.println(createResp.getStatusCode()); try (FcrepoResponse response = client.head(container).perform()) { if (response.getStatusCode() == 404) { try (FcrepoResponse putResponse = client.put(container).perform()) { if (!(putResponse.getStatusCode() < 299)) { System.out.println(IOUtils.toString(putResponse.getBody(), UTF_8));
/** * @param destinationURI URI * @throws ModellerClientFailedException Throwable */ public static void doPut(final URI destinationURI) throws ModellerClientFailedException { final FcrepoClient testClient; testClient = FcrepoClient.client().throwExceptionOnFailure().build(); try { final FcrepoResponse response = testClient.put(destinationURI).perform(); try { log.info(IOUtils.toString(response.getBody(), UTF_8)); } catch (IOException e) { log.info(getMessage(e)); } } catch (FcrepoOperationFailedException e) { log.info(getMessage(e)); throw new ModellerClientFailedException(e); } }
/** * Instantiates default implementations of the underlying Fedora client, JSON adapter, and OkHttpClient. */ public FedoraPassCrudClient() { this(FcrepoClient.client() .credentials(FedoraConfig.getUserName(), FedoraConfig.getPassword()) .throwExceptionOnFailure() .build(), new PassJsonAdapterBasic()); }
/** * @param destinationURI URI * @param resourceFile File * @param contentType String * @throws ModellerClientFailedException Throwable */ public static void doBinaryPut(final URI destinationURI, final File resourceFile, final String contentType) throws ModellerClientFailedException { final FcrepoClient testClient; testClient = FcrepoClient.client().throwExceptionOnFailure().build(); try { final FcrepoResponse response = testClient.put(destinationURI).body(resourceFile, contentType).perform(); log.info(String.valueOf(response.getStatusCode())); } catch (FcrepoOperationFailedException e) { log.info(getMessage(e)); throw new ModellerClientFailedException(e); } catch (IOException e) { e.printStackTrace(); } }
/** * Instantiates default implementations of the underlying Fedora client, JSON adapter, and OkHttpClient. */ public FedoraPassCrudClient() { this(FcrepoClient.client() .credentials(FedoraConfig.getUserName(), FedoraConfig.getPassword()) .throwExceptionOnFailure() .build(), new PassJsonAdapterBasic()); }
@Override public List<URI> getChildren(URI resource) { try (final FcrepoResponse response = client.get(resource) .accept("application/n-triples") .preferRepresentation(asList(PREFER_CONTAINMENT), emptyList()).perform()) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getBody(), UTF_8))) { final List<URI> children = new ArrayList<>(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { final Matcher aclFinder = childPattern.matcher(line); if (aclFinder.matches()) { children.add(URI.create(aclFinder.group(1))); } } return children; } } catch (final Exception e) { throw new RuntimeException("Error getting children of " + resource, e); } } }
/** * Create a FcrepoProducer object * * @param endpoint the FcrepoEndpoint corresponding to the exchange. */ public FcrepoProducer(final FcrepoEndpoint endpoint) { super(endpoint); this.endpoint = endpoint; this.transactionTemplate = endpoint.createTransactionTemplate(); final FcrepoClient.FcrepoClientBuilder builder = client() .credentials(endpoint.getAuthUsername(), endpoint.getAuthPassword()) .authScope(endpoint.getAuthHost()); if (endpoint.getThrowExceptionOnFailure()) { this.fcrepoClient = builder.throwExceptionOnFailure().build(); } else { this.fcrepoClient = builder.build(); } }