Updated on 2026-08-14 GMT+08:00

Obtaining Back-to-Source by Mirroring Rules (SDK for Java)

Function

This API is used to obtain the back-to-source by mirroring rules of a bucket.

Restrictions

  • The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.

Method

obsClient.getBucketMirrorBackToSource(GetBucketMirrorBackToSourceRequest request)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

request

Table 2

Yes

Explanation:

Request parameters for obtaining the back-to-source by mirroring rules. For details, see Table 2.

Table 2 GetBucketMirrorBackToSourceRequest

Parameter

Type

Mandatory (Yes/No)

Description

bucketName

String

Yes

Explanation:

Bucket name

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain a period (.) and a hyphen (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets with the same name in the same region, no error will be reported and the bucket properties comply with those set in the first creation request.

Default value:

None

Responses

Table 3 GetBucketTrashResult

Parameter

Type

Description

statusCode

int

Explanation:

HTTP status code

Value range:

A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors).

For more information, see Status Code.

Default value:

None

responseHeaders

Map<String, Object>

Explanation:

HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header.

Default value:

None

mirrorBackToSourceConfiguration

Table 4

Explanation:

Back-to-source by mirroring configuration. For details, see Table 4.

Table 4 MirrorBackToSourceConfiguration

Parameter

Type

Description

rules

List<Table 5>

Explanation:

List of back-to-source by mirroring rules. For details, see Table 5.

Table 5 MirrorBackToSourceRule

Parameter

Type

Description

id

String

Explanation:

Rule ID. It is the unique identifier of the back-to-source by mirroring rule configured for the current bucket.

condition

Table 6

Explanation:

Condition for triggering back to source. For details, see Table 6.

redirect

Table 7

Explanation:

Parameters for implementing the back to source function. For details, see Table 7.

Table 6 MirrorBackCondition

Parameter

Type

Description

httpErrorCodeReturnedEquals

String

Explanation:

Error code that triggers the back to source function. When this error code is returned for a download request, the back to source function is triggered.

Default value:

404

objectKeyPrefixEquals

String

Explanation:

Prefix of the object name that triggers the back to source function. Back to source is performed only when the specified object name prefix is contained in the request.

Restrictions:

  • If this parameter is left blank, all objects can trigger the back to source function.
  • For the same bucket, prefixes of different rules cannot be the same or contain each other.
Table 7 MirrorBackRedirect

Parameter

Type

Description

agency

String

Explanation:

Agency name. With an agency, you can grant OBS the permissions to query whether a specified object exists in a bucket and to upload objects to a bucket.

publicSource

Table 8

Explanation:

Configuration of the source site that can be publicly accessed. This parameter is mandatory when the source site is a publicly accessible resource. publicSource is the parent node of sourceEndpoint. For details, see Table 8.

vpcEndpointURN

String

Explanation:

URN of the VPC endpoint service

retryConditions

List<String>

Explanation:

Condition for switching the source site address

passQueryString

Boolean

Explanation:

Whether to include the request character string

Value range:

  • false: queryString in the OBS request is not passed to the source site.
  • true: queryString in the OBS request is passed to the source site.

mirrorFollowRedirect

Boolean

Explanation:

Whether to obtain resources by redirecting the request based on the 3XX response from the source site

Value range:

  • false: OBS transparently transmits the 3XX response and does not return resources.
  • true: OBS returns resources by redirecting the request based on the 3XX response.

mirrorHttpHeader

Table 10

Explanation:

HTTP header pass rule. mirrorHttpHeader is the parent node of passAll, pass, remove, and set. For details, see Table 10.

replaceKeyWith

String

Explanation:

Whether to add a prefix or suffix when downloading objects from the source site

replaceKeyPrefixWith

String

Explanation:

Character string used to replace objectKeyPrefixEquals. If you need to replace the current object name prefix when downloading the object from the source site, specify this parameter.

redirectWithoutReferer

Boolean

Explanation:

Whether to carry the original host as the referer header to the destination address for redirection

Value range:

false: The original host is carried as the referer header to the destination address for redirection.

true: The original host is not carried as the referer header to the destination address for redirection.

mirrorAllowHttpMethod

List<String>

Explanation:

Request method that supports transparent transmission

Value range:

  • GET: requests to obtain objects in a bucket
  • HEAD: requests to obtain the metadata of an object in a bucket
Table 8 MirrorBackPublicSource

Parameter

Type

Mandatory (Yes/No)

Description

sourceEndpoint

Table 9

No

Explanation:

Address of the source site that can be publicly accessed. sourceEndpoint is the parent node of master and slave. For details, see Table 9.

Table 9 MirrorBackSourceEndpoint

Parameter

Type

Mandatory (Yes/No)

Description

master

List<String>

No

Explanation:

Primary source site address. If the source site is a bucket that can be accessed over HTTP, the address is the bucket domain name. If the source site is a private bucket provided by other cloud vendors, the address is the region domain name.

slave

List<String>

No

Explanation:

Secondary source site address. If the source site is a bucket that can be accessed over HTTP, the address is the bucket domain name. If the source site is a private bucket provided by other cloud vendors, the address is the region domain name.

Table 10 MirrorBackHttpHeader

Parameter

Type

Mandatory (Yes/No)

Description

passAll

Boolean

No

Explanation:

Whether to transparently transmit all HTTP headers to the source site

Value range:

  • false: Do not transparently transmit all HTTP headers to the source site.
  • true: Transparently transmit all HTTP headers to the source site.

pass

List<String>

No

Explanation:

List of HTTP headers to be transparently transmitted

remove

List<String>

No

Explanation:

List of HTTP headers that cannot be transparently transmitted

set

List<Table 11>

No

Explanation:

List of HTTP header values to be transparently transmitted. For details, see Table 11.

Table 11 MirrorBackHttpHeaderSet

Parameter

Type

Mandatory (Yes/No)

Description

key

String

No

Explanation:

Keyword of the HTTP header that needs to be transparently transmitted

value

String

No

Explanation:

Value of the HTTP header that needs to be transparently transmitted

Sample Code

This example obtains the back-to-source by mirroring configuration of bucket examplebucket.
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
import com.obs.services.model.mirrorback.GetBucketMirrorBackToSourceRequest;
import com.obs.services.model.mirrorback.GetBucketMirrorBackToSourceResult;
import com.obs.services.model.mirrorback.MirrorBackRedirect;
import com.obs.services.model.mirrorback.MirrorBackSourceEndpoint;
import com.obs.services.model.mirrorback.MirrorBackToSourceConfiguration;
import com.obs.services.model.mirrorback.MirrorBackToSourceRule;
public class GetBucketMirrorBackToSource {
    public static void main(String[] args) {
        // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
        // Obtain an AK/SK pair on the management console.
        String ak = System.getenv("ACCESS_KEY_ID");
        String sk = System.getenv("SECRET_ACCESS_KEY_ID");
        // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage.
        // Obtain an AK/SK pair and a security token using environment variables or import them in other ways.
        String securityToken = System.getenv("SECURITY_TOKEN");
        // Enter the endpoint corresponding to the bucket. CN North-Beijing4 is used here as an example. Replace it with the one currently in use.
        // Obtain an endpoint using environment variables or import it in other ways.
        String endPoint = System.getenv("ENDPOINT");
        ObsConfiguration obsConfiguration = new ObsConfiguration();
        obsConfiguration.setEndPoint(endPoint);
        ObsClient obsClient = new ObsClient(ak, sk, securityToken, obsConfiguration);
        try {
            String exampleBucket = "examplebucket";
            GetBucketMirrorBackToSourceRequest request = new GetBucketMirrorBackToSourceRequest(exampleBucket);
            GetBucketMirrorBackToSourceResult result = obsClient.getBucketMirrorBackToSource(request);
            System.out.println("GetBucketMirrorBackToSource successfully");
            MirrorBackToSourceConfiguration config = result.getMirrorBackToSourceConfiguration();
            if (config != null && config.getRules() != null) {
                for (MirrorBackToSourceRule rule : config.getRules()) {
                    System.out.println("Rule ID: " + rule.getId());
                    if (rule.getCondition() != null) {
                        System.out.println("Condition HTTP Error Code: "
                            + rule.getCondition().getHttpErrorCodeReturnedEquals());
                        System.out.println("Condition Object Key Prefix: "
                            + rule.getCondition().getObjectKeyPrefixEquals());
                    }
                    if (rule.getRedirect() != null) {
                        MirrorBackRedirect redirect = rule.getRedirect();
                        System.out.println("Agency: " + redirect.getAgency());
                        System.out.println("Pass Query String: " + redirect.getPassQueryString());
                        System.out.println("Mirror Follow Redirect: " + redirect.getMirrorFollowRedirect());
                        if (redirect.getPublicSource() != null
                            && redirect.getPublicSource().getSourceEndpoint() != null) {
                            MirrorBackSourceEndpoint ep =
                                redirect.getPublicSource().getSourceEndpoint();
                            System.out.println("Master Endpoints: " + ep.getMaster());
                            System.out.println("Slave Endpoints: " + ep.getSlave());
                        }
                    }
                }
            }
        } catch (ObsException e) {
            System.out.println("GetBucketMirrorBackToSource failed");
            // Request failed. Print the HTTP status code.
            System.out.println("HTTP Code:" + e.getResponseCode());
            // Request failed. Print the server-side error code.
            System.out.println("Error Code:" + e.getErrorCode());
            // Request failed. Print the error details.
            System.out.println("Error Message:" + e.getErrorMessage());
            // Request failed. Print the request ID.
            System.out.println("Request ID:" + e.getErrorRequestId());
            System.out.println("Host ID:" + e.getErrorHostId());
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println("GetBucketMirrorBackToSource failed");
            // Print other error information.
            e.printStackTrace();
        }
    }
}