Last updated Jul 10, 2024

Bitbucket REST v2 migration for app developers

This document will guide you through the migration of your Marketplace app from REST v1 to REST v2. Bitbucket Data Center has migrated to REST v2 as part of the upgrade to Platform 7.

These documents include Atlassian REST v2 migration guides:

The rest of this documentation will be Bitbucket specific REST v2 migration.

Update plugin pom to use the correct dependencies

Bitbucket REST package replacements

REST v1 dependenciesREST v2 dependencies
<dependency>
    <groupId>com.atlassian.bitbucket.server</groupId>
    <artifactId>bitbucket-rest-api</artifactId>
    <scope>provided</scope>
<dependency>
<dependency>
    <groupId>com.atlassian.bitbucket.server</groupId>
    <artifactId>bitbucket-rest-v2-api</artifactId>
    <scope>provided</scope>
<dependency>
<dependency>
    <groupId>com.atlassian.bitbucket.server</groupId>
    <artifactId>bitbucket-rest-spi</artifactId>
    <scope>provided</scope>
<dependency>
<dependency>
    <groupId>com.atlassian.bitbucket.server</groupId>
    <artifactId>bitbucket-rest-v2-spi</artifactId>
    <scope>provided</scope>
<dependency>
<dependency>
    <groupId>com.atlassian.bitbucket.server</groupId>
    <artifactId>bitbucket-rest-model</artifactId>
    <scope>provided</scope>
<dependency>
removed in REST v2. Most classes migrated to bitbucket-rest-v2-api.

Plugin resource updates

Inject custom resolvers

Update @Context with @BeanParams for injecting custom resolvers constructed from request parameters into a resource. Then, use the custom resolvers to get the appropriate object.

1
2
// REST v1
public Response getProjectData(@Context Project project) {
    ...
}
// REST v2
public Response getProjectData(@BeanParam ProjectResolver projectResolver) {
    Project project = projectResolver.getProject();
    ...
}

The custom resolvers that we currently support may require additional OSGi imports:

ResolverRequired OSGi imports
com.atlassian.bitbucket.rest.v2.api.resolver.ProjectResolver
  • com.atlassian.bitbucket.project.ProjectService

  • com.atlassian.bitbucket.i18n.I18nService
com.atlassian.bitbucket.rest.v2.api.resolver.RepositoryResolver
  • com.atlassian.bitbucket.project.ProjectService

  • com.atlassian.bitbucket.repository.RepositoryService

  • com.atlassian.bitbucket.i18n.I18nService
com.atlassian.bitbucket.rest.v2.api.resolver.PullRequestResolver
  • com.atlassian.bitbucket.project.ProjectService

  • com.atlassian.bitbucket.repository.RepositoryService

  • com.atlassian.bitbucket.pull.PullRequestService

  • com.atlassian.bitbucket.i18n.I18nService
com.atlassian.bitbucket.rest.v2.api.resolver.CommentResolver
  • com.atlassian.bitbucket.comment.CommentService

  • com.atlassian.bitbucket.i18n.I18nService
com.atlassian.bitbucket.rest.v2.api.resolver.UserResolver
  • com.atlassian.bitbucket.permission.PermissionValidationService

  • com.atlassian.bitbucket.user.UserService

  • com.atlassian.bitbucket.i18n.I18nService
com.atlassian.bitbucket.rest.v2.api.resolver.PageRequestResolver
  • com.atlassian.bitbucket.i18n.I18nService
com.atlassian.bitbucket.rest.v2.api.resolver.DiffContentFilterResolver
  • none

RestUtils properties and methods migration

com.atlassian.bitbucket.rest.util.RestUtils was separated into helper classes as below:

RestUtils (REST v1)REST v2 location
com.atlassian.bitbucket.rest.util.RestUtils constants
com.atlassian.bitbucket.rest.v2.api.util.RestConstants
com.atlassian.bitbucket.rest.util.RestUtils#makeAvatarRequest
com.atlassian.bitbucket.rest.v2.api.enrich.AvatarRequestHelper#makeAvatarRequest
com.atlassian.bitbucket.rest.util.RestUtils#processAvatarResponse
com.atlassian.bitbucket.rest.v2.api.enrich.AvatarRequestHelper#processAvatarResponse
com.atlassian.bitbucket.rest.util.RestUtils#makePageRequest
use com.atlassian.bitbucket.rest.v2.api.resolver.PageRequestResolver
com.atlassian.bitbucket.rest.util.RestUtils#makeRenderContext
removed from API.
com.atlassian.bitbucket.rest.util.RestUtils#isImmutableObjectId
removed from API, see com.atlassian.bitbucket.rest.v2.api.util.CachePolicies#getCacheControlForObjectId
com.atlassian.bitbucket.rest.util.RestUtils#isImmutableBetween
removed from API, see com.atlassian.bitbucket.rest.v2.api.util.CachePolicies#getCacheControlForRange
com.atlassian.bitbucket.rest.util.RestUtils#processEntities
com.atlassian.bitbucket.rest.v2.api.enrich.EnrichProcessor#processEntities

ExceptionMapper changes

com.atlassian.bitbucket.rest.exception.UnhandledExceptionMapper was removed in REST v2. All the standard Bitbucket exceptions will be mapped to the appropriate status code by the Bitbucket application.

  • For custom exception handling, implement the javax.ws.rs.ext.ExceptionMapper and override the toResponse method.
  • Annotate the custom exception mapper with @Provider for runtime discovery.
1
2
@Provider
@Singleton
public class CustomExceptionMapper implements ExceptionMapper<CustomException> {
    @Override
    public Response toResponse(CustomException exception) {
            return ResponseFactory.status(Response.Status.FORBIDDEN)
                    .entity(new RestErrors(exception.getLocalizedMessage()))
                    .build();
    }
}

Removed APIs

@com.atlassian.bitbucket.rest.annotation.SecondaryRepository annotation was removed in REST v2.

com.atlassian.bitbucket.rest.util.StreamingResponse was removed in REST v2.

com.atlassian.bitbucket.rest.RestResource was removed in REST v2. Resources relying on RestResource previously must now throw their own exceptions directly.

RestFragment changes

RestFragments have migrated from bitbucket-rest-spi to bitbucket-rest-v2-spi.

The imports have changed from com.atlassian.bitbucket.rest.fragment.* to com.atlassian.bitbucket.rest.v2.fragment.*.

Its configuration remains the same, more information available on REST fragment plugin module

Rate this page: