--- /dev/null
+package org.apache.archiva.repository.api;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * InvalidOperationException
+ */
+public class InvalidOperationException extends RepositoryManagerException
+{
+ public InvalidOperationException(String message)
+ {
+ super(message);
+ }
+
+ public InvalidOperationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public InvalidOperationException(Throwable cause)
+ {
+ super(cause.getMessage(), cause);
+ }
+}
}
return result;
}
- return Collections.EMPTY_LIST;
}
- return null;
+ return Collections.EMPTY_LIST;
}
}
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import org.apache.archiva.repository.api.InvalidOperationException;
import org.apache.archiva.repository.api.MutableResourceContext;
import org.apache.archiva.repository.api.RepositoryManager;
-import org.apache.archiva.repository.api.RepositoryManagerException;
import org.apache.archiva.repository.api.RepositoryManagerWeight;
import org.apache.archiva.repository.api.ResourceContext;
import org.apache.archiva.repository.api.Status;
public boolean write(ResourceContext context, InputStream is)
{
- throw new RepositoryManagerException("Repository Groups are not writable: " + context.getRepositoryId());
+ throw new InvalidOperationException("Repository Groups are not writable: " + context.getRepositoryId());
}
public List<Status> stat(ResourceContext context)
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.archiva.repository.api.InvalidOperationException;
import org.apache.archiva.repository.api.ResourceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private void handleRequest(final HttpServletRequest req, final HttpServletResponse resp)
- throws IOException
+ throws IOException, ServletException
{
log.debug("Request started");
HttpRepositoryContext context = new HttpRepositoryContext(req, resp);
log.debug("Running PreRepositoryInterceptors");
executePreRepositoryInterceptors(context);
log.debug("Executing Repository Manager");
- runRepositoryManager(context, req, resp);
+ try
+ {
+ runRepositoryManager(context, req, resp);
+ }
+ catch (InvalidOperationException e)
+ {
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, e.getMessage());
+ }
log.debug("Running PostRepositoryInterceptors");
executePostRepositoryInterceptors(context);
log.debug("Request Completed");
if (withBody)
{
- repositoryManager.read(context, resp.getOutputStream());
+ if (!repositoryManager.read(context, resp.getOutputStream()))
+ {
+ resp.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
}
}
}