| | |
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.inject.Inject;
|
| | | import javax.inject.Singleton;
|
| | | import javax.servlet.ServletException;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
| | | import com.gitblit.utils.RpcUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | import dagger.ObjectGraph;
|
| | |
|
| | | /**
|
| | | * Handles remote procedure calls.
|
| | | *
|
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | @Singleton
|
| | | public class RpcServlet extends JsonServlet {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public static final int PROTOCOL_VERSION = 6;
|
| | | public static final int PROTOCOL_VERSION = 7;
|
| | |
|
| | | private final IStoredSettings settings;
|
| | | private IStoredSettings settings;
|
| | |
|
| | | private final IGitblit gitblit;
|
| | | private IGitblit gitblit;
|
| | |
|
| | | @Inject
|
| | | public RpcServlet(IGitblit gitblit) {
|
| | |
|
| | | super();
|
| | |
|
| | | this.settings = gitblit.getSettings();
|
| | | this.gitblit = gitblit;
|
| | | @Override
|
| | | protected void inject(ObjectGraph dagger) {
|
| | | this.settings = dagger.get(IStoredSettings.class);
|
| | | this.gitblit = dagger.get(IGitblit.class);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | result = PROTOCOL_VERSION;
|
| | | } else if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {
|
| | | // Determine the Gitblit clone url
|
| | | String gitblitUrl = HttpUtils.getGitblitURL(request);
|
| | | String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
|
| | | if (StringUtils.isEmpty(gitblitUrl)) {
|
| | | gitblitUrl = HttpUtils.getGitblitURL(request);
|
| | | }
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append(gitblitUrl);
|
| | | sb.append(Constants.R_PATH);
|
| | |
| | | // create user
|
| | | UserModel model = deserialize(request, response, UserModel.class);
|
| | | try {
|
| | | gitblit.updateUserModel(model.username, model, true);
|
| | | gitblit.addUser(model);
|
| | | } catch (GitBlitException e) {
|
| | | response.setStatus(failureCode);
|
| | | }
|
| | |
| | | username = model.username;
|
| | | }
|
| | | try {
|
| | | gitblit.updateUserModel(username, model, false);
|
| | | gitblit.reviseUser(username, model);
|
| | | } catch (GitBlitException e) {
|
| | | response.setStatus(failureCode);
|
| | | }
|
| | |
| | | // create team
|
| | | TeamModel model = deserialize(request, response, TeamModel.class);
|
| | | try {
|
| | | gitblit.updateTeamModel(model.name, model, true);
|
| | | gitblit.addTeam(model);
|
| | | } catch (GitBlitException e) {
|
| | | response.setStatus(failureCode);
|
| | | }
|
| | |
| | | teamname = model.name;
|
| | | }
|
| | | try {
|
| | | gitblit.updateTeamModel(teamname, model, false);
|
| | | gitblit.reviseTeam(teamname, model);
|
| | | } catch (GitBlitException e) {
|
| | | response.setStatus(failureCode);
|
| | | }
|
| | |
| | | } else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {
|
| | | // return the list of federation sets
|
| | | if (allowAdmin && gitblit.canFederate()) {
|
| | | String gitblitUrl = HttpUtils.getGitblitURL(request);
|
| | | String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
|
| | | if (StringUtils.isEmpty(gitblitUrl)) {
|
| | | gitblitUrl = HttpUtils.getGitblitURL(request);
|
| | | }
|
| | | result = gitblit.getFederationSets(gitblitUrl);
|
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | |
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | | }
|
| | | } else if (RpcRequest.REINDEX_TICKETS.equals(reqType)) {
|
| | | if (allowManagement) {
|
| | | if (StringUtils.isEmpty(objectName)) {
|
| | | // reindex all tickets
|
| | | gitblit.getTicketService().reindex();
|
| | | } else {
|
| | | // reindex tickets in a specific repository
|
| | | RepositoryModel model = gitblit.getRepositoryModel(objectName);
|
| | | gitblit.getTicketService().reindex(model);
|
| | | }
|
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | | }
|
| | | }
|
| | |
|
| | | // send the result of the request
|