commit | author | age
|
65d5bb
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
package com.gitblit.servlet;
|
|
17 |
|
|
18 |
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
|
19 |
|
|
20 |
import java.io.IOException;
|
|
21 |
import java.util.Enumeration;
|
|
22 |
|
cdb2fe
|
23 |
import com.google.inject.Inject;
|
JM |
24 |
import com.google.inject.Singleton;
|
65d5bb
|
25 |
import javax.servlet.FilterChain;
|
JM |
26 |
import javax.servlet.FilterConfig;
|
|
27 |
import javax.servlet.ServletConfig;
|
|
28 |
import javax.servlet.ServletContext;
|
|
29 |
import javax.servlet.ServletException;
|
|
30 |
import javax.servlet.ServletRequest;
|
|
31 |
import javax.servlet.ServletResponse;
|
|
32 |
import javax.servlet.http.HttpServlet;
|
|
33 |
import javax.servlet.http.HttpServletRequest;
|
|
34 |
import javax.servlet.http.HttpServletResponse;
|
|
35 |
|
|
36 |
import org.eclipse.jgit.http.server.GitFilter;
|
|
37 |
|
|
38 |
import com.gitblit.git.GitblitReceivePackFactory;
|
|
39 |
import com.gitblit.git.GitblitUploadPackFactory;
|
|
40 |
import com.gitblit.git.RepositoryResolver;
|
|
41 |
import com.gitblit.manager.IGitblit;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* The GitServlet provides http/https access to Git repositories.
|
|
45 |
* Access to this servlet is protected by the GitFilter.
|
|
46 |
*
|
|
47 |
* @author James Moger
|
|
48 |
*
|
|
49 |
*/
|
1b34b0
|
50 |
@Singleton
|
65d5bb
|
51 |
public class GitServlet extends HttpServlet {
|
JM |
52 |
|
|
53 |
private static final long serialVersionUID = 1L;
|
|
54 |
|
|
55 |
private final GitFilter gitFilter;
|
|
56 |
|
1b34b0
|
57 |
@Inject
|
JM |
58 |
public GitServlet(IGitblit gitblit) {
|
65d5bb
|
59 |
gitFilter = new GitFilter();
|
1b34b0
|
60 |
gitFilter.setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(gitblit));
|
JM |
61 |
gitFilter.setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>(gitblit));
|
|
62 |
gitFilter.setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>(gitblit));
|
65d5bb
|
63 |
}
|
JM |
64 |
|
|
65 |
@Override
|
|
66 |
public void init(final ServletConfig config) throws ServletException {
|
|
67 |
|
|
68 |
gitFilter.init(new FilterConfig() {
|
|
69 |
@Override
|
|
70 |
public String getFilterName() {
|
|
71 |
return gitFilter.getClass().getName();
|
|
72 |
}
|
|
73 |
|
|
74 |
@Override
|
|
75 |
public String getInitParameter(String name) {
|
|
76 |
return config.getInitParameter(name);
|
|
77 |
}
|
|
78 |
|
|
79 |
@Override
|
|
80 |
public Enumeration<String> getInitParameterNames() {
|
|
81 |
return config.getInitParameterNames();
|
|
82 |
}
|
|
83 |
|
|
84 |
@Override
|
|
85 |
public ServletContext getServletContext() {
|
|
86 |
return config.getServletContext();
|
|
87 |
}
|
|
88 |
});
|
|
89 |
|
|
90 |
init();
|
|
91 |
}
|
|
92 |
|
|
93 |
@Override
|
|
94 |
protected void service(HttpServletRequest req, HttpServletResponse res)
|
|
95 |
throws ServletException, IOException {
|
|
96 |
gitFilter.doFilter(req, res, new FilterChain() {
|
|
97 |
@Override
|
|
98 |
public void doFilter(ServletRequest request,
|
|
99 |
ServletResponse response) throws IOException,
|
|
100 |
ServletException {
|
|
101 |
((HttpServletResponse) response).sendError(SC_NOT_FOUND);
|
|
102 |
}
|
|
103 |
});
|
|
104 |
}
|
|
105 |
|
|
106 |
@Override
|
|
107 |
public void destroy() {
|
|
108 |
gitFilter.destroy();
|
|
109 |
}
|
|
110 |
}
|