use of javax.jcr.NoSuchWorkspaceException in project jackrabbit by apache.
the class NodeTest method testGetCorrespondingNodePathNoSuchWorkspaceException.
/**
* Calls {@link javax.jcr.Node#getCorrespondingNodePath(String )} with a non
* existing workspace.
* <p>
* This should throw an {@link javax.jcr.NoSuchWorkspaceException }.
*/
public void testGetCorrespondingNodePathNoSuchWorkspaceException() throws RepositoryException {
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create testNode in default workspace
Node defaultTestNode = defaultRootNode.addNode(nodeName1, testNodeType);
// save changes
superuser.save();
try {
defaultTestNode.getCorrespondingNodePath(getNonExistingWorkspaceName(superuser));
fail("Calling Node.getCorrespondingNodePath(workspace) with invalid workspace should throw NoSuchWorkspaceException");
} catch (NoSuchWorkspaceException e) {
// ok, works as expected
}
}
use of javax.jcr.NoSuchWorkspaceException in project jackrabbit by apache.
the class ConnectionFactoryTest method testExceptionHandling.
/**
* Tests if a NoSuchWorkspaceException is thrown if a wrong workspace name is given to login
*/
public void testExceptionHandling() throws Exception {
Object cf = mcf.createConnectionFactory();
Repository repository = (Repository) cf;
try {
repository.login(JCR_SUPERUSER, "xxx");
} catch (Exception e) {
assertTrue(e instanceof NoSuchWorkspaceException);
}
}
use of javax.jcr.NoSuchWorkspaceException in project jackrabbit by apache.
the class AbstractLoginFilter method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
try {
Credentials credentials = getCredentials(httpRequest);
Session session = repository.login(credentials, workspace);
try {
request.setAttribute(sessionAttribute, session);
request.setAttribute(nodeAttribute, session.getRootNode());
chain.doFilter(request, response);
if (session.hasPendingChanges()) {
session.save();
}
} finally {
session.logout();
}
} catch (ServletException e) {
Throwable cause = e.getRootCause();
if (cause instanceof AccessDeniedException) {
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN, cause.getMessage());
} else {
throw e;
}
} catch (LoginException e) {
httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
} catch (NoSuchWorkspaceException e) {
throw new ServletException("Workspace " + workspace + " not found in the content repository", e);
} catch (RepositoryException e) {
throw new ServletException("Unable to access the content repository", e);
}
}
use of javax.jcr.NoSuchWorkspaceException in project jackrabbit-oak by apache.
the class OakServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
Credentials credentials = null;
String authorization = request.getHeader("Authorization");
if (authorization != null && authorization.startsWith("Basic ")) {
String[] basic = Base64.decode(authorization.substring("Basic ".length())).split(":");
credentials = new SimpleCredentials(basic[0], basic[1].toCharArray());
} else {
throw new LoginException();
}
ContentSession session = repository.login(credentials, null);
try {
Root root = session.getLatestRoot();
request.setAttribute("root", root);
// Find the longest part of the given path that matches
// an existing node. The tail part might be used when
// creating new nodes or when exposing virtual resources.
// Note that we need to traverse the path in reverse
// direction as some parent nodes may be read-protected.
String head = request.getPathInfo();
String tail = "";
Tree tree = root.getTree(head);
while (!tree.exists()) {
if (tree.isRoot()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
tail = "/" + tree.getName() + tail;
tree = tree.getParent();
}
request.setAttribute("tree", tree);
request.setAttribute("path", tail);
super.service(request, response);
} finally {
session.close();
}
} catch (NoSuchWorkspaceException e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (LoginException e) {
response.setHeader("WWW-Authenticate", "Basic realm=\"Oak\"");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
use of javax.jcr.NoSuchWorkspaceException in project jackrabbit by apache.
the class DavSessionProviderImpl method attachSession.
/**
* Acquires a DavSession. Upon success, the WebdavRequest will
* reference that session.
*
* A session will not be available if an exception is thrown.
*
* @param request
* @throws org.apache.jackrabbit.webdav.DavException if a problem occurred while obtaining the session
* @see DavSessionProvider#attachSession(org.apache.jackrabbit.webdav.WebdavRequest)
*/
public boolean attachSession(WebdavRequest request) throws DavException {
try {
// retrieve the workspace name
String workspaceName = request.getRequestLocator().getWorkspaceName();
// empty workspaceName rather means default -> must be 'null'
if (workspaceName != null && "".equals(workspaceName)) {
workspaceName = null;
}
// login to repository
Session repSession = sesProvider.getSession(request, repository, workspaceName);
if (repSession == null) {
log.debug("Could not to retrieve a repository session.");
return false;
}
DavSession ds = new DavSessionImpl(repSession);
log.debug("Attaching session '" + ds + "' to request '" + request + "'");
request.setDavSession(ds);
return true;
} catch (NoSuchWorkspaceException e) {
// which seems not appropriate here
throw new JcrDavException(e, DavServletResponse.SC_NOT_FOUND);
} catch (RepositoryException e) {
throw new JcrDavException(e);
} catch (ServletException e) {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
}
Aggregations