mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
remove deprecations and fixed some compiler warnings
This commit is contained in:
@@ -1,139 +0,0 @@
|
||||
/**
|
||||
* 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.net;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple client for http operations.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses sonia.scm.net.HttpRequest
|
||||
* @apiviz.uses sonia.scm.net.HttpResponse
|
||||
*
|
||||
* @deprecated use {@link sonia.scm.net.ahc.AdvancedHttpClient} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface HttpClient
|
||||
{
|
||||
|
||||
/**
|
||||
* Send a post request to the given url.
|
||||
*
|
||||
*
|
||||
* @param url url for post request
|
||||
*
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse post(String url) throws IOException;
|
||||
|
||||
/**
|
||||
* Sends a post request with the parameter specified in the
|
||||
* {@link HttpRequest} object.
|
||||
*
|
||||
*
|
||||
* @param request request object
|
||||
*
|
||||
* @return the response of the http request
|
||||
* @since 1.9
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse post(HttpRequest request) throws IOException;
|
||||
|
||||
/**
|
||||
* Send a post request to the given url with the specified post parameters.
|
||||
*
|
||||
*
|
||||
* @param url url for post request
|
||||
* @param parameters parameters for the post request
|
||||
*
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse post(String url, Map<String, List<String>> parameters)
|
||||
throws IOException;
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Send a get request to the given url.
|
||||
*
|
||||
*
|
||||
* @param url url for get request
|
||||
*
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse get(String url) throws IOException;
|
||||
|
||||
/**
|
||||
* Sends a get request with the parameter specified in the
|
||||
* {@link HttpRequest} object.
|
||||
*
|
||||
*
|
||||
* @param request request object
|
||||
*
|
||||
* @return the response of the http request
|
||||
* @since 1.9
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse get(HttpRequest request) throws IOException;
|
||||
|
||||
/**
|
||||
* Send a get request to the given url with the specified post parameters.
|
||||
*
|
||||
*
|
||||
* @param url url for get request
|
||||
* @param parameters parameters for the get request
|
||||
*
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse get(String url, Map<String, List<String>> parameters)
|
||||
throws IOException;
|
||||
}
|
||||
@@ -1,387 +0,0 @@
|
||||
/**
|
||||
* 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.net;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import sonia.scm.util.AssertUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Http request which can be executed by the {@link HttpClient}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.9
|
||||
*
|
||||
* @deprecated use {@link sonia.scm.net.ahc.AdvancedHttpRequest} or
|
||||
* {@link sonia.scm.net.ahc.AdvancedHttpRequestWithBody} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class HttpRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs a new HttpRequest.
|
||||
*
|
||||
*
|
||||
* @param url url for the request
|
||||
*/
|
||||
public HttpRequest(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add a http header for the request.
|
||||
*
|
||||
*
|
||||
* @param name name of the request header
|
||||
* @param values values of the request header
|
||||
*
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest addHeader(String name, String... values)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(name);
|
||||
|
||||
if (headers == null)
|
||||
{
|
||||
headers = new HashMap<String, List<String>>();
|
||||
}
|
||||
|
||||
appendValues(headers, name, values);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a parameter to the request.
|
||||
*
|
||||
*
|
||||
* @param name name of the parameter
|
||||
* @param values values of the parameter
|
||||
*
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest addParameters(String name, String... values)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(name);
|
||||
|
||||
if (parameters == null)
|
||||
{
|
||||
parameters = new HashMap<String, List<String>>();
|
||||
}
|
||||
|
||||
appendValues(parameters, name, values);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return a map with http headers used for the request.
|
||||
*
|
||||
*
|
||||
* @return map with http headers
|
||||
*/
|
||||
public Map<String, List<String>> getHeaders()
|
||||
{
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a map with http parameters for the request.
|
||||
*
|
||||
*
|
||||
* @return map with http parameters
|
||||
*/
|
||||
public Map<String, List<String>> getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password for http basic authentication.
|
||||
*
|
||||
*
|
||||
* @return password for http basic authentication
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the url for the request.
|
||||
*
|
||||
*
|
||||
* @return url of the request
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username for http basic authentication.
|
||||
*
|
||||
*
|
||||
* @return username for http basic authentication
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the request decodes gzip compression.
|
||||
*
|
||||
*
|
||||
* @return true if the request decodes gzip compression
|
||||
*
|
||||
* @since 1.14
|
||||
*/
|
||||
public boolean isDecodeGZip()
|
||||
{
|
||||
return decodeGZip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the verification of ssl certificates is disabled.
|
||||
*
|
||||
*
|
||||
* @return true if certificate verification is disabled
|
||||
* @since 1.17
|
||||
*/
|
||||
public boolean isDisableCertificateValidation()
|
||||
{
|
||||
return disableCertificateValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the ssl hostname validation is disabled.
|
||||
*
|
||||
*
|
||||
* @return true if the ssl hostname validation is disabled
|
||||
* @since 1.17
|
||||
*/
|
||||
public boolean isDisableHostnameValidation()
|
||||
{
|
||||
return disableHostnameValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the proxy settings are ignored.
|
||||
*
|
||||
*
|
||||
* @return true if the proxy settings are ignored
|
||||
* @since 1.17
|
||||
*/
|
||||
public boolean isIgnoreProxySettings()
|
||||
{
|
||||
return ignoreProxySettings;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Enabled http basic authentication.
|
||||
*
|
||||
*
|
||||
* @param username username for http basic authentication
|
||||
* @param password password for http basic authentication
|
||||
*
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest setBasicAuthentication(String username, String password)
|
||||
{
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disabled gzip decoding. The default value is false.
|
||||
*
|
||||
*
|
||||
* @param decodeGZip true to enable gzip decoding
|
||||
*
|
||||
* @return {@code this}
|
||||
*
|
||||
* @since 1.14
|
||||
*/
|
||||
public HttpRequest setDecodeGZip(boolean decodeGZip)
|
||||
{
|
||||
this.decodeGZip = decodeGZip;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable certificate validation of ssl certificates. The default
|
||||
* value is false.
|
||||
*
|
||||
*
|
||||
* @param disableCertificateValidation true to disable certificate validation
|
||||
* @since 1.17
|
||||
*/
|
||||
public void setDisableCertificateValidation(
|
||||
boolean disableCertificateValidation)
|
||||
{
|
||||
this.disableCertificateValidation = disableCertificateValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the validation of ssl hostnames. The default value is
|
||||
* false.
|
||||
*
|
||||
*
|
||||
* @param disableHostnameValidation true to disable ssl hostname validation
|
||||
* @since 1.17
|
||||
*/
|
||||
public void setDisableHostnameValidation(boolean disableHostnameValidation)
|
||||
{
|
||||
this.disableHostnameValidation = disableHostnameValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set http headers for the request.
|
||||
*
|
||||
*
|
||||
* @param headers headers for the request
|
||||
*
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest setHeaders(Map<String, List<String>> headers)
|
||||
{
|
||||
this.headers = headers;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore proxy settings. The default value is false.
|
||||
*
|
||||
*
|
||||
* @param ignoreProxySettings true to ignore proxy settings.
|
||||
* @since 1.17
|
||||
*/
|
||||
public void setIgnoreProxySettings(boolean ignoreProxySettings)
|
||||
{
|
||||
this.ignoreProxySettings = ignoreProxySettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set http parameters for the request.
|
||||
*
|
||||
*
|
||||
* @param parameters parameters for the request
|
||||
*
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest setParameters(Map<String, List<String>> parameters)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Append values to map.
|
||||
*
|
||||
*
|
||||
* @param map map to append values
|
||||
* @param name name of the key
|
||||
* @param values values to append
|
||||
*/
|
||||
private void appendValues(Map<String, List<String>> map, String name,
|
||||
String[] values)
|
||||
{
|
||||
List<String> valueList = map.get(name);
|
||||
|
||||
if (valueList == null)
|
||||
{
|
||||
valueList = Lists.newArrayList();
|
||||
map.put(name, valueList);
|
||||
}
|
||||
|
||||
if (values != null)
|
||||
{
|
||||
valueList.addAll(Arrays.asList(values));
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** map of request headers */
|
||||
private Map<String, List<String>> headers;
|
||||
|
||||
/** ignore proxy settings */
|
||||
private boolean ignoreProxySettings = false;
|
||||
|
||||
/** disable ssl hostname validation */
|
||||
private boolean disableHostnameValidation = false;
|
||||
|
||||
/** disable ssl certificate validation */
|
||||
private boolean disableCertificateValidation = false;
|
||||
|
||||
/** decode gzip */
|
||||
private boolean decodeGZip = false;
|
||||
|
||||
/** map of parameters */
|
||||
private Map<String, List<String>> parameters;
|
||||
|
||||
/** password for http basic authentication */
|
||||
private String password;
|
||||
|
||||
/** url for the request */
|
||||
private String url;
|
||||
|
||||
/** username for http basic authentication */
|
||||
private String username;
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* 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.net;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import sonia.scm.net.ahc.AdvancedHttpResponse;
|
||||
|
||||
/**
|
||||
* Response of a {@link HttpRequest} execute by the {@link HttpClient}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @deprecated use {@link AdvancedHttpResponse} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface HttpResponse extends Closeable
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the response body as stream.
|
||||
*
|
||||
*
|
||||
* @return response body as stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream getContent() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the response body as string.
|
||||
*
|
||||
*
|
||||
* @return response body as string
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public String getContentAsString() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the value of the first response header with the given name.
|
||||
*
|
||||
*
|
||||
* @param name name of the response header
|
||||
*
|
||||
* @return value of the first response header with the given name
|
||||
*/
|
||||
public String getHeader(String name);
|
||||
|
||||
/**
|
||||
* Returns a map with all response headers.
|
||||
*
|
||||
*
|
||||
* @return map with all response headers
|
||||
*/
|
||||
public Map<String, List<String>> getHeaderMap();
|
||||
|
||||
/**
|
||||
* Returns the status code of the response.
|
||||
*
|
||||
*
|
||||
* @return status code
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public int getStatusCode() throws IOException;
|
||||
}
|
||||
@@ -68,20 +68,6 @@ public final class Branch implements Serializable
|
||||
*/
|
||||
public Branch() {}
|
||||
|
||||
/**
|
||||
* Constructs a new branch.
|
||||
*
|
||||
*
|
||||
* @param name name of the branch
|
||||
*
|
||||
* @deprecated use {@link Branch#Branch(String, String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Branch(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new branch.
|
||||
*
|
||||
|
||||
@@ -377,7 +377,7 @@ public final class GitUtil
|
||||
|
||||
try
|
||||
{
|
||||
Ref ref = repo.getRef(branchName);
|
||||
Ref ref = repo.findRef(branchName);
|
||||
|
||||
if (ref != null)
|
||||
{
|
||||
|
||||
@@ -216,13 +216,13 @@ public abstract class AbstractGitIncomingOutgoingCommand
|
||||
|
||||
if (localBranch != null)
|
||||
{
|
||||
ref = repository.getRef(GitUtil.getScmRemoteRefName(remoteRepository,
|
||||
ref = repository.findRef(GitUtil.getScmRemoteRefName(remoteRepository,
|
||||
localBranch));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ref = repository.getRef(GitUtil.getScmRemoteRefName(remoteRepository,
|
||||
ref = repository.findRef(GitUtil.getScmRemoteRefName(remoteRepository,
|
||||
"master"));
|
||||
|
||||
if (ref == null)
|
||||
|
||||
@@ -43,6 +43,8 @@ import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -64,29 +66,18 @@ public class GitBranchCommand implements BranchCommand
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public Branch branch(String name) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
git.branchCreate().setName(name).call();
|
||||
Ref ref = git.branchCreate().setName(name).call();
|
||||
return new Branch(name, GitUtil.getId(ref.getObjectId()));
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryClientException("could not create branch", ex);
|
||||
}
|
||||
|
||||
return new Branch(name);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -57,8 +57,6 @@ 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.PluginLoader;
|
||||
@@ -137,7 +135,6 @@ 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.XsrfProtectionFilter;
|
||||
import sonia.scm.web.UserAgentParser;
|
||||
|
||||
/**
|
||||
@@ -298,8 +295,6 @@ public class ScmServletModule extends JerseyServletModule
|
||||
// bind sslcontext provider
|
||||
bind(SSLContext.class).toProvider(SSLContextProvider.class);
|
||||
|
||||
// bind httpclient
|
||||
bind(HttpClient.class, URLHttpClient.class);
|
||||
|
||||
// bind ahc
|
||||
Multibinder<ContentTransformer> transformers =
|
||||
|
||||
@@ -1,669 +0,0 @@
|
||||
/**
|
||||
* 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.net;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.core.util.Base64;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @deprecated use {@link sonia.scm.net.ahc.AdvancedHttpClient}
|
||||
*/
|
||||
@Deprecated
|
||||
public class URLHttpClient implements HttpClient
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String CREDENTIAL_SEPARATOR = ":";
|
||||
|
||||
/** Field description */
|
||||
public static final String ENCODING = "UTF-8";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_ACCEPT_ENCODING_VALUE = "gzip";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_AUTHORIZATION = "Authorization";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_USERAGENT = "User-Agent";
|
||||
|
||||
/** Field description */
|
||||
public static final String HEADER_USERAGENT_VALUE = "SCM-Manager ";
|
||||
|
||||
/** Field description */
|
||||
public static final String METHOD_POST = "POST";
|
||||
|
||||
/** Field description */
|
||||
public static final String PREFIX_BASIC_AUTHENTICATION = "Basic ";
|
||||
|
||||
/** Field description */
|
||||
public static final int TIMEOUT_CONNECTION = 30000;
|
||||
|
||||
/** Field description */
|
||||
public static final int TIMEOUT_RAED = 1200000;
|
||||
|
||||
/** the logger for URLHttpClient */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(URLHttpClient.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param configuration
|
||||
*/
|
||||
@Inject
|
||||
public URLHttpClient(SCMContextProvider context,
|
||||
ScmConfiguration configuration)
|
||||
{
|
||||
this.context = context;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse post(String url) throws IOException
|
||||
{
|
||||
HttpURLConnection connection = (HttpURLConnection) openConnection(null,
|
||||
url);
|
||||
|
||||
connection.setRequestMethod(METHOD_POST);
|
||||
// send empty content-length
|
||||
// see issue #701 http://goo.gl/oyTdrA
|
||||
setContentLength(connection, 0);
|
||||
|
||||
return new URLHttpResponse(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param parameters
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse post(String url, Map<String, List<String>> parameters)
|
||||
throws IOException
|
||||
{
|
||||
HttpURLConnection connection = (HttpURLConnection) openConnection(null,
|
||||
url);
|
||||
|
||||
connection.setRequestMethod(METHOD_POST);
|
||||
appendPostParameter(connection, parameters);
|
||||
|
||||
return new URLHttpResponse(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse post(HttpRequest request) throws IOException
|
||||
{
|
||||
HttpURLConnection connection = (HttpURLConnection) openConnection(request,
|
||||
request.getUrl());
|
||||
|
||||
connection.setRequestMethod(METHOD_POST);
|
||||
appendPostParameter(connection, request.getParameters());
|
||||
|
||||
return new URLHttpResponse(connection);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param spec
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse get(String spec) throws IOException
|
||||
{
|
||||
return new URLHttpResponse(openConnection(null, spec));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param parameters
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse get(String url, Map<String, List<String>> parameters)
|
||||
throws IOException
|
||||
{
|
||||
url = createGetUrl(url, parameters);
|
||||
|
||||
return new URLHttpResponse(openConnection(null, url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse get(HttpRequest request) throws IOException
|
||||
{
|
||||
String url = createGetUrl(request.getUrl(), request.getParameters());
|
||||
|
||||
return new URLHttpResponse(openConnection(request, url),
|
||||
request.isDecodeGZip());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param connection
|
||||
* @param header
|
||||
* @param username
|
||||
* @param password
|
||||
*/
|
||||
private void appendBasicAuthHeader(HttpURLConnection connection,
|
||||
String header, String username, String password)
|
||||
{
|
||||
if (Util.isNotEmpty(username) || Util.isNotEmpty(password))
|
||||
{
|
||||
username = Util.nonNull(username);
|
||||
password = Util.nonNull(password);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("append {} header for user {}", header, username);
|
||||
}
|
||||
|
||||
String auth = username.concat(CREDENTIAL_SEPARATOR).concat(password);
|
||||
|
||||
auth = new String(Base64.encode(auth.getBytes()));
|
||||
connection.addRequestProperty(header,
|
||||
PREFIX_BASIC_AUTHENTICATION.concat(auth));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param headers
|
||||
* @param connection
|
||||
*/
|
||||
private void appendHeaders(Map<String, List<String>> headers,
|
||||
URLConnection connection)
|
||||
{
|
||||
if (Util.isNotEmpty(headers))
|
||||
{
|
||||
for (Map.Entry<String, List<String>> e : headers.entrySet())
|
||||
{
|
||||
String name = e.getKey();
|
||||
List<String> values = e.getValue();
|
||||
|
||||
if (Util.isNotEmpty(name) && Util.isNotEmpty(values))
|
||||
{
|
||||
for (String value : values)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("append header {}:{}", name, value);
|
||||
}
|
||||
|
||||
connection.setRequestProperty(name, value);
|
||||
}
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("value of {} header is empty", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("header map is emtpy");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param connection
|
||||
* @param parameters
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void appendPostParameter(HttpURLConnection connection,
|
||||
Map<String, List<String>> parameters)
|
||||
throws IOException
|
||||
{
|
||||
if (Util.isNotEmpty(parameters))
|
||||
{
|
||||
// use a ByteArrayOutputStream in order to get the final content-length
|
||||
// see issue #701 http://goo.gl/oyTdrA
|
||||
connection.setDoOutput(true);
|
||||
|
||||
OutputStreamWriter writer = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
|
||||
try
|
||||
{
|
||||
baos = new ByteArrayOutputStream();
|
||||
writer = new OutputStreamWriter(baos);
|
||||
|
||||
appendPostParameters(writer, parameters);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(writer);
|
||||
IOUtil.close(baos);
|
||||
}
|
||||
|
||||
if ( baos != null ){
|
||||
byte[] data = baos.toByteArray();
|
||||
appendBody(connection, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setContentLength(connection, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendBody(HttpURLConnection connection, byte[] body) throws IOException
|
||||
{
|
||||
int length = body.length;
|
||||
logger.trace("write {} bytes to output", length);
|
||||
setContentLength(connection, length);
|
||||
connection.setFixedLengthStreamingMode(length);
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = connection.getOutputStream();
|
||||
os.write(body);
|
||||
} finally {
|
||||
IOUtil.close(os);
|
||||
}
|
||||
}
|
||||
|
||||
private void setContentLength(HttpURLConnection connection, int length)
|
||||
{
|
||||
connection.setRequestProperty(HttpUtil.HEADER_CONTENT_LENGTH, String.valueOf(length));
|
||||
}
|
||||
|
||||
private void appendPostParameters(OutputStreamWriter writer, Map<String, List<String>> parameters) throws IOException
|
||||
{
|
||||
Iterator<Map.Entry<String, List<String>>> it = parameters.entrySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry<String, List<String>> p = it.next();
|
||||
List<String> values = p.getValue();
|
||||
|
||||
if (Util.isNotEmpty(values))
|
||||
{
|
||||
String key = encode(p.getKey());
|
||||
|
||||
Iterator<String> valueIt = values.iterator();
|
||||
|
||||
while(valueIt.hasNext())
|
||||
{
|
||||
String value = valueIt.next();
|
||||
writer.append(key).append("=").append(encode(value));
|
||||
if ( valueIt.hasNext() ){
|
||||
writer.write("&");
|
||||
}
|
||||
}
|
||||
|
||||
if (it.hasNext())
|
||||
{
|
||||
writer.write("&");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param connection
|
||||
*/
|
||||
private void applySSLSettings(HttpRequest request,
|
||||
HttpsURLConnection connection)
|
||||
{
|
||||
if (request.isDisableCertificateValidation())
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("disable certificate validation");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TrustManager[] trustAllCerts = new TrustManager[] {
|
||||
new TrustAllTrustManager() };
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
connection.setSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("could not disable certificate validation", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.isDisableHostnameValidation())
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("disable hostname validation");
|
||||
}
|
||||
|
||||
connection.setHostnameVerifier(new TrustAllHostnameVerifier());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param parameters
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String createGetUrl(String url, Map<String, List<String>> parameters)
|
||||
{
|
||||
if (Util.isNotEmpty(parameters))
|
||||
{
|
||||
StringBuilder ub = new StringBuilder(url);
|
||||
boolean first = url.contains("?");
|
||||
|
||||
for (Map.Entry<String, List<String>> p : parameters.entrySet())
|
||||
{
|
||||
String key = encode(p.getKey());
|
||||
List<String> values = p.getValue();
|
||||
|
||||
if (Util.isNotEmpty(values))
|
||||
{
|
||||
for (String value : values)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
ub.append("?");
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ub.append("&");
|
||||
}
|
||||
|
||||
ub.append(key).append("=").append(encode(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
url = ub.toString();
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param param
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String encode(String param)
|
||||
{
|
||||
try
|
||||
{
|
||||
param = URLEncoder.encode(param, ENCODING);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param spec
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private HttpURLConnection openConnection(HttpRequest request, String spec)
|
||||
throws IOException
|
||||
{
|
||||
return openConnection(request, new URL(spec));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param url
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private HttpURLConnection openConnection(HttpRequest request, URL url)
|
||||
throws IOException
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
|
||||
// TODO improve
|
||||
request = new HttpRequest(url.toExternalForm());
|
||||
}
|
||||
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
if (!request.isIgnoreProxySettings()
|
||||
&& Proxies.isEnabled(configuration, url))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("fetch '{}' using proxy {}:{}",
|
||||
new Object[] { url.toExternalForm(),
|
||||
configuration.getProxyServer(), configuration.getProxyPort() });
|
||||
}
|
||||
|
||||
SocketAddress address =
|
||||
new InetSocketAddress(configuration.getProxyServer(),
|
||||
configuration.getProxyPort());
|
||||
|
||||
connection =
|
||||
(HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP,
|
||||
address));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (request.isIgnoreProxySettings() && logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("ignore proxy settings");
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("fetch '{}'", url.toExternalForm());
|
||||
}
|
||||
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
|
||||
if (connection instanceof HttpsURLConnection)
|
||||
{
|
||||
applySSLSettings(request, (HttpsURLConnection) connection);
|
||||
}
|
||||
|
||||
connection.setReadTimeout(TIMEOUT_RAED);
|
||||
connection.setConnectTimeout(TIMEOUT_CONNECTION);
|
||||
|
||||
if (request != null)
|
||||
{
|
||||
Map<String, List<String>> headers = request.getHeaders();
|
||||
|
||||
appendHeaders(headers, connection);
|
||||
|
||||
String username = request.getUsername();
|
||||
String password = request.getPassword();
|
||||
|
||||
appendBasicAuthHeader(connection, HEADER_AUTHORIZATION, username,
|
||||
password);
|
||||
}
|
||||
|
||||
connection.setRequestProperty(HEADER_ACCEPT_ENCODING,
|
||||
HEADER_ACCEPT_ENCODING_VALUE);
|
||||
connection.setRequestProperty(HEADER_USERAGENT,
|
||||
HEADER_USERAGENT_VALUE.concat(context.getVersion()));
|
||||
|
||||
String username = configuration.getProxyUser();
|
||||
String password = configuration.getProxyPassword();
|
||||
|
||||
appendBasicAuthHeader(connection, HEADER_PROXY_AUTHORIZATION, username,
|
||||
password);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private SCMContextProvider context;
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
/**
|
||||
* 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.net;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class URLHttpResponse implements HttpResponse
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String ENCODING_GZIP = "gzip";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param connection
|
||||
*/
|
||||
public URLHttpResponse(URLConnection connection)
|
||||
{
|
||||
this(connection, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param connection
|
||||
* @param decodeGZip
|
||||
*/
|
||||
public URLHttpResponse(URLConnection connection, boolean decodeGZip)
|
||||
{
|
||||
this.connection = connection;
|
||||
this.decodeGZip = decodeGZip;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
if ((connection != null) &&!clientClose)
|
||||
{
|
||||
InputStream in = getContent();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public InputStream getContent() throws IOException
|
||||
{
|
||||
clientClose = true;
|
||||
|
||||
String enc = connection.getContentEncoding();
|
||||
InputStream input = null;
|
||||
|
||||
if (decodeGZip || (Util.isNotEmpty(enc) && enc.contains(ENCODING_GZIP)))
|
||||
{
|
||||
input = new GZIPInputStream(connection.getInputStream());
|
||||
}
|
||||
else
|
||||
{
|
||||
input = connection.getInputStream();
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public String getContentAsString() throws IOException
|
||||
{
|
||||
String result = null;
|
||||
InputStream in = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
|
||||
try
|
||||
{
|
||||
in = getContent();
|
||||
baos = new ByteArrayOutputStream();
|
||||
IOUtil.copy(in, baos);
|
||||
baos.flush();
|
||||
result = new String(baos.toByteArray());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (in != null)
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
|
||||
if (baos != null)
|
||||
{
|
||||
baos.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getHeader(String name)
|
||||
{
|
||||
return connection.getHeaderField(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, List<String>> getHeaderMap()
|
||||
{
|
||||
return connection.getHeaderFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public int getStatusCode() throws IOException
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if (connection instanceof HttpURLConnection)
|
||||
{
|
||||
result = ((HttpURLConnection) connection).getResponseCode();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private URLConnection connection;
|
||||
|
||||
/** Field description */
|
||||
private boolean decodeGZip = false;
|
||||
|
||||
/** Field description */
|
||||
private boolean clientClose = false;
|
||||
}
|
||||
@@ -42,7 +42,6 @@ import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.web.security.AdministrationContext;
|
||||
import sonia.scm.web.security.PrivilegedAction;
|
||||
|
||||
/**
|
||||
* InjectionEnabledJob allows the execution of quartz jobs and enable injection on them.
|
||||
@@ -55,6 +54,7 @@ public class InjectionEnabledJob implements Job {
|
||||
private static final Logger logger = LoggerFactory.getLogger(InjectionEnabledJob.class);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void execute(JobExecutionContext jec) throws JobExecutionException {
|
||||
Preconditions.checkNotNull(jec, "execution context is null");
|
||||
|
||||
@@ -73,16 +73,11 @@ public class InjectionEnabledJob implements Job {
|
||||
}
|
||||
|
||||
AdministrationContext ctx = injector.getInstance(AdministrationContext.class);
|
||||
ctx.runAsAdmin(new PrivilegedAction()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ctx.runAsAdmin(() -> {
|
||||
logger.trace("create runnable from provider");
|
||||
Runnable runnable = runnableProvider.get();
|
||||
logger.debug("execute injection enabled job {}", runnable.getClass());
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ public class DefaultAdvancedHttpResponseTest
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testContentAsByteSourceWithFailedRequest() throws IOException
|
||||
{
|
||||
ByteArrayInputStream bais =
|
||||
|
||||
@@ -103,6 +103,7 @@ public class JsonContentTransformerTest
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = ContentTransformerException.class)
|
||||
public void testUnmarshallIOException() throws IOException
|
||||
{
|
||||
|
||||
@@ -63,6 +63,7 @@ public class XmlContentTransformerTest {
|
||||
assertEquals("test", to.value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = ContentTransformerException.class)
|
||||
public void testUnmarshallIOException() throws IOException{
|
||||
ByteSource bs = mock(ByteSource.class);
|
||||
|
||||
@@ -41,7 +41,6 @@ import static org.hamcrest.Matchers.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.quartz.CronTrigger;
|
||||
@@ -77,6 +76,7 @@ public class QuartzSchedulerTest {
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSchedule() throws SchedulerException
|
||||
{
|
||||
DummyRunnable dr = new DummyRunnable();
|
||||
@@ -158,6 +158,7 @@ public class QuartzSchedulerTest {
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testInitException() throws SchedulerException
|
||||
{
|
||||
when(quartzScheduler.isStarted()).thenThrow(SchedulerException.class);
|
||||
@@ -200,6 +201,7 @@ public class QuartzSchedulerTest {
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCloseException() throws IOException, SchedulerException
|
||||
{
|
||||
when(quartzScheduler.isStarted()).thenThrow(SchedulerException.class);
|
||||
|
||||
@@ -79,6 +79,7 @@ public class QuartzTaskTest {
|
||||
* Tests {@link QuartzTask#cancel()} when the scheduler throws an exception.
|
||||
* @throws org.quartz.SchedulerException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testCancelWithException() throws SchedulerException
|
||||
{
|
||||
|
||||
@@ -36,10 +36,7 @@ import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.Permission;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.authz.permission.PermissionResolver;
|
||||
import org.apache.shiro.authz.permission.WildcardPermission;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.hamcrest.Matchers;
|
||||
@@ -76,6 +73,7 @@ import sonia.scm.user.UserTestData;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultAuthorizationCollectorTest {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user