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

The following examples show how to use org.openrdf.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: NamespaceHandler.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param prefix the prefix
 * @return the SimpleResponseView which will return the namesapce
 * @throws ServerHTTPException throws when there is error about the repository
 * @throws ClientHTTPException throws when there is undefined prefix
 */
private ModelAndView getExportNamespaceResult(final Repository repository, final HttpServletRequest request, final String prefix)
		throws ServerHTTPException, ClientHTTPException {
	try {
		String namespace = null;

		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			namespace = repositoryCon.getNamespace(prefix);
		}

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

		Map<String, Object> model = new HashMap<String, Object>();
		model.put(SimpleResponseView.CONTENT_KEY, namespace);
		repositoryCon.close();
		return new ModelAndView(SimpleResponseView.getInstance(), model);
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
	}
}
 
Example 2
Source File: NamespaceHandler.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * update the namespace.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param prefix the prefix
 * @return EmptySuccessView object if success
 * @throws IOException throws if there is error reading the namespace from the HttpServletRequest
 * @throws ClientHTTPException throws if No namespace name found in request body
 * @throws ServerHTTPException throws when there is error about the repository
 */
private ModelAndView getUpdateNamespaceResult(final Repository repository, final HttpServletRequest request, final 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");
	}

	try {
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			repositoryCon.setNamespace(prefix, namespace);
		}
		repositoryCon.close();
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
	}

	return new ModelAndView(EmptySuccessView.getInstance());
}
 
Example 3
Source File: GraphHandler.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Delete data from the graph.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param response the HttpServletResponse object
 * @return the EmptySuccessView if successes
 * @throws ClientHTTPException throws when there are errors in getting the name of the Graph
 * @throws ServerHTTPException throws when errors happens update the data
 */
private ModelAndView getDeleteDataResult(final Repository repository,
		final HttpServletRequest request, final HttpServletResponse response)
		throws ClientHTTPException, ServerHTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	URI graph = getGraphName(request, vf);

	try {
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			repositoryCon.clear(graph);
		}
		repositoryCon.close();
		return new ModelAndView(EmptySuccessView.getInstance());
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
	}
}
 
Example 4
Source File: SizeHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws Exception {
	ProtocolUtil.logRequestParameters(request);

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

	if (!headersOnly) {

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

		long size = -1;

		try {
			RepositoryConnection repositoryCon = repository.getConnection();
			synchronized (repositoryCon) {
				size = repositoryCon.size(contexts);
			}
			repositoryCon.close();
		} 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 5
Source File: NamespacesHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * clear the namespaces
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object 
 * @param response the HttpServletResponse oject
 * @return EmptySuccessView object if success
 * @throws ServerHTTPException throws when errors in repository
 * @throws RepositoryException throws when errors in closing the RepositoryConnection 
 */
private ModelAndView getClearNamespacesResult(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws ServerHTTPException, RepositoryException {
	RepositoryConnection repositoryCon = repository.getConnection();
	synchronized (repositoryCon) {
		try {
			repositoryCon.clearNamespaces();
		} catch (RepositoryException e) {
			throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
		}
	}
	repositoryCon.close();
	return new ModelAndView(EmptySuccessView.getInstance());
}
 
Example 6
Source File: NamespaceHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * remove the namespace.
 * 
 *@param repository the Repository object
 * @param request the HttpServletRequest object
 * @param prefix the prefix
 * @return EmptySuccessView object if successvletRequest
 * @throws ServerHTTPException throws when there is error about the repository
 */
private ModelAndView getRemoveNamespaceResult(final Repository repository, final HttpServletRequest request, final String prefix)
		throws ServerHTTPException {
	try {
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			repositoryCon.removeNamespace(prefix);
		}
		repositoryCon.close();
	} catch (RepositoryException e) {
		throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
	}

	return new ModelAndView(EmptySuccessView.getInstance());
}
 
Example 7
Source File: StatementHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Delete data from the repository.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param response the HttpServletResponse object
 * @return EmptySuccessView if success
 * @throws HTTPException throws when there are repository update errors
 */
private ModelAndView getDeleteDataResult(final Repository repository, final HttpServletRequest request,
		final HttpServletResponse response)
		throws HTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
	URI 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 = repository.getConnection();
		synchronized (repositoryCon) {
			repositoryCon.remove(subj, pred, obj, contexts);
		}
		repositoryCon.close();
		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 8
Source File: ContextsHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws Exception {
	Map<String, Object> model = new HashMap<String, Object>();
	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<BindingSet>();
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			try {
				CloseableIteration<? extends Resource, RepositoryException> contextIter = repositoryCon.getContextIDs();

				try {
					while (contextIter.hasNext()) {
						BindingSet bindingSet = new ListBindingSet(columnNames, contextIter.next());
						contexts.add(bindingSet);
					}
				} finally {
					contextIter.close();
				}
			} catch (RepositoryException e) {
				throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
			}
		}
		model.put(QueryResultView.QUERY_RESULT_KEY, new TupleQueryResultImpl(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()));
	return new ModelAndView(TupleQueryResultView.getInstance(), model);
}
 
Example 9
Source File: RepositoryListHandler.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws Exception {
	Map<String, Object> model = new HashMap<String, Object>();

	if (METHOD_GET.equals(request.getMethod())) {
		Repository systemRepository = _repositoryManager.getSystemRepository();
		ValueFactory vf = systemRepository.getValueFactory();

		try {
			RepositoryConnection con = systemRepository.getConnection();
			try {
				// connection before returning. Would be much better to stream the query result directly to the client.

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

				TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL,
						REPOSITORY_LIST_QUERY).evaluate();
				try {
					// Determine the repository's URI
					StringBuffer requestURL = request.getRequestURL();
					if (requestURL.charAt(requestURL.length() - 1) != '/') {
						requestURL.append('/');
					}
					String namespace = requestURL.toString();

					while (queryResult.hasNext()) {
						QueryBindingSet bindings = new QueryBindingSet(queryResult.next());

						String id = bindings.getValue("id").stringValue();
						bindings.addBinding("uri", vf.createURI(namespace, id));

						bindingSets.add(bindings);
					}

					bindingNames.add("uri");
					bindingNames.addAll(queryResult.getBindingNames());
				} finally {
					queryResult.close();
				}
				model.put(QueryResultView.QUERY_RESULT_KEY,
						new TupleQueryResultImpl(bindingNames, bindingSets));

			} finally {
				con.close();
			}
		} 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);
}
 
Example 10
Source File: NamespacesHandler.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object 
 * @param response the HttpServletResponse oject
 * @return QueryResultView object include the namespaces
 * @throws ClientHTTPException throws when errors in the request
 * @throws ServerHTTPException throws when errors in the Repository
 * @throws RepositoryException throws when errors in closing the RepositoryConnection 
 */
private ModelAndView getExportNamespacesResult(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
		throws ClientHTTPException, ServerHTTPException, RepositoryException {
	final boolean headersOnly = METHOD_HEAD.equals(request.getMethod());

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

		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			try {
				CloseableIteration<? extends Namespace, RepositoryException> iter = repositoryCon.getNamespaces();

				try {
					while (iter.hasNext()) {
						Namespace ns = iter.next();

						Literal prefix = new LiteralImpl(ns.getPrefix());
						Literal namespace = new LiteralImpl(ns.getName());

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

	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);
}