本文整理了Java中org.wso2.msf4j.Request
类的一些代码示例,展示了Request
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request
类的具体详情如下:
包路径:org.wso2.msf4j.Request
类名称:Request
[英]Class that represents an HTTP request in MSF4J level.
[中]类,该类表示MSF4J级别的HTTP请求。
代码示例来源:origin: wso2/msf4j
@Override
public boolean interceptRequest(Request request, Response response) throws Exception {
log.info("Logging HTTP request { HTTPMethod: {}, URI: {} }", request.getHttpMethod(), request.getUri());
return true;
}
}
代码示例来源:origin: wso2/msf4j
/**
* Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
*
* @param name a {@link String} specifying the name of the attribute
* @return an {@link Object} containing the value of the attribute, or null if the attribute does not exist
*/
public Object getAttribute(String name) {
return request.getProperty(name);
}
代码示例来源:origin: wso2/msf4j
@Override
public boolean interceptRequest(Request request, Response response) throws Exception {
request.getHeaders().getRequestHeaders().entrySet()
.forEach(header -> log.info("Header - " + header.getKey() + " : " + header.getValue()));
return true;
}
}
代码示例来源:origin: wso2/msf4j
@Override
default boolean interceptRequest(Request request, Response response) throws Exception {
Method method = (Method) request.getProperty(MSF4JConstants.METHOD_PROPERTY_NAME);
ServiceMethodInfo serviceMethodInfo = new ServiceMethodInfo(method.getName(), method, request);
request.getProperties().forEach(serviceMethodInfo::setAttribute);
return preCall(request, response, serviceMethodInfo);
}
代码示例来源:origin: org.wso2.msf4j/msf4j-core
private void setBaseUri(Request request) {
StringBuilder builder = new StringBuilder();
builder.append(request.getProperty(Constants.PROTOCOL).toString().toLowerCase(Locale.US)).append("://")
.append(request.getHeader(HttpHeaderNames.HOST.toString()));
if (builder.charAt(builder.length() - 1) != '/') {
builder.append("/");
}
try {
MSF4JResponse.setBaseUri(new URI(builder.toString()));
} catch (URISyntaxException e) {
log.error("Error while setting the Base URI. " + e.getMessage(), e);
}
}
代码示例来源:origin: org.wso2.carbon.uis/org.wso2.carbon.uis
this.method = request.getHttpMethod();
String rawUri = request.getUri();
int uriPathEndIndex = rawUri.indexOf('?');
String rawUriPath, rawQueryString;
Map<String, String> httpHeaders = request.getHeaders().getRequestHeaders().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get(0)));
this.headers = Collections.unmodifiableMap(httpHeaders);
代码示例来源:origin: org.wso2.carbon.identity.gateway/org.wso2.carbon.identity.gateway.api
/**
* Update GatewayRequestBuilder.
*
* @param builder Builder.
* @param request MS4J request
* @throws GatewayClientException GatewayClientException
*/
protected void create(T builder, Request request)
throws GatewayClientException {
request.getHeaders().getAll().forEach(header -> {
builder.addHeader(header.getName(), header.getValue());
});
builder.setMethod(request.getHttpMethod());
builder.setContentType(request.getContentType());
builder.setRequestURI(request.getUri());
builder.setMethod(request.getHttpMethod());
builder.setAttributes((Map) request.getProperties());
builder.addParameter(Constants.QUERY_PARAMETERS,
(Serializable) request.getProperty(Constants.QUERY_PARAMETERS));
builder.addParameter(Constants.BODY_PARAMETERS, (Serializable) request.getProperty(Constants.BODY_PARAMETERS));
String[] queryStringParams = request.getUri().split("\\?");
if (queryStringParams.length > 1) {
builder.setQueryString(queryStringParams[1]);
} else {
builder.setQueryString(queryStringParams[0]);
}
if (logger.isDebugEnabled()) {
logger.debug("Successfully Updated the request builder in GatewayRequestBuilderFactory.");
}
}
代码示例来源:origin: org.wso2.carbon.analytics-common/org.wso2.carbon.analytics.msf4j.interceptor.common
} else {
for (String url : DataHolder.getInstance().getExcludeURLList()) {
if (request.getUri().matches(url)) {
return true;
Headers headers = request.getHeaders();
String authorizationHeader = request.getHeader(IdPClientConstants.AUTHORIZATION_HEADER);
if (authorizationHeader != null) {
String headerPrefix = authorizationHeader.split(" ")[0];
String username = idPClient.authenticate(accessToken);
if (username != null) {
request.setProperty(InterceptorConstants.PROPERTY_USERNAME, username);
return true;
String userName = authHeader.split(":")[0];
String password = authHeader.split(":")[1];
String appName = request.getUri().split("/\\|?")[1];
.equals(IdPClientConstants.LoginStatus.LOGIN_FAILURE)) {
LOGGER.debug("Authentication failed for the request to '{}' due to Error: '{}', " +
"Error Description: '{}'.", request.getUri(),
loginValues.get(IdPClientConstants.ERROR),
loginValues.get(IdPClientConstants.ERROR_DESCRIPTION));
response.setEntity("Authentication failed for the request to : '" + request.getUri() +
"' due to Error :'" + loginValues.get(IdPClientConstants.ERROR) + "'," +
" Error Description : '" + loginValues.get(IdPClientConstants.ERROR_DESCRIPTION))
request.setProperty(InterceptorConstants.PROPERTY_USERNAME, userName);
代码示例来源:origin: org.wso2.msf4j/msf4j-core
String requestPath = request.getUri();
if (requestPath.endsWith("/")) {
requestPath = requestPath.substring(0, requestPath.length() - 1);
.filter(e -> e.getValue().getHttpMethod().contains(request.getHttpMethod()) &&
finalRequestPath.matches(e.getKey().getPath().replaceAll(GROUP_PATTERN,
GROUP_PATTERN_REGEX)) &&
.collect(Collectors.toList());
Optional<Map.Entry<SubresourceKey, HttpResourceModel>> entry = entries.stream().filter(
entryPair -> entryPair.getValue().matchConsumeMediaType(request.getContentType()) &&
entryPair.getValue().matchProduceMediaType(request.getAcceptTypes()))
.findFirst();
.getValue()
.matchConsumeMediaType(
request.getContentType()) &&
entryPair
.getValue()
.matchProduceMediaType(
request.getAcceptTypes()))
.findFirst();
if (entry.isPresent()) {
httpSubResourceModelProcessor.setFormParameters(formParameters);
responder.setMediaType(
Util.getResponseType(request.getAcceptTypes(), resourceModel.getProducesMediaTypes()));
HttpMethodInfo httpMethodInfo = httpSubResourceModelProcessor
.buildHttpMethodInfo(request, responder, groupNameValues);
代码示例来源:origin: org.wso2.msf4j/msf4j-core
@Override
public boolean interceptRequest(Request request, Response response) throws Exception {
SecurityErrorCode errorCode;
try {
HttpHeaders headers = request.getHeaders();
String authHeader = headers.getHeaderString(AUTHORIZATION_HTTP_HEADER);
if (authHeader != null && !authHeader.isEmpty()) {
return validateToken(authHeader);
} else {
throw new MSF4JSecurityException(SecurityErrorCode.AUTHENTICATION_FAILURE,
"Missing Authorization header is the request.`");
}
} catch (MSF4JSecurityException e) {
errorCode = e.getErrorCode();
log.error(e.getMessage() + " Requested Path: " + request.getUri());
}
handleSecurityError(errorCode, response);
return false;
}
代码示例来源:origin: wso2/msf4j
Request request, MicroservicesRegistryImpl microservicesRegistry, boolean isSubResource) throws Exception {
Class<?> clazz = httpMethodInfo.method.getDeclaringClass();
request.setProperty(MSF4JConstants.METHOD_PROPERTY_NAME, httpMethodInfo.method); // Required for analytics
((ArrayList<Class<?>>) request.getProperty(DECLARING_CLASS_LIST_CONSTANT)).add(0, clazz);
((ArrayList<Method>) request.getProperty(RESOURCE_METHOD_LIST_CONSTANT)).add(0, httpMethodInfo.method);
return httpMethodInfo
.invokeSubResource(request, destination, returnedValue, microservicesRegistry);
代码示例来源:origin: org.wso2.msf4j/msf4j-core
/**
* Get the request's content type.
*
* @return String request's content type
*/
public String getContentType() {
return this.request.getHeader("Content-Type");
}
代码示例来源:origin: org.wso2.carbon.auth/org.wso2.carbon.auth.rest.api.authenticators
/**
* Get defined HTTP methods in the swagger definition as a comma separated string
*
* @param request Request
* @return Http Methods as a comma separated string
*/
public static RestAPIInfo getElectedRestApiInfo(Request request) {
if (request.getProperty(RestAPIConstants.ELECTED_BASE_PATH) != null) {
return ServiceReferenceHolder.getInstance().getSwaggerDefinitionMap().get(request.getProperty
(RestAPIConstants.ELECTED_BASE_PATH));
}
String requestURI = request.getUri().toLowerCase(Locale.ENGLISH);
RestAPIInfo electedSwagger = null;
for (String basePath : ServiceReferenceHolder.getInstance().getSwaggerDefinitionMap().keySet()) {
if (requestURI.contains(basePath)) {
electedSwagger = ServiceReferenceHolder.getInstance().getSwaggerDefinitionMap().get(basePath);
break;
}
}
if (electedSwagger != null) {
request.setProperty(RestAPIConstants.ELECTED_BASE_PATH, electedSwagger.getBasePath());
}
return electedSwagger;
}
代码示例来源:origin: wso2/msf4j
@Override
public URI getUri() {
return URI.create(req.getUri());
}
代码示例来源:origin: wso2/msf4j
long time = new Date().getTime();
serviceMethodInfo.setAttribute(RESPONDER_ATTRIBUTE, responder);
String traceOriginId = request.getHeader(TracingConstants.TRACE_ORIGIN_ID_HEADER);
String serverTraceId;
if (traceOriginId == null) {
serverTraceId = TracingUtil.generateUniqueId();
String traceParentId = request.getHeader(TracingConstants.TRACE_ID_HEADER);
TraceEvent serverTraceEvent = new TraceEvent(
TracingConstants.SERVER_TRACE_START,
serverTraceEvent.setInstanceName(instanceName);
serverTraceEvent.setParentId(traceParentId);
serverTraceEvent.setHttpMethod(request.getHttpMethod());
serverTraceEvent.setUrl(request.getUri());
TracingEventTracker.setTraceEvent(serverTraceEvent);
serviceMethodInfo.setAttribute(TRACE_EVENT_ATTRIBUTE, serverTraceEvent);
代码示例来源:origin: org.wso2.carbon.auth/org.wso2.carbon.auth.rest.api.authenticators
@Override
public boolean interceptRequest(Request request, Response response) {
Method method = (Method) request.getProperty(MSF4JConstants.METHOD_PROPERTY_NAME);
String origin = request.getHeader(RestAPIConstants.ORIGIN_HEADER);
String allowedOrigin = RestApiUtil.getAllowedOrigin(origin);
if (allowedOrigin != null) {
if (request.getHttpMethod().equalsIgnoreCase(RestAPIConstants.HTTP_OPTIONS)) {
try {
String definedHttpMethods = RestApiUtil.getDefinedMethodHeadersInSwaggerContent(request, method);
代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.msf4j.interceptor.common
@Override
public boolean interceptRequest(Request request, Response response) throws Exception {
String authorizationHeader = request.getHeader(HEADER_AUTHORIZATION);
if (authorizationHeader != null) {
byte[] decodedAuthHeader = Base64.getDecoder().decode(authorizationHeader.split(" ")[1]);
String authHeader = new String(decodedAuthHeader);
String userName = authHeader.split(":")[0];
String password = authHeader.split(":")[1];
CarbonMessage carbonMessage = new DefaultCarbonMessage();
carbonMessage.setHeader(HEADER_AUTHORIZATION, "Basic " + Base64.getEncoder()
.encodeToString((userName + ":" + password).getBytes())
);
/*
ProxyCallbackHandler callbackHandler = new ProxyCallbackHandler(carbonMessage);
LoginContext loginContext;
loginContext = new LoginContext("CarbonSecurityConfig", callbackHandler);
loginContext.login();
*/
return true;
}
LOG.error("Authorization header not found for request : '" + request.getUri() + "'");
response.setStatus(javax.ws.rs.core.Response.Status.UNAUTHORIZED.getStatusCode())
.setEntity("Authorization is required to access uri '" + request.getUri() + "'. Please set " +
"the authentication header and try again.")
.setMediaType(MediaType.TEXT_PLAIN);
return false;
}
代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.authenticator
if (AuthenticatorConstants.REFRESH_GRANT.equals(grantType)) {
refToken = AuthUtil
.extractTokenFromHeaders(request.getHeaders(), AuthenticatorConstants.REFRESH_TOKEN_2);
if (refToken == null) {
ErrorDTO errorDTO = new ErrorDTO();
refreshTokenCookie, refreshTokenHttpOnlyCookie).header(AuthenticatorConstants.
REFERER_HEADER,
(request.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER) != null && request
.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER)
.equals(request.getHeader(AuthenticatorConstants.REFERER_HEADER))) ?
"" :
request.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER) != null ?
request.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER) :
"").build();
} else {
.header(AuthenticatorConstants.
REFERER_HEADER,
(request.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER) != null && request
.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER)
.equals(request.getHeader(AuthenticatorConstants.REFERER_HEADER))) ?
"" :
request.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER) != null ?
request.getHeader(AuthenticatorConstants.X_ALT_REFERER_HEADER) :
"").build();
代码示例来源:origin: org.wso2.carbon.auth/org.wso2.carbon.auth.rest.api.commons
RestAPIAuthSecurityException {
String authHeader = request.getHeader(RestApiConstants.AUTHORIZATION_HTTP_HEADER);
if (authHeader != null) {
String authEncoded = authHeader.substring(RestApiConstants.AUTH_TYPE_BASIC.length()).trim();
boolean authenticated = userStoreManager.doAuthenticate(username, password);
if (authenticated) {
request.setProperty(RestAPIConstants.LOGGED_IN_USER, username);
request.setProperty(RestAPIConstants.LOGGED_IN_PSEUDO_USER, userNameMapper
.getLoggedInPseudoNameFromUserID(username));
return true;
代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.rest.api.webserver
@Override public Response publisherGet(String accept, String ifNoneMatch, String ifModifiedSince, Request request)
throws NotFoundException {
String rawUri = request.getUri();
String hostName = String.valueOf(request.getProperties().get("HOST"));
String port = String.valueOf(request.getProperties().get("LISTENER_PORT"));
String protocol = String.valueOf(request.getProperties().get("PROTOCOL"));
String absURL = protocol + "://" + hostName + ":" + port + rawUri;
String path;
内容来源于网络,如有侵权,请联系作者删除!