CDN JAVA SDK creating rules

Beto Agüero 6 Reputation points
2022-06-06T17:21:44.857+00:00

Hi all,

I am trying to create a rule over the CDN I followed the example that is for the Java SDK.

I have successfully created the CDN and got the profile and endpoint but the CDN rules I cant figure out. Can you help me with how this is done?.

Thanks

Here is a sample code:

CdnProfile.DefinitionStages.WithStandardCreate profileDefinition = azureResourceManager.cdnProfiles().define("cpl-"+"testpefaijava2")
.withRegion(Region.US_EAST2)
.withExistingResourceGroup("rsg-borrraStorageResourceGroup")
.withSku(SkuName.STANDARD_MICROSOFT);
//.withStandardVerizonSku();

        // Define all the endpoints. We need to keep track of the last creatable stage
        // to be able to call create on the entire Cdn profile deployment definition.
        Creatable
Azure Content Delivery Network
{count} vote

1 answer

Sort by: Most helpful
  1. Beto Agüero 6 Reputation points
    2023-03-09T19:07:03.4333333+00:00

    hi i have the answer to this in case anyone needs it:

           DeliveryRuleRequestSchemeCondition deliveryRulesCondition = new DeliveryRuleRequestSchemeCondition()
                    .withParameters(
                            new RequestSchemeMatchConditionParameters()
                                    .withMatchValues(
                                            Arrays.asList(RequestSchemeMatchConditionParametersMatchValuesItem.HTTP)));
            deliveryRulesCondition.validate();
     
            UrlRedirectActionParameters deliveryRulesActionParameters = new UrlRedirectActionParameters()
                    .withRedirectType(RedirectType.TEMPORARY_REDIRECT).withDestinationProtocol(DestinationProtocol.HTTPS)
                    .withCustomHostname("");
            UrlRedirectAction deliveryRulesAction = new UrlRedirectAction().withParameters(deliveryRulesActionParameters);
            deliveryRulesAction.validate();
     
            DeliveryRule cdnRrule = new DeliveryRule()
                    .withName("HTTP to HTTPS redirect policy rule")
                    .withOrder(1)
                    .withConditions(Arrays.asList(deliveryRulesCondition))
                    .withActions(Arrays.asList(deliveryRulesAction));
            cdnRrule.validate();
     
            EndpointUpdateParameters endpointUpdateParameters = new EndpointUpdateParameters()
                    .withDeliveryPolicy(new EndpointPropertiesUpdateParametersDeliveryPolicy()
                            .withRules(Arrays.asList(cdnRrule))
                            .withDescription("HTTP to HTTPS redirect policy"));
     
            azureResourceManager.cdnProfiles()
                    .manager()
                    .serviceClient()
                    .getEndpoints()
                    .update(
                            resourceGroupName,
                            profileName,
                            endpointName,
                            endpointUpdateParameters);
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.