mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Backed out changeset 5d23ff274a2f
This commit is contained in:
@@ -35,13 +35,15 @@ package sonia.scm;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.multibindings.Multibinder;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.inject.servlet.RequestScoped;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.google.inject.throwingproviders.ThrowingProviderBinder;
|
||||
|
||||
import org.apache.shiro.authz.permission.PermissionResolver;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -50,6 +52,11 @@ import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.cache.GuavaCacheManager;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.filter.AdminSecurityFilter;
|
||||
import sonia.scm.filter.BaseUrlFilter;
|
||||
import sonia.scm.filter.GZipFilter;
|
||||
import sonia.scm.filter.MDCFilter;
|
||||
import sonia.scm.filter.SecurityFilter;
|
||||
import sonia.scm.group.DefaultGroupManager;
|
||||
import sonia.scm.group.GroupDAO;
|
||||
import sonia.scm.group.GroupManager;
|
||||
@@ -57,14 +64,20 @@ import sonia.scm.group.GroupManagerProvider;
|
||||
import sonia.scm.group.xml.XmlGroupDAO;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.net.URLHttpClient;
|
||||
import sonia.scm.plugin.DefaultPluginLoader;
|
||||
import sonia.scm.plugin.DefaultPluginManager;
|
||||
import sonia.scm.plugin.Plugin;
|
||||
import sonia.scm.plugin.PluginLoader;
|
||||
import sonia.scm.plugin.PluginManager;
|
||||
import sonia.scm.repository.ChangesetViewerUtil;
|
||||
import sonia.scm.repository.DefaultRepositoryManager;
|
||||
import sonia.scm.repository.DefaultRepositoryProvider;
|
||||
import sonia.scm.repository.HealthCheckContextListener;
|
||||
import sonia.scm.repository.LastModifiedUpdateListener;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryBrowserUtil;
|
||||
import sonia.scm.repository.RepositoryDAO;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.RepositoryManagerProvider;
|
||||
@@ -79,9 +92,15 @@ import sonia.scm.resources.ResourceManager;
|
||||
import sonia.scm.resources.ScriptResourceServlet;
|
||||
import sonia.scm.security.CipherHandler;
|
||||
import sonia.scm.security.CipherUtil;
|
||||
import sonia.scm.security.ConfigurableLoginAttemptHandler;
|
||||
import sonia.scm.security.DefaultKeyGenerator;
|
||||
import sonia.scm.security.DefaultSecuritySystem;
|
||||
import sonia.scm.security.EncryptionHandler;
|
||||
import sonia.scm.security.KeyGenerator;
|
||||
import sonia.scm.security.LoginAttemptHandler;
|
||||
import sonia.scm.security.MessageDigestEncryptionHandler;
|
||||
import sonia.scm.security.RepositoryPermissionResolver;
|
||||
import sonia.scm.security.SecurityContext;
|
||||
import sonia.scm.security.SecuritySystem;
|
||||
import sonia.scm.store.BlobStoreFactory;
|
||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
@@ -89,10 +108,16 @@ import sonia.scm.store.DataStoreFactory;
|
||||
import sonia.scm.store.FileBlobStoreFactory;
|
||||
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
||||
import sonia.scm.store.JAXBDataStoreFactory;
|
||||
import sonia.scm.store.JAXBConfigurationStoreFactory;
|
||||
import sonia.scm.store.JAXBStoreFactory;
|
||||
import sonia.scm.store.ListenableStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.template.DefaultEngine;
|
||||
import sonia.scm.template.FreemarkerTemplateEngine;
|
||||
import sonia.scm.template.FreemarkerTemplateHandler;
|
||||
import sonia.scm.template.MustacheTemplateEngine;
|
||||
import sonia.scm.template.TemplateEngine;
|
||||
import sonia.scm.template.TemplateEngineFactory;
|
||||
import sonia.scm.template.TemplateHandler;
|
||||
import sonia.scm.template.TemplateServlet;
|
||||
import sonia.scm.url.RestJsonUrlProvider;
|
||||
import sonia.scm.url.RestXmlUrlProvider;
|
||||
@@ -108,16 +133,21 @@ import sonia.scm.util.DebugServlet;
|
||||
import sonia.scm.util.ScmConfigurationUtil;
|
||||
import sonia.scm.web.cgi.CGIExecutorFactory;
|
||||
import sonia.scm.web.cgi.DefaultCGIExecutorFactory;
|
||||
import sonia.scm.web.filter.AutoLoginFilter;
|
||||
import sonia.scm.web.filter.LoggingFilter;
|
||||
import sonia.scm.web.security.AdministrationContext;
|
||||
import sonia.scm.web.security.ApiBasicAuthenticationFilter;
|
||||
import sonia.scm.web.security.AuthenticationManager;
|
||||
import sonia.scm.web.security.BasicSecurityContext;
|
||||
import sonia.scm.web.security.ChainAuthenticatonManager;
|
||||
import sonia.scm.web.security.DefaultAdministrationContext;
|
||||
import sonia.scm.web.security.WebSecurityContext;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.core.PackagesResourceConfig;
|
||||
import com.sun.jersey.api.core.ResourceConfig;
|
||||
import com.sun.jersey.api.json.JSONConfiguration;
|
||||
import com.sun.jersey.guice.JerseyServletModule;
|
||||
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||
|
||||
@@ -127,10 +157,6 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import sonia.scm.net.SSLContextProvider;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
@@ -140,16 +166,15 @@ import sonia.scm.net.ahc.JsonContentTransformer;
|
||||
import sonia.scm.net.ahc.XmlContentTransformer;
|
||||
import sonia.scm.schedule.QuartzScheduler;
|
||||
import sonia.scm.schedule.Scheduler;
|
||||
import sonia.scm.security.ConfigurableLoginAttemptHandler;
|
||||
import sonia.scm.security.LoginAttemptHandler;
|
||||
import sonia.scm.security.AuthorizationChangedEventProducer;
|
||||
import sonia.scm.security.XsrfProtectionFilter;
|
||||
import sonia.scm.web.UserAgentParser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class ScmServletModule extends JerseyServletModule
|
||||
public class ScmServletModule extends ServletModule
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -214,15 +239,11 @@ public class ScmServletModule extends JerseyServletModule
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param servletContext
|
||||
* @param pluginLoader
|
||||
* @param overrides
|
||||
*/
|
||||
ScmServletModule(ServletContext servletContext,
|
||||
DefaultPluginLoader pluginLoader, ClassOverrides overrides)
|
||||
ScmServletModule(DefaultPluginLoader pluginLoader, ClassOverrides overrides)
|
||||
{
|
||||
this.servletContext = servletContext;
|
||||
this.pluginLoader = pluginLoader;
|
||||
this.overrides = overrides;
|
||||
}
|
||||
@@ -242,24 +263,22 @@ public class ScmServletModule extends JerseyServletModule
|
||||
|
||||
bind(SCMContextProvider.class).toInstance(context);
|
||||
|
||||
ScmConfiguration config = getScmConfiguration();
|
||||
ScmConfiguration config = getScmConfiguration(context);
|
||||
CipherUtil cu = CipherUtil.getInstance();
|
||||
|
||||
|
||||
// bind repository provider
|
||||
ThrowingProviderBinder.create(binder()).bind(
|
||||
RepositoryProvider.class, Repository.class).to(
|
||||
DefaultRepositoryProvider.class).in(RequestScoped.class);
|
||||
|
||||
// bind servlet context
|
||||
bind(ServletContext.class).annotatedWith(Default.class).toInstance(
|
||||
servletContext);
|
||||
|
||||
// bind event api
|
||||
bind(ScmEventBus.class).toInstance(ScmEventBus.getInstance());
|
||||
|
||||
// bind core
|
||||
bind(ConfigurationStoreFactory.class, JAXBConfigurationStoreFactory.class);
|
||||
bind(ConfigurationEntryStoreFactory.class, JAXBConfigurationEntryStoreFactory.class);
|
||||
bind(StoreFactory.class, JAXBStoreFactory.class);
|
||||
bind(ListenableStoreFactory.class, JAXBStoreFactory.class);
|
||||
bind(ConfigurationEntryStoreFactory.class,
|
||||
JAXBConfigurationEntryStoreFactory.class);
|
||||
bind(DataStoreFactory.class, JAXBDataStoreFactory.class);
|
||||
bind(BlobStoreFactory.class, FileBlobStoreFactory.class);
|
||||
bind(ScmConfiguration.class).toInstance(config);
|
||||
@@ -272,20 +291,24 @@ public class ScmServletModule extends JerseyServletModule
|
||||
// note CipherUtil uses an other generator
|
||||
bind(KeyGenerator.class).to(DefaultKeyGenerator.class);
|
||||
bind(CipherHandler.class).toInstance(cu.getCipherHandler());
|
||||
bind(EncryptionHandler.class, MessageDigestEncryptionHandler.class);
|
||||
bind(FileSystem.class, DefaultFileSystem.class);
|
||||
|
||||
// bind health check stuff
|
||||
bind(HealthCheckContextListener.class);
|
||||
|
||||
// bind extensions
|
||||
pluginLoader.getExtensionProcessor().processAutoBindExtensions(binder());
|
||||
pluginLoader.processExtensions(binder());
|
||||
|
||||
// bind security stuff
|
||||
bind(LoginAttemptHandler.class).to(ConfigurableLoginAttemptHandler.class);
|
||||
bind(AuthorizationChangedEventProducer.class);
|
||||
|
||||
bind(PermissionResolver.class, RepositoryPermissionResolver.class);
|
||||
bind(AuthenticationManager.class, ChainAuthenticatonManager.class);
|
||||
bind(SecurityContext.class).to(BasicSecurityContext.class);
|
||||
bind(WebSecurityContext.class).to(BasicSecurityContext.class);
|
||||
bind(SecuritySystem.class).to(DefaultSecuritySystem.class);
|
||||
bind(AdministrationContext.class, DefaultAdministrationContext.class);
|
||||
bind(LoginAttemptHandler.class, ConfigurableLoginAttemptHandler.class);
|
||||
|
||||
// bind cache
|
||||
bind(CacheManager.class, GuavaCacheManager.class);
|
||||
@@ -303,10 +326,14 @@ public class ScmServletModule extends JerseyServletModule
|
||||
bindDecorated(GroupManager.class, DefaultGroupManager.class,
|
||||
GroupManagerProvider.class);
|
||||
bind(CGIExecutorFactory.class, DefaultCGIExecutorFactory.class);
|
||||
bind(ChangesetViewerUtil.class);
|
||||
bind(RepositoryBrowserUtil.class);
|
||||
|
||||
// bind sslcontext provider
|
||||
bind(SSLContext.class).toProvider(SSLContextProvider.class);
|
||||
|
||||
// bind httpclient
|
||||
bind(HttpClient.class, URLHttpClient.class);
|
||||
|
||||
// bind ahc
|
||||
Multibinder<ContentTransformer> transformers =
|
||||
@@ -351,7 +378,24 @@ public class ScmServletModule extends JerseyServletModule
|
||||
{
|
||||
filter(PATTERN_ALL).through(LoggingFilter.class);
|
||||
}
|
||||
|
||||
// protect api agains xsrf attacks
|
||||
filter(PATTERN_RESTAPI).through(XsrfProtectionFilter.class);
|
||||
|
||||
/*
|
||||
* filter(PATTERN_PAGE,
|
||||
* PATTERN_STATIC_RESOURCES).through(StaticResourceFilter.class);
|
||||
*/
|
||||
filter(PATTERN_ALL).through(BaseUrlFilter.class);
|
||||
filter(PATTERN_ALL).through(AutoLoginFilter.class);
|
||||
filterRegex(RESOURCE_REGEX).through(GZipFilter.class);
|
||||
filter(PATTERN_RESTAPI, PATTERN_DEBUG).through(ApiBasicAuthenticationFilter.class);
|
||||
filter(PATTERN_RESTAPI, PATTERN_DEBUG).through(SecurityFilter.class);
|
||||
filter(PATTERN_CONFIG, PATTERN_ADMIN).through(AdminSecurityFilter.class);
|
||||
|
||||
// added mdcs for logging
|
||||
filter(PATTERN_ALL).through(MDCFilter.class);
|
||||
|
||||
// debug servlet
|
||||
serve(PATTERN_DEBUG).with(DebugServlet.class);
|
||||
|
||||
@@ -359,21 +403,23 @@ public class ScmServletModule extends JerseyServletModule
|
||||
serve(PATTERN_PLUGIN_SCRIPT).with(ScriptResourceServlet.class);
|
||||
|
||||
// template
|
||||
bind(TemplateHandler.class).to(FreemarkerTemplateHandler.class);
|
||||
serve(PATTERN_INDEX, "/").with(TemplateServlet.class);
|
||||
|
||||
Multibinder<TemplateEngine> engineBinder =
|
||||
Multibinder.newSetBinder(binder(), TemplateEngine.class);
|
||||
|
||||
engineBinder.addBinding().to(MustacheTemplateEngine.class);
|
||||
bind(TemplateEngine.class).annotatedWith(Default.class).to(
|
||||
engineBinder.addBinding().to(FreemarkerTemplateEngine.class);
|
||||
bind(TemplateEngine.class).annotatedWith(DefaultEngine.class).to(
|
||||
MustacheTemplateEngine.class);
|
||||
bind(TemplateEngineFactory.class);
|
||||
|
||||
// bind events
|
||||
// bind(LastModifiedUpdateListener.class);
|
||||
bind(LastModifiedUpdateListener.class);
|
||||
|
||||
// jersey
|
||||
Map<String, String> params = Maps.newHashMap();
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
||||
/*
|
||||
* params.put("com.sun.jersey.spi.container.ContainerRequestFilters",
|
||||
@@ -386,17 +432,63 @@ public class ScmServletModule extends JerseyServletModule
|
||||
params.put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE.toString());
|
||||
params.put(ResourceConfig.FEATURE_REDIRECT, Boolean.TRUE.toString());
|
||||
params.put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE.toString());
|
||||
|
||||
/*
|
||||
* TODO remove UriExtensionsConfig and PackagesResourceConfig
|
||||
* to stop jersey classpath scanning
|
||||
*/
|
||||
params.put(ServletContainer.RESOURCE_CONFIG_CLASS,
|
||||
UriExtensionsConfig.class.getName());
|
||||
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "unbound");
|
||||
|
||||
String restPath = getRestPackages();
|
||||
logger.info("configure jersey with package path: {}", restPath);
|
||||
|
||||
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, restPath);
|
||||
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param packageSet
|
||||
* @param plugin
|
||||
*/
|
||||
private void appendPluginPackages(Set<String> packageSet, Plugin plugin)
|
||||
{
|
||||
Set<String> pluginPackageSet = plugin.getPackageSet();
|
||||
|
||||
if (pluginPackageSet != null)
|
||||
{
|
||||
for (String pluginPkg : pluginPackageSet)
|
||||
{
|
||||
boolean append = true;
|
||||
|
||||
for (String pkg : packageSet)
|
||||
{
|
||||
if (pluginPkg.startsWith(pkg))
|
||||
{
|
||||
append = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (append)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String name = "unknown";
|
||||
|
||||
if (plugin.getInformation() != null)
|
||||
{
|
||||
name = plugin.getInformation().getName();
|
||||
}
|
||||
|
||||
logger.debug("plugin {} added rest path {}", name, pluginPkg);
|
||||
}
|
||||
|
||||
packageSet.add(pluginPkg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -484,6 +576,44 @@ public class ScmServletModule extends JerseyServletModule
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getRestPackages()
|
||||
{
|
||||
Set<String> packageSet = new HashSet<String>();
|
||||
|
||||
packageSet.add(SCMContext.DEFAULT_PACKAGE);
|
||||
|
||||
Collection<Plugin> plugins = pluginLoader.getInstalledPlugins();
|
||||
|
||||
if (plugins != null)
|
||||
{
|
||||
for (Plugin plugin : plugins)
|
||||
{
|
||||
appendPluginPackages(packageSet, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
Iterator<String> pkgIterator = packageSet.iterator();
|
||||
|
||||
while (pkgIterator.hasNext())
|
||||
{
|
||||
buffer.append(pkgIterator.next());
|
||||
|
||||
if (pkgIterator.hasNext())
|
||||
{
|
||||
buffer.append(";");
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load ScmConfiguration with JAXB
|
||||
*
|
||||
@@ -492,7 +622,7 @@ public class ScmServletModule extends JerseyServletModule
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ScmConfiguration getScmConfiguration()
|
||||
private ScmConfiguration getScmConfiguration(SCMContextProvider context)
|
||||
{
|
||||
ScmConfiguration configuration = new ScmConfiguration();
|
||||
|
||||
@@ -504,11 +634,8 @@ public class ScmServletModule extends JerseyServletModule
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final ClassOverrides overrides;
|
||||
private ClassOverrides overrides;
|
||||
|
||||
/** Field description */
|
||||
private final DefaultPluginLoader pluginLoader;
|
||||
|
||||
/** Field description */
|
||||
private final ServletContext servletContext;
|
||||
private DefaultPluginLoader pluginLoader;
|
||||
}
|
||||
|
||||
@@ -42,50 +42,65 @@ import sonia.scm.template.TemplateEngineFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.view.Viewable;
|
||||
import com.sun.jersey.spi.template.ViewProcessor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.ext.MessageBodyWriter;
|
||||
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import sonia.scm.template.Viewable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Provider
|
||||
public class TemplateEngineViewable implements MessageBodyWriter<Viewable>
|
||||
public class TemplateEngineViewable implements ViewProcessor<String>
|
||||
{
|
||||
|
||||
private final TemplateEngineFactory templateEngineFactory;
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param templateEngineFactory
|
||||
*/
|
||||
@Inject
|
||||
public TemplateEngineViewable(TemplateEngineFactory templateEngineFactory)
|
||||
{
|
||||
this.templateEngineFactory = templateEngineFactory;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||
return type.isAssignableFrom(Viewable.class);
|
||||
public String resolve(String name)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
* @param viewable
|
||||
* @param out
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public long getSize(Viewable viewable, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(Viewable viewable, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
|
||||
String path = viewable.getPath();
|
||||
|
||||
public void writeTo(String path, Viewable viewable, OutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
TemplateEngine engine = templateEngineFactory.getEngineByExtension(path);
|
||||
|
||||
if (engine == null)
|
||||
@@ -100,9 +115,14 @@ public class TemplateEngineViewable implements MessageBodyWriter<Viewable>
|
||||
throw new IOException("could not find template for ".concat(path));
|
||||
}
|
||||
|
||||
PrintWriter writer = new PrintWriter(entityStream);
|
||||
PrintWriter writer = new PrintWriter(out);
|
||||
|
||||
template.execute(writer, viewable.getContext());
|
||||
template.execute(writer, viewable.getModel());
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private TemplateEngineFactory templateEngineFactory;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.api.rest;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.core.PackagesResourceConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class UriExtensionsConfig extends PackagesResourceConfig
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String EXTENSION_JSON = "json";
|
||||
|
||||
/** Field description */
|
||||
public static final String EXTENSION_XML = "xml";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public UriExtensionsConfig()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param props
|
||||
*/
|
||||
public UriExtensionsConfig(Map<String, Object> props)
|
||||
{
|
||||
super(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param paths
|
||||
*/
|
||||
public UriExtensionsConfig(String[] paths)
|
||||
{
|
||||
super(paths);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, MediaType> getMediaTypeMappings()
|
||||
{
|
||||
if (mediaTypeMap == null)
|
||||
{
|
||||
mediaTypeMap = new HashMap<String, MediaType>();
|
||||
mediaTypeMap.put(EXTENSION_JSON, MediaType.APPLICATION_JSON_TYPE);
|
||||
mediaTypeMap.put(EXTENSION_XML, MediaType.APPLICATION_XML_TYPE);
|
||||
}
|
||||
|
||||
return mediaTypeMap;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Map<String, MediaType> mediaTypeMap;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public abstract class AbstractPermissionResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response add(@Context UriInfo uriInfo, Permission permission)
|
||||
{
|
||||
AssignedPermission ap = transformPermission(permission);
|
||||
@@ -185,7 +185,7 @@ public abstract class AbstractPermissionResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response update(@PathParam("id") String id, Permission permission)
|
||||
{
|
||||
StoredAssignedPermission sap = getPermission(id);
|
||||
@@ -213,7 +213,7 @@ public abstract class AbstractPermissionResource
|
||||
@ResponseCode(code = 404, condition = "not found, no permission with the specified id available"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Permission get(@PathParam("id") String id)
|
||||
{
|
||||
StoredAssignedPermission sap = getPermission(id);
|
||||
@@ -231,7 +231,7 @@ public abstract class AbstractPermissionResource
|
||||
@ResponseCode(code = 204, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public List<Permission> getAll()
|
||||
{
|
||||
return getPermissions(getPredicate());
|
||||
|
||||
@@ -118,7 +118,7 @@ public class ChangePasswordResource
|
||||
@ResponseCode(code = 400, condition = "bad request, the old password is not correct"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response changePassword(@FormParam("old-password") String oldPassword,
|
||||
@FormParam("new-password") String newPassword)
|
||||
throws UserException, IOException
|
||||
|
||||
@@ -89,7 +89,7 @@ public class ConfigurationResource
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response getConfiguration()
|
||||
{
|
||||
Response response = null;
|
||||
@@ -118,7 +118,7 @@ public class ConfigurationResource
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response setConfig(@Context UriInfo uriInfo,
|
||||
ScmConfiguration newConfig)
|
||||
{
|
||||
|
||||
@@ -119,7 +119,7 @@ public class GroupResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response create(@Context UriInfo uriInfo, Group group)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ public class GroupResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response update(@Context UriInfo uriInfo,
|
||||
@PathParam("id") String name, Group group)
|
||||
@@ -191,7 +191,7 @@ public class GroupResource
|
||||
@ResponseCode(code = 404, condition = "not found, no group with the specified id/name available"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response get(@Context Request request, @PathParam("id") String id)
|
||||
{
|
||||
@@ -221,7 +221,7 @@ public class GroupResource
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@TypeHint(Group[].class)
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
|
||||
@@ -52,6 +52,7 @@ import sonia.scm.plugin.PluginInformationComparator;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||
@@ -65,7 +66,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
@@ -124,9 +124,9 @@ public class PluginResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response install(
|
||||
/*@FormParam("package")*/ InputStream uploadedInputStream)
|
||||
@FormDataParam("package") InputStream uploadedInputStream)
|
||||
throws IOException
|
||||
{
|
||||
Response response = null;
|
||||
@@ -194,7 +194,7 @@ public class PluginResource
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
public Response installFromUI(
|
||||
/*@FormParam("package")*/ InputStream uploadedInputStream)
|
||||
@FormDataParam("package") InputStream uploadedInputStream)
|
||||
throws IOException
|
||||
{
|
||||
return install(uploadedInputStream);
|
||||
@@ -257,7 +257,7 @@ public class PluginResource
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Collection<PluginInformation> getAll()
|
||||
{
|
||||
return pluginManager.getAll();
|
||||
@@ -274,7 +274,7 @@ public class PluginResource
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Collection<PluginInformation> getAvailable()
|
||||
{
|
||||
return pluginManager.getAvailable();
|
||||
@@ -291,7 +291,7 @@ public class PluginResource
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Collection<PluginInformation> getAvailableUpdates()
|
||||
{
|
||||
return pluginManager.getAvailableUpdates();
|
||||
@@ -325,7 +325,7 @@ public class PluginResource
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Collection<PluginInformation> getOverview()
|
||||
{
|
||||
//J-
|
||||
|
||||
@@ -69,6 +69,8 @@ import static com.google.common.base.Preconditions.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||
@@ -87,7 +89,6 @@ import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
@@ -110,7 +111,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
// @Path("import/repositories")
|
||||
@Path("import/repositories")
|
||||
public class RepositoryImportResource
|
||||
{
|
||||
|
||||
@@ -169,8 +170,8 @@ public class RepositoryImportResource
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Response importFromBundle(@Context UriInfo uriInfo,
|
||||
@PathParam("type") String type, @FormParam("name") String name,
|
||||
@FormParam("bundle") InputStream inputStream, @QueryParam("compressed")
|
||||
@PathParam("type") String type, @FormDataParam("name") String name,
|
||||
@FormDataParam("bundle") InputStream inputStream, @QueryParam("compressed")
|
||||
@DefaultValue("false") boolean compressed)
|
||||
{
|
||||
Repository repository = doImportFromBundle(type, name, inputStream,
|
||||
@@ -210,8 +211,8 @@ public class RepositoryImportResource
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
public Response importFromBundleUI(@PathParam("type") String type,
|
||||
@FormParam("name") String name,
|
||||
@FormParam("bundle") InputStream inputStream, @QueryParam("compressed")
|
||||
@FormDataParam("name") String name,
|
||||
@FormDataParam("bundle") InputStream inputStream, @QueryParam("compressed")
|
||||
@DefaultValue("false") boolean compressed)
|
||||
{
|
||||
Response response;
|
||||
@@ -259,7 +260,7 @@ public class RepositoryImportResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response importFromUrl(@Context UriInfo uriInfo,
|
||||
@PathParam("type") String type, UrlImportRequest request)
|
||||
{
|
||||
@@ -319,7 +320,7 @@ public class RepositoryImportResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(Repository[].class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response importRepositories(@PathParam("type") String type)
|
||||
{
|
||||
SecurityUtils.getSubject().checkRole(Role.ADMIN);
|
||||
@@ -351,7 +352,7 @@ public class RepositoryImportResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(Repository[].class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response importRepositories()
|
||||
{
|
||||
SecurityUtils.getSubject().checkRole(Role.ADMIN);
|
||||
@@ -393,7 +394,7 @@ public class RepositoryImportResource
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(ImportResult.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response importRepositoriesFromDirectory(
|
||||
@PathParam("type") String type)
|
||||
{
|
||||
@@ -434,7 +435,7 @@ public class RepositoryImportResource
|
||||
.warn(
|
||||
"import feature is not supported by repository handler for type "
|
||||
.concat(type), ex);
|
||||
response = Response.status(Response.Status.BAD_REQUEST).build();
|
||||
response = Response.status(Status.BAD_REQUEST).build();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@@ -450,7 +451,7 @@ public class RepositoryImportResource
|
||||
else
|
||||
{
|
||||
logger.warn("could not find reposiotry handler for type {}", type);
|
||||
response = Response.status(Response.Status.BAD_REQUEST).build();
|
||||
response = Response.status(Status.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
return response;
|
||||
@@ -474,7 +475,7 @@ public class RepositoryImportResource
|
||||
),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response getImportableTypes()
|
||||
{
|
||||
SecurityUtils.getSubject().checkRole(Role.ADMIN);
|
||||
|
||||
@@ -166,7 +166,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response create(@Context UriInfo uriInfo, Repository repository)
|
||||
{
|
||||
@@ -296,7 +296,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response update(@Context UriInfo uriInfo, @PathParam("id") String id, Repository repository)
|
||||
{
|
||||
@@ -315,7 +315,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
*/
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 404, condition = "not found, no repository with the specified id available"),
|
||||
@@ -340,7 +340,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
* @return all repositories
|
||||
*/
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
@@ -377,7 +377,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(BlameResult.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response getBlame(@PathParam("id") String id,
|
||||
@QueryParam("revision") String revision, @QueryParam("path") String path)
|
||||
throws RepositoryException, IOException
|
||||
@@ -449,7 +449,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(Branches.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response getBranches(@PathParam("id") String id)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
@@ -511,7 +511,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(BrowserResult.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
//J-
|
||||
public Response getBrowserResult(
|
||||
@PathParam("id") String id,
|
||||
@@ -591,7 +591,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(Repository.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response getByTypeAndName(@PathParam("type") String type,
|
||||
@PathParam("name") String name)
|
||||
{
|
||||
@@ -632,7 +632,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(Changeset.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response getChangeset(@PathParam("id") String id,
|
||||
@PathParam("revision") String revision)
|
||||
throws IOException, RepositoryException
|
||||
@@ -708,7 +708,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(ChangesetPagingResult.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
//J-
|
||||
public Response getChangesets(
|
||||
@PathParam("id") String id,
|
||||
@@ -948,7 +948,7 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(Tags.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response getTags(@PathParam("id") String id)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
|
||||
@@ -50,6 +50,8 @@ import sonia.scm.util.HttpUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.view.Viewable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -65,7 +67,6 @@ import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import sonia.scm.template.Viewable;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -75,13 +76,17 @@ import sonia.scm.template.Viewable;
|
||||
public class RepositoryRootResource
|
||||
{
|
||||
|
||||
private static final String TEMPLATE = "/templates/repository-root.mustache";
|
||||
/** Field description */
|
||||
public static final String TEMPLATE = "/templates/repository-root.mustache";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
private final RepositoryManager repositoryManager;
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param templateHandler
|
||||
* @param repositoryManager
|
||||
*/
|
||||
@Inject
|
||||
@@ -325,4 +330,10 @@ public class RepositoryRootResource
|
||||
/** Field description */
|
||||
private UrlProvider urlProvider;
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private RepositoryManager repositoryManager;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ public class SearchResource implements UserListener, GroupListener
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public SearchResults searchGroups(@QueryParam("query") String queryString)
|
||||
{
|
||||
return groupSearchHandler.search(queryString,
|
||||
@@ -189,7 +189,7 @@ public class SearchResource implements UserListener, GroupListener
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public SearchResults searchUsers(@QueryParam("query") String queryString)
|
||||
{
|
||||
return userSearchHandler.search(queryString,
|
||||
|
||||
@@ -125,7 +125,7 @@ public class UserResource extends AbstractManagerResource<User, UserException>
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response create(@Context UriInfo uriInfo, User user)
|
||||
{
|
||||
@@ -170,7 +170,7 @@ public class UserResource extends AbstractManagerResource<User, UserException>
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response update(@Context UriInfo uriInfo,
|
||||
@PathParam("id") String name, User user)
|
||||
@@ -197,7 +197,7 @@ public class UserResource extends AbstractManagerResource<User, UserException>
|
||||
@ResponseCode(code = 404, condition = "not found, no group with the specified id/name available"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response get(@Context Request request, @PathParam("id") String id)
|
||||
{
|
||||
@@ -233,7 +233,7 @@ public class UserResource extends AbstractManagerResource<User, UserException>
|
||||
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@Override
|
||||
public Response getAll(@Context Request request, @DefaultValue("0")
|
||||
@QueryParam("start") int start, @DefaultValue("-1")
|
||||
|
||||
@@ -67,7 +67,7 @@ public final class DebugResource
|
||||
* @return all received hook data for the given repository
|
||||
*/
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
||||
public Collection<DebugHookData> getAll(@PathParam("repository") String repository){
|
||||
return debugService.getAll(repository);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public final class DebugResource
|
||||
*/
|
||||
@GET
|
||||
@Path("last")
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
||||
public DebugHookData getLast(@PathParam("repository") String repository){
|
||||
return debugService.getLast(repository);
|
||||
}
|
||||
|
||||
@@ -33,16 +33,14 @@ package sonia.scm.net.ahc;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.fasterxml.jackson.databind.AnnotationIntrospector;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
|
||||
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
|
||||
|
||||
import com.google.common.io.ByteSource;
|
||||
|
||||
import org.codehaus.jackson.map.AnnotationIntrospector;
|
||||
import org.codehaus.jackson.map.DeserializationConfig;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
|
||||
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
|
||||
|
||||
import sonia.scm.plugin.ext.Extension;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
@@ -75,12 +73,12 @@ public class JsonContentTransformer implements ContentTransformer
|
||||
|
||||
// allow jackson and jaxb annotations
|
||||
AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();
|
||||
AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
|
||||
AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
|
||||
|
||||
this.mapper.setAnnotationIntrospector(new AnnotationIntrospectorPair(jackson, jaxb));
|
||||
this.mapper.setAnnotationIntrospector(new AnnotationIntrospector.Pair(jackson, jaxb));
|
||||
|
||||
// do not fail on unknown json properties
|
||||
this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
this.mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user