Java Code Examples for org.eclipse.rdf4j.repository.RepositoryException#getMessage()

The following examples show how to use org.eclipse.rdf4j.repository.RepositoryException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FedXConnection.java    From CostFed with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Add the specified endpoint to the federation. The endpoint must be initialized and
 * the federation must not contain a member with the same endpoint location.
 * 
 * @param e
 *          the initialized endpoint
 * @param updateStrategy
 *          optional parameter, to determine if strategy is to be updated, default=true
 * 
 * @throws FedXRuntimeException
 *           if the endpoint is not initialized, or if the federation has already a member with the
 *           same location  
 */
public void addEndpoint(Endpoint e, boolean ...updateStrategy) throws FedXRuntimeException {
    log.info("Adding endpoint " + e.getId() + " to federation ...");
    
    /* check if endpoint is initialized*/
    if (!e.isInitialized()) {
        try {
            e.initialize(strategy);
        } catch (RepositoryException e1){
            throw new FedXRuntimeException("Provided endpoint was not initialized and could not be initialized: " + e1.getMessage(), e1);
        }
    }
    
    /* check for duplicate before adding: heuristic => same location */
    for (Endpoint member : endpoints)
        if (member.getEndpoint().equals(e.getEndpoint()))
            throw new FedXRuntimeException("Adding failed: there exists already an endpoint with location " + e.getEndpoint() + " (eid=" + member.getId() + ")");

    endpoints.add(e);
    endpointManager.addEndpoint(e);
    
    if (updateStrategy==null || updateStrategy.length==0 || (updateStrategy.length==1 && updateStrategy[0]==true)) {
        updateStrategy();
    }
}
 
Example 2
Source File: SPARQLHttpRepoProvider.java    From CostFed with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Endpoint loadEndpoint(RepositoryInformation repoInfo) throws FedXException {

	try {
		HTTPRepository repo = new HTTPRepository(repoInfo.getLocation());
		repo.initialize();
		
		ProviderUtil.checkConnectionIfConfigured(config, repo);
		
		String location = repoInfo.getLocation();
		EndpointClassification epc = EndpointClassification.Remote;
				
		Endpoint res = new Endpoint(repoInfo.getId(), repoInfo.getName(), location, repoInfo.getType(), epc);
		res.setEndpointConfiguration(repoInfo.getEndpointConfiguration());
		res.setRepo(repo);
		
		return res;
	} catch (RepositoryException e) {
		throw new FedXException("Repository " + repoInfo.getId() + " could not be initialized: " + e.getMessage(), e);
	}
}
 
Example 3
Source File: SizeController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	ProtocolUtil.logRequestParameters(request);

	Map<String, Object> model = new HashMap<>();
	final boolean headersOnly = METHOD_HEAD.equals(request.getMethod());

	if (!headersOnly) {
		Repository repository = RepositoryInterceptor.getRepository(request);

		ValueFactory vf = repository.getValueFactory();
		Resource[] contexts = ProtocolUtil.parseContextParam(request, Protocol.CONTEXT_PARAM_NAME, vf);

		long size = -1;

		try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
			size = repositoryCon.size(contexts);
		} catch (RepositoryException e) {
			throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
		}
		model.put(SimpleResponseView.CONTENT_KEY, String.valueOf(size));
	}

	return new ModelAndView(SimpleResponseView.getInstance(), model);
}
 
Example 4
Source File: NamespaceController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ModelAndView getExportNamespaceResult(HttpServletRequest request, String prefix)
		throws ServerHTTPException, ClientHTTPException {
	try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
		String namespace = repositoryCon.getNamespace(prefix);

		if (namespace == null) {
			throw new ClientHTTPException(SC_NOT_FOUND, "Undefined prefix: " + prefix);
		}

		Map<String, Object> model = new HashMap<>();
		model.put(SimpleResponseView.CONTENT_KEY, namespace);

		return new ModelAndView(SimpleResponseView.getInstance(), model);
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
	}
}
 
Example 5
Source File: NamespaceController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ModelAndView getUpdateNamespaceResult(HttpServletRequest request, String prefix)
		throws IOException, ClientHTTPException, ServerHTTPException {
	String namespace = IOUtil.readString(request.getReader());
	namespace = namespace.trim();

	if (namespace.length() == 0) {
		throw new ClientHTTPException(SC_BAD_REQUEST, "No namespace name found in request body");
	}
	// FIXME: perform some sanity checks on the namespace string

	try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
		repositoryCon.setNamespace(prefix, namespace);
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
	}

	return new ModelAndView(EmptySuccessView.getInstance());
}
 
Example 6
Source File: GraphController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Delete data from the graph.
 */
private ModelAndView getDeleteDataResult(Repository repository, HttpServletRequest request,
		HttpServletResponse response) throws ClientHTTPException, ServerHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	IRI graph = getGraphName(request, vf);

	try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
		repositoryCon.clear(graph);

		return new ModelAndView(EmptySuccessView.getInstance());
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
	}
}
 
Example 7
Source File: NativeStoreProvider.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Endpoint loadEndpoint(RepositoryInformation repoInfo) throws FedXException {
	
	File store = FileUtil.getFileLocation(config, repoInfo.getLocation());
	
	if (!store.exists()){
		throw new FedXRuntimeException("Store does not exist at '" + repoInfo.getLocation() + ": " + store.getAbsolutePath() + "'.");
	}
	
	try {
		NativeStore ns = new NativeStoreExt(store);
		SailRepository repo = new SailRepository(ns);
		repo.initialize();
		
		ProviderUtil.checkConnectionIfConfigured(config, repo);
		
		Endpoint res = new Endpoint(repoInfo.getId(), repoInfo.getName(), repoInfo.getLocation(), repoInfo.getType(), EndpointClassification.Local);
		res.setEndpointConfiguration(repoInfo.getEndpointConfiguration());
		res.setRepo(repo);
		
		/*
		// register a federated service manager to deal with this endpoint
		SAILFederatedService federatedService = new SAILFederatedService(res);
		federatedService.initialize();
		FederatedServiceManager.getInstance().registerService(repoInfo.getName(), federatedService);
		*/
		
		return res;
	} catch (RepositoryException e) {
		throw new FedXException("Repository " + repoInfo.getId() + " could not be initialized: " + e.getMessage(), e);
	}
}
 
Example 8
Source File: SPARQLProvider.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Endpoint loadEndpoint(RepositoryInformation repoInfo) throws FedXException {

	try {
		SPARQLRepository repo = new SPARQLRepository(repoInfo.getLocation());
		if (httpClient != null) {
		    // repo.setHttpClient(httpClient);
		}
		repo.initialize();
		
		long rtime = ProviderUtil.checkConnectionIfConfigured(config, repo);
		if (rtime != 0) {
			rtime = ProviderUtil.checkConnectionIfConfigured(config, repo); // measure again
		}
		
		String location = repoInfo.getLocation();
		EndpointClassification epc = EndpointClassification.Remote;
		
		/*
		// register a federated service manager to deal with this endpoint
		SPARQLFederatedService federatedService = new SPARQLFederatedService(repoInfo.getLocation(), null);
		federatedService.initialize();
		FederatedServiceResolverImpl
		FederatedService Manager.getInstance().registerService(repoInfo.getName(), federatedService);
		*/
		
		Endpoint res = new Endpoint(repoInfo.getId(), repoInfo.getName(), location, repoInfo.getType(), epc);
		EndpointConfiguration ep = manipulateEndpointConfiguration(location, repoInfo.getEndpointConfiguration());
		res.setEndpointConfiguration(ep);
		res.setRepo(repo);
		res.setResponseTime(rtime);
		return res;
	} catch (RepositoryException e) {
		throw new FedXException("Repository " + repoInfo.getId() + " could not be initialized: " + e.getMessage(), e);
	}
}
 
Example 9
Source File: NamespacesController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ModelAndView getExportNamespacesResult(HttpServletRequest request, HttpServletResponse response)
		throws ClientHTTPException, ServerHTTPException {
	final boolean headersOnly = METHOD_HEAD.equals(request.getMethod());

	Map<String, Object> model = new HashMap<>();
	if (!headersOnly) {
		List<String> columnNames = Arrays.asList("prefix", "namespace");
		List<BindingSet> namespaces = new ArrayList<>();

		try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
			final ValueFactory vf = repositoryCon.getValueFactory();
			try {
				try (CloseableIteration<? extends Namespace, RepositoryException> iter = repositoryCon
						.getNamespaces()) {
					while (iter.hasNext()) {
						Namespace ns = iter.next();

						Literal prefix = vf.createLiteral(ns.getPrefix());
						Literal namespace = vf.createLiteral(ns.getName());

						BindingSet bindingSet = new ListBindingSet(columnNames, prefix, namespace);
						namespaces.add(bindingSet);
					}
				}
			} catch (RepositoryException e) {
				throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
			}
		}
		model.put(QueryResultView.QUERY_RESULT_KEY, new IteratingTupleQueryResult(columnNames, namespaces));
	}

	TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
			TupleQueryResultWriterRegistry.getInstance());

	model.put(QueryResultView.FILENAME_HINT_KEY, "namespaces");
	model.put(QueryResultView.HEADERS_ONLY, headersOnly);
	model.put(QueryResultView.FACTORY_KEY, factory);

	return new ModelAndView(TupleQueryResultView.getInstance(), model);
}
 
Example 10
Source File: NamespacesController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ModelAndView getClearNamespacesResult(HttpServletRequest request, HttpServletResponse response)
		throws ServerHTTPException {
	try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
		try {
			repositoryCon.clearNamespaces();
		} catch (RepositoryException e) {
			throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
		}

		return new ModelAndView(EmptySuccessView.getInstance());
	}
}
 
Example 11
Source File: NamespaceController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ModelAndView getRemoveNamespaceResult(HttpServletRequest request, String prefix)
		throws ServerHTTPException {
	try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
		repositoryCon.removeNamespace(prefix);
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
	}

	return new ModelAndView(EmptySuccessView.getInstance());
}
 
Example 12
Source File: StatementsController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Delete data from the repository.
 */
private ModelAndView getDeleteDataResult(Repository repository, HttpServletRequest request,
		HttpServletResponse response) throws ServerHTTPException, ClientHTTPException, HTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
	IRI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
	Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
	Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);

	try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) {
		repositoryCon.remove(subj, pred, obj, contexts);

		return new ModelAndView(EmptySuccessView.getInstance());
	} catch (RepositoryException e) {
		if (e.getCause() != null && e.getCause() instanceof HTTPException) {
			// custom signal from the backend, throw as HTTPException
			// directly
			// (see SES-1016).
			throw (HTTPException) e.getCause();
		} else {
			throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
		}
	}
}
 
Example 13
Source File: ContextsController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	Map<String, Object> model = new HashMap<>();
	TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
			TupleQueryResultWriterRegistry.getInstance());

	if (METHOD_GET.equals(request.getMethod())) {
		List<String> columnNames = Arrays.asList("contextID");
		List<BindingSet> contexts = new ArrayList<>();
		RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request);
		try {
			try (CloseableIteration<? extends Resource, RepositoryException> contextIter = repositoryCon
					.getContextIDs()) {
				while (contextIter.hasNext()) {
					BindingSet bindingSet = new ListBindingSet(columnNames, contextIter.next());
					contexts.add(bindingSet);
				}
			}
			model.put(QueryResultView.QUERY_RESULT_KEY, new IteratingTupleQueryResult(columnNames, contexts));
			model.put(QueryResultView.FILENAME_HINT_KEY, "contexts");
			model.put(QueryResultView.FACTORY_KEY, factory);
			model.put(QueryResultView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
			model.put(QueryResultView.CONNECTION_KEY, repositoryCon);

		} catch (RepositoryException e) {
			// normally the QueryResultView closes the connection, but not if an exception occurred
			repositoryCon.close();
			throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
		}
	}
	return new ModelAndView(TupleQueryResultView.getInstance(), model);
}
 
Example 14
Source File: RepositoryEndpointProvider.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Endpoint loadEndpoint(RepositoryInformation repoInfo)
		throws FedXException {

	try {
		boolean didInitialize = false;
		try {
			if (!repository.isInitialized()) {
				repository.init();
				didInitialize = true;
			}
		} finally {
			if (didInitialize) {
				repository.shutDown();
			}
		}

		EndpointBase res;

		if (repository.isInitialized()) {
			res = new RepositoryEndpoint(repoInfo, repoInfo.getLocation(), EndpointClassification.Remote,
					repository);
		} else {
			res = new ManagedRepositoryEndpoint(repoInfo, repoInfo.getLocation(), EndpointClassification.Remote,
					repository);
		}
		res.setEndpointConfiguration(repoInfo.getEndpointConfiguration());

		return res;
	} catch (RepositoryException e) {
		throw new FedXException("Repository " + repoInfo.getId() + " could not be initialized: " + e.getMessage(),
				e);
	}
}
 
Example 15
Source File: SPARQLProvider.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Endpoint loadEndpoint(SPARQLRepositoryInformation repoInfo)
		throws FedXException {

	try {
		SPARQLRepository repo = new SPARQLRepository(repoInfo.getLocation());
		HttpClientBuilder httpClientBuilder = HttpClients.custom()
				.useSystemProperties()
				.setMaxConnTotal(20)
				.setMaxConnPerRoute(20);
		((SharedHttpClientSessionManager) repo.getHttpClientSessionManager())
				.setHttpClientBuilder(httpClientBuilder);
		try {
			repo.init();
		} finally {
			repo.shutDown();
		}

		String location = repoInfo.getLocation();
		EndpointClassification epc = EndpointClassification.Remote;

		ManagedRepositoryEndpoint res = new ManagedRepositoryEndpoint(repoInfo, location, epc, repo);
		EndpointConfiguration ep = manipulateEndpointConfiguration(location, repoInfo.getEndpointConfiguration());
		res.setEndpointConfiguration(ep);

		return res;
	} catch (RepositoryException e) {
		throw new FedXException("Repository " + repoInfo.getId() + " could not be initialized: " + e.getMessage(),
				e);
	}
}
 
Example 16
Source File: RepositoryListController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	Map<String, Object> model = new HashMap<>();

	if (METHOD_GET.equals(request.getMethod())) {
		ValueFactory vf = SimpleValueFactory.getInstance();

		try {
			List<String> bindingNames = new ArrayList<>();
			List<BindingSet> bindingSets = new ArrayList<>();

			// Determine the repository's URI
			StringBuffer requestURL = request.getRequestURL();
			if (requestURL.charAt(requestURL.length() - 1) != '/') {
				requestURL.append('/');
			}
			String namespace = requestURL.toString();

			repositoryManager.getAllRepositoryInfos(false).forEach(info -> {
				QueryBindingSet bindings = new QueryBindingSet();
				bindings.addBinding("uri", vf.createIRI(namespace, info.getId()));
				bindings.addBinding("id", vf.createLiteral(info.getId()));
				if (info.getDescription() != null) {
					bindings.addBinding("title", vf.createLiteral(info.getDescription()));
				}
				bindings.addBinding("readable", vf.createLiteral(info.isReadable()));
				bindings.addBinding("writable", vf.createLiteral(info.isWritable()));
				bindingSets.add(bindings);
			});

			bindingNames.add("uri");
			bindingNames.add("id");
			bindingNames.add("title");
			bindingNames.add("readable");
			bindingNames.add("writable");
			model.put(QueryResultView.QUERY_RESULT_KEY, new IteratingTupleQueryResult(bindingNames, bindingSets));
		} catch (RepositoryException e) {
			throw new ServerHTTPException(e.getMessage(), e);
		}
	}

	TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
			TupleQueryResultWriterRegistry.getInstance());

	model.put(QueryResultView.FILENAME_HINT_KEY, "repositories");
	model.put(QueryResultView.FACTORY_KEY, factory);
	model.put(QueryResultView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));

	return new ModelAndView(TupleQueryResultView.getInstance(), model);
}