-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modify the request method in v4
This policy has been migrated for V4 engine but remains backward compatible with V3 engine. BREAKING CHANGE: Requires APIM 3.20 minimum because it requires RxJava3. With V4 Api definition, the request's method is directly overridden.
- Loading branch information
Showing
12 changed files
with
354 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/io/gravitee/policy/v3/overriderequestmethod/OverrideRequestMethodPolicyV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.policy.v3.overriderequestmethod; | ||
|
||
import io.gravitee.gateway.api.ExecutionContext; | ||
import io.gravitee.gateway.api.Request; | ||
import io.gravitee.gateway.api.Response; | ||
import io.gravitee.policy.api.PolicyChain; | ||
import io.gravitee.policy.api.annotations.OnRequest; | ||
import io.gravitee.policy.overriderequestmethod.configuration.OverrideRequestMethodPolicyConfiguration; | ||
|
||
/** | ||
* @author David BRASSELY (david.brassely at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
public class OverrideRequestMethodPolicyV3 { | ||
|
||
/** | ||
* The associated configuration to this Policy | ||
*/ | ||
protected OverrideRequestMethodPolicyConfiguration configuration; | ||
|
||
/** | ||
* Create a new policy instance based on its associated configuration | ||
* | ||
* @param configuration the associated configuration to the new policy instance | ||
*/ | ||
public OverrideRequestMethodPolicyV3(OverrideRequestMethodPolicyConfiguration configuration) { | ||
this.configuration = configuration; | ||
} | ||
|
||
@OnRequest | ||
public void onRequest(Request request, Response response, ExecutionContext executionContext, PolicyChain policyChain) { | ||
executionContext.setAttribute(ExecutionContext.ATTR_REQUEST_METHOD, configuration.getMethod()); | ||
policyChain.doNext(request, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...licy/overriderequestmethod/OverrideRequestMethodPolicyV3CompatibilityIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.policy.overriderequestmethod; | ||
|
||
import io.gravitee.apim.gateway.tests.sdk.configuration.GatewayConfigurationBuilder; | ||
import io.gravitee.definition.model.Api; | ||
import io.gravitee.definition.model.ExecutionMode; | ||
|
||
/** | ||
* @author Yann TAVERNIER (yann.tavernier at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
public class OverrideRequestMethodPolicyV3CompatibilityIntegrationTest extends OverrideRequestMethodPolicyIntegrationTest { | ||
|
||
@Override | ||
protected void configureGateway(GatewayConfigurationBuilder gatewayConfigurationBuilder) { | ||
super.configureGateway(gatewayConfigurationBuilder); | ||
gatewayConfigurationBuilder.set("api.jupiterMode.enabled", "true"); | ||
gatewayConfigurationBuilder.set("api.jupiterMode.default", "always"); | ||
} | ||
|
||
@Override | ||
public void configureApi(Api api) { | ||
super.configureApi(api); | ||
api.setExecutionMode(ExecutionMode.V3); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...o/gravitee/policy/overriderequestmethod/OverrideRequestMethodPolicyV4IntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.policy.overriderequestmethod; | ||
|
||
import io.gravitee.apim.gateway.tests.sdk.annotations.DeployApi; | ||
import io.gravitee.apim.gateway.tests.sdk.configuration.GatewayConfigurationBuilder; | ||
import io.gravitee.apim.gateway.tests.sdk.connector.EndpointBuilder; | ||
import io.gravitee.apim.gateway.tests.sdk.connector.EntrypointBuilder; | ||
import io.gravitee.definition.model.ExecutionMode; | ||
import io.gravitee.definition.model.v4.Api; | ||
import io.gravitee.gateway.reactor.ReactableApi; | ||
import io.gravitee.plugin.endpoint.EndpointConnectorPlugin; | ||
import io.gravitee.plugin.endpoint.http.proxy.HttpProxyEndpointConnectorFactory; | ||
import io.gravitee.plugin.entrypoint.EntrypointConnectorPlugin; | ||
import io.gravitee.plugin.entrypoint.http.proxy.HttpProxyEntrypointConnectorFactory; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Yann TAVERNIER (yann.tavernier at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
@DeployApi("/apis/v4_definition/override-http-method.json") | ||
public class OverrideRequestMethodPolicyV4IntegrationTest extends OverrideRequestMethodPolicyIntegrationTest { | ||
|
||
@Override | ||
protected void configureGateway(GatewayConfigurationBuilder gatewayConfigurationBuilder) { | ||
super.configureGateway(gatewayConfigurationBuilder); | ||
gatewayConfigurationBuilder.set("api.jupiterMode.enabled", "true"); | ||
gatewayConfigurationBuilder.set("api.jupiterMode.default", "always"); | ||
} | ||
|
||
@Override | ||
public void configureEntrypoints(Map<String, EntrypointConnectorPlugin<?, ?>> entrypoints) { | ||
entrypoints.putIfAbsent("http-proxy", EntrypointBuilder.build("http-proxy", HttpProxyEntrypointConnectorFactory.class)); | ||
} | ||
|
||
@Override | ||
public void configureEndpoints(Map<String, EndpointConnectorPlugin<?, ?>> endpoints) { | ||
endpoints.putIfAbsent("http-proxy", EndpointBuilder.build("http-proxy", HttpProxyEndpointConnectorFactory.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.