404 on custom plugin path when using PermissionAdminService class in java servlet

I am developing a small plugin extension for an internal facing instance of Bitbucket. It will expose admins of projects and repositories to users that are not a part of that project, so that they can contact the admins and get proper access and relieve the global admins of that duty.

I am using a basic servlet class:

package com.atlassian.bitbucket.plugin.servlet;

import com.atlassian.soy.renderer.SoyTemplateRenderer;
import com.atlassian.bitbucket.project.Project;
import com.atlassian.bitbucket.project.ProjectService;
import com.atlassian.bitbucket.permission.Permission;
import com.atlassian.bitbucket.permission.PermissionAdminService;
import com.atlassian.bitbucket.permission.SetPermissionRequest;
import com.atlassian.bitbucket.user.UserService;
import com.atlassian.bitbucket.util.Page;
import com.atlassian.bitbucket.util.PageRequest;
import com.atlassian.bitbucket.util.PageRequestImpl;
import com.google.common.collect.ImmutableMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ProjectServlet extends AbstractExampleServlet {
    private final ProjectService projectService;
    private final PermissionAdminService permissionAdminService;

    public ProjectServlet(SoyTemplateRenderer soyTemplateRenderer, ProjectService projectService, PermissionAdminService permissionAdminService) {
        super(soyTemplateRenderer);
        this.projectService = projectService;
        this.permissionAdminService = permissionAdminService;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // Get projectKey from path
        String pathInfo = req.getPathInfo();

        String[] components = pathInfo.split("/");

        if (components.length < 2) {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        Project project = projectService.getByKey(components[1]);

        if (project == null) {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        boolean isSettings = false;
        if (components.length == 3 && "settings".equalsIgnoreCase(components[2])) {
            isSettings = true;
        }

        String template = isSettings ? "plugin.example.projectSettings" : "plugin.example.project";

        render(resp, template, ImmutableMap.<String, Object>of("project", project));
    }
}

When using PermissionAdminService, my plugin path returns a 404 "Could not find servlet for: /plugins/servlet/example/project/". When I remove the PermissionAdminService and just use ProjectService, everything works correctly and I can navigate to my context path fine.

I can leave the import statement intact and remove actual usage of the PermissionAdminService class and the plugin builds without failure, which leads me to believe that the class is included in the dependencies I am downloading via maven (using Atlassian SDK).

 

Any help on this would be greatly appreciated.

0 answers

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

626 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot