本文整理汇总了Java中io.apiman.gateway.engine.beans.ApiRequest.setType方法的典型用法代码示例。如果您正苦于以下问题:Java ApiRequest.setType方法的具体用法?Java ApiRequest.setType怎么用?Java ApiRequest.setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.apiman.gateway.engine.beans.ApiRequest
的用法示例。
在下文中一共展示了ApiRequest.setType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testApplyJdbcWithRoles
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
public void testApplyJdbcWithRoles(String json) throws Exception {
// A live LDAP server is required to run this test!
BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy();
BasicAuthenticationConfig config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
Mockito.when(context.getComponent(IJdbcComponent.class)).thenReturn(new DefaultJdbcComponent());
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
// Success
request.getHeaders().put("Authorization", createBasicAuthorization(JDBC_USER, JDBC_PASSWORD));
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
Set<String> expectedRoles = new HashSet<>();
expectedRoles.add("admin");
expectedRoles.add("user");
Mockito.verify(context).setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, expectedRoles);
}
示例2: buildRequest
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
public static ApiRequest buildRequest(HttpServerRequest req, boolean isTransportSecure) {
ApiRequest apimanRequest = new ApiRequest();
apimanRequest.setApiKey(parseApiKey(req));
apimanRequest.setRemoteAddr(req.remoteAddress().host());
apimanRequest.setType(req.method().toString());
apimanRequest.setTransportSecure(isTransportSecure);
multimapToMap(apimanRequest.getHeaders(), req.headers(), IGNORESET);
multimapToMap(apimanRequest.getQueryParams(), req.params(), Collections.<String>emptySet());
parsePath(req, apimanRequest);
return apimanRequest;
}
示例3: requestWithVerb
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
private ApiRequest requestWithVerb(IPolicyChain<ApiRequest> chain, String verb)
throws IOException, JsonGenerationException, JsonMappingException
{
IgnoredResourcesPolicy policy = new IgnoredResourcesPolicy();
IgnoredResourcesConfig configObj = new IgnoredResourcesConfig();
ArrayList<IgnoredResource> elements = new ArrayList<>(2);
elements.add(createResource(verb, firstPath));
elements.add(createResource(verb, secondPath));
configObj.setRules(elements);
String json = mapper.writeValueAsString(configObj);
Object config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/invoices/1");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
createFailurePolicyObject(context);
// Success
policy.apply(request, context, config, chain);
// Fail
request.setDestination("/invoices/23/items/43");
policy.apply(request, context, config, chain);
// Fail
request.setDestination("/items/43");
policy.apply(request, context, config, chain);
return request;
}
示例4: doTest
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
private void doTest(String json, HashSet<String> userRoles, String verb, String path, boolean shouldSucceed) {
AuthorizationPolicy policy = new AuthorizationPolicy();
Object config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType(verb);
request.setDestination(path);
IPolicyContext context = Mockito.mock(IPolicyContext.class);
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
Mockito.when(context.getAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, (HashSet<String>) null)).thenReturn(userRoles);
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(
new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
failure.setFailureCode(failureCode);
failure.setType(type);
failure.setMessage(message);
return failure;
}
});
// Success
policy.apply(request, context, config, chain);
if (shouldSucceed) {
Mockito.verify(chain).doApply(request);
} else {
Mockito.verify(chain).doFailure(failure);
}
}
示例5: testApply
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
* Test method for {@link io.apiman.gateway.engine.policies.IPWhitelistPolicy#parseConfiguration(java.lang.String)}.
*/
@Test
public void testApply() {
IPWhitelistPolicy policy = new IPWhitelistPolicy();
String json = "{" +
" \"ipList\" : [" +
" \"1.2.3.4\"," +
" \"3.4.5.6\"," +
" \"10.0.0.11\"" +
" ]" +
"}";
Object config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
// Success
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
// Failure
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
return failure;
}
});
chain = Mockito.mock(IPolicyChain.class);
request.setRemoteAddr("9.8.7.6");
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
}
示例6: testApplyWithWildcards
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
* Test method for {@link io.apiman.gateway.engine.policies.IPWhitelistPolicy#parseConfiguration(java.lang.String)}.
*/
@Test
public void testApplyWithWildcards() {
IPWhitelistPolicy policy = new IPWhitelistPolicy();
String json = "{" +
" \"ipList\" : [" +
" \"10.0.*.*\"" +
" ]" +
"}";
Object config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setDestination("/");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
// Success
request.setRemoteAddr("10.0.87.33");
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
request.setRemoteAddr("10.0.12.19");
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
// Failure
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
return failure;
}
});
chain = Mockito.mock(IPolicyChain.class);
request.setRemoteAddr("9.8.7.6");
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
}
示例7: testApply
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
* Test method for {@link io.apiman.gateway.engine.policies.RateLimitingPolicy#parseConfiguration(java.lang.String)}.
*/
@Test
public void testApply() {
RateLimitingPolicy policy = new RateLimitingPolicy();
String json = "{\r\n" +
" \"limit\" : 10,\r\n" +
" \"granularity\" : \"User\",\r\n" +
" \"period\" : \"Minute\",\r\n" +
" \"userHeader\" : \"X-Identity\"\r\n" +
"}";
Object config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setContract(createTestContract());
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/");
request.getHeaders().put("X-Identity", "sclause"); //$NON-NLS-2$
IPolicyContext context = Mockito.mock(IPolicyContext.class);
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
return failure;
}
});
Mockito.when(context.getComponent(IRateLimiterComponent.class)).thenReturn(new InMemoryRateLimiterComponent());
IPolicyChain<ApiRequest> chain;
for (int count = 0; count < 10; count++) {
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
}
// Failure - only allow 10 per minute!
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
}
示例8: testApply
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
* Test method for {@link io.apiman.gateway.engine.policies.IPBlacklistPolicy#parseConfiguration(java.lang.String)}.
*/
@Test
public void testApply() {
IPBlacklistPolicy policy = new IPBlacklistPolicy();
String json = "{" +
" \"ipList\" : [" +
" \"1.2.3.4\"," +
" \"3.4.5.6\"," +
" \"10.0.0.11\"" +
" ]" +
"}";
IPListConfig config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
return failure;
}
});
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
// Failure
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
// Success
request.setRemoteAddr("9.8.7.6");
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
}
示例9: testApplyJdbcNoRoles
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
* @param json
* @throws Exception
*/
public void testApplyJdbcNoRoles(String json) throws Exception {
// A live LDAP server is required to run this test!
BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy();
BasicAuthenticationConfig config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
return failure;
}
});
Mockito.when(context.getComponent(IJdbcComponent.class)).thenReturn(new DefaultJdbcComponent());
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
// Failure
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
// Failure
request.getHeaders().put("Authorization", createBasicAuthorization(JDBC_USER, "invalid_password"));
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
// Success
request.getHeaders().put("Authorization", createBasicAuthorization(JDBC_USER, JDBC_PASSWORD));
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
}
示例10: testApply
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
@Test
public void testApply() throws Exception {
IgnoredResourcesPolicy policy = new IgnoredResourcesPolicy();
IgnoredResourcesConfig configObj = new IgnoredResourcesConfig();
ArrayList<IgnoredResource> elements = new ArrayList<>(2);
elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, firstPath));
elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, secondPath));
configObj.setRules(elements);
String json = mapper.writeValueAsString(configObj);
Object config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/invoices/1");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
// Success
policy.apply(request, context, config, chain);
// Success
request.setDestination("/invoices");
policy.apply(request, context, config, chain);
// Success
request.setDestination("/invoices/items");
policy.apply(request, context, config, chain);
// Success
request.setDestination("/invoices/items/13");
policy.apply(request, context, config, chain);
Mockito.verify(chain, Mockito.times(4)).doApply(request);
Mockito.verify(chain, Mockito.never()).doFailure(Mockito.<PolicyFailure> any());
final PolicyFailure failure = createFailurePolicyObject(context);
chain = Mockito.mock(IPolicyChain.class);
request.setDestination("/invoices/23/items/43");
policy.apply(request, context, config, chain);
// Failure
request.setDestination("/items/43");
policy.apply(request, context, config, chain);
Mockito.verify(chain, Mockito.times(2)).doFailure(failure);
}
示例11: testApplyWithWildcards
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
* Test method for {@link io.apiman.gateway.engine.policies.IPBlacklistPolicy#parseConfiguration(java.lang.String)}.
*/
@Test
public void testApplyWithWildcards() {
IPBlacklistPolicy policy = new IPBlacklistPolicy();
String json = "{" +
" \"ipList\" : [" +
" \"10.0.*.*\"" +
" ]" +
"}";
IPListConfig config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setDestination("/");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
return failure;
}
});
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
// Failures
request.setRemoteAddr("10.0.123.87");
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
request.setRemoteAddr("10.0.97.1");
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
// Successes
request.setRemoteAddr("9.8.7.6");
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
request.setRemoteAddr("10.10.15.123");
chain = Mockito.mock(IPolicyChain.class);
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
}
示例12: doTest
import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
private void doTest(String json, String username, String password, Integer expectedFailureCode,
Set<String> expectedRoles) throws Exception {
BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy();
BasicAuthenticationConfig config = policy.parseConfiguration(json);
ApiRequest request = new ApiRequest();
request.setType("GET");
request.setApiKey("12345");
request.setRemoteAddr("1.2.3.4");
request.setDestination("/");
IPolicyContext context = Mockito.mock(IPolicyContext.class);
final PolicyFailure failure = new PolicyFailure();
Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
@Override
public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
failure.setType(type);
failure.setFailureCode(failureCode);
failure.setMessage(message);
return failure;
}
});
// The LDAP stuff we're testing!
Mockito.when(context.getComponent(ILdapComponent.class)).thenReturn(new DefaultLdapComponent());
IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
if (username != null) {
request.getHeaders().put("Authorization", createBasicAuthorization(username, password));
}
if (expectedFailureCode == null) {
policy.apply(request, context, config, chain);
Mockito.verify(chain).doApply(request);
} else {
policy.apply(request, context, config, chain);
Mockito.verify(chain).doFailure(failure);
Assert.assertEquals(expectedFailureCode.intValue(), failure.getFailureCode());
}
if (expectedRoles != null && expectedFailureCode == null) {
Mockito.verify(context).setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, expectedRoles);
}
}