本文整理了Java中org.wso2.msf4j.Request.getUri
方法的一些代码示例,展示了Request.getUri
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getUri
方法的具体详情如下:
包路径:org.wso2.msf4j.Request
类名称:Request
方法名:getUri
暂无
代码示例来源:origin: wso2/msf4j
@Override
public URI getUri() {
return URI.create(req.getUri());
}
代码示例来源:origin: wso2/msf4j
@Override
public boolean interceptRequest(Request request, Response response) throws Exception {
log.info("Logging HTTP request { HTTPMethod: " + request.getHttpMethod() + ", URI: " + request.getUri() + "}");
return true;
}
}
代码示例来源: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: org.wso2.msf4j.samples/interceptor-common
@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
private HTTPCarbonMessage getHttpCarbonMessage(Request request) throws HandlerException {
Class<?> clazz = request.getClass();
try {
Method retrieveCarbonMsg = clazz.getDeclaredMethod("getHttpCarbonMessage");
retrieveCarbonMsg.setAccessible(true);
return (HTTPCarbonMessage) retrieveCarbonMsg.invoke(request);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new HandlerException(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR,
String.format("Error in executing request: %s %s", request.getHttpMethod(),
request.getUri()), e);
}
}
代码示例来源:origin: org.wso2.msf4j/msf4j-core
private HTTPCarbonMessage getHttpCarbonMessage(Request request) throws HandlerException {
Class<?> clazz = request.getClass();
try {
Method retrieveCarbonMsg = clazz.getDeclaredMethod("getHttpCarbonMessage");
retrieveCarbonMsg.setAccessible(true);
return (HTTPCarbonMessage) retrieveCarbonMsg.invoke(request);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new HandlerException(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR,
String.format("Error in executing request: %s %s", request.getHttpMethod(),
request.getUri()), e);
}
}
代码示例来源:origin: org.ballerinalang/composer-server-core
@GET
public Response handleGet(@Context Request request) {
String requestedPath = request.getUri();
String publicFolder = serverConfig.getPublicPath();
String targetFilePath = publicFolder + File.separator;
if (requestedPath.trim().length() == 0 || requestedPath.endsWith("/")) {
targetFilePath += "index.html";
} else if (requestedPath.indexOf('?') != -1) {
targetFilePath += requestedPath.substring(0, requestedPath.indexOf('?'));
} else {
targetFilePath += requestedPath;
}
File file = new File(targetFilePath);
if (file.exists()) {
return Response.ok(file).build();
}
return Response.status(Response.Status.NOT_FOUND).build();
}
代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.siddhi.editor.core
@GET
@Path("/**")
public Response handleGet(@Context Request request) throws FileNotFoundException {
String rawUri = request.getUri().replaceFirst("^/editor", "");
String rawUriPath, mimeType;
if (rawUri == null || rawUri.trim().length() == 0 || "/".equals(rawUri)) {
rawUriPath = "/index.html";
} else {
int uriPathEndIndex = rawUri.indexOf('?');
if (uriPathEndIndex != -1) {
// handling query Params.
rawUriPath = rawUri.substring(0, uriPathEndIndex);
} else {
rawUriPath = rawUri;
}
}
try {
mimeType = MimeMapper.getMimeType(FilenameUtils.getExtension(rawUriPath));
} catch (Throwable ignored) {
mimeType = "text/plain";
}
File file = getResourceAsFile("/web" + rawUriPath);
if (file != null) {
return Response.ok(new FileInputStream(file)).type(mimeType).build();
}
log.error(" File not found [" + rawUriPath + "], Requesting path [" + rawUriPath + "] ");
return Response.status(Response.Status.NOT_FOUND).build();
}
代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.business.rules.templates.editor.core
@GET
@Path("/**")
public Response handleGet(@Context Request request) throws FileNotFoundException {
String rawUri = request.getUri().replaceFirst("^/template-editor", "");
String rawUriPath, mimeType;
if (rawUri == null || rawUri.trim().length() == 0 || "/".equals(rawUri)) {
rawUriPath = "/index.html";
} else {
int uriPathEndIndex = rawUri.indexOf('?');
if (uriPathEndIndex != -1) {
// handling query Params.
rawUriPath = rawUri.substring(0, uriPathEndIndex);
} else {
rawUriPath = rawUri;
}
}
try {
mimeType = MimeMapper.getMimeType(FilenameUtils.getExtension(rawUriPath));
} catch (Throwable ignored) {
mimeType = "text/plain";
}
File file = getResourceAsFile("/web" + rawUriPath);
if (file != null) {
return Response.ok(new FileInputStream(file)).type(mimeType).build();
}
log.error(" File not found [" + rawUriPath + "], Requesting path [" + rawUriPath + "] ");
return Response.status(Response.Status.NOT_FOUND).build();
}
代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.msf4j.interceptor.common
@Override
public boolean onRequestInterceptionError(Request request, Response response, Exception e) {
if (e instanceof LoginException) {
LOG.error("Authorization invalid for request : '" + request.getUri() + "'", e);
response.setEntity("Login credential is not valid in accessing the uri '" + request.getUri() + "'. " +
"Please check the credentials and try again.")
.setMediaType(MediaType.TEXT_PLAIN)
.setStatus(javax.ws.rs.core.Response.Status.UNAUTHORIZED.getStatusCode());
return false;
}
String message = "Exception while executing request interceptor '" + this.getClass() + "' for uri : '" +
request.getUri() + "'";
LOG.error(message, e);
response.setEntity(message)
.setMediaType(MediaType.TEXT_PLAIN)
.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return false;
}
}
代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.analytics.msf4j.interceptor.common
@Override
public boolean onRequestInterceptionError(Request request, Response response, Exception e) {
if (e instanceof AuthenticationException) {
LOGGER.debug("Authorization invalid for request '{}'.", request.getUri(), e);
response.setEntity(e.getMessage())
.setMediaType(MediaType.TEXT_PLAIN)
.setStatus(javax.ws.rs.core.Response.Status.UNAUTHORIZED.getStatusCode());
return false;
}
String message = "Exception while executing request interceptor '" + this.getClass() + "' for uri : '" +
request.getUri() + "'. Error: '" + e.getMessage() + "'";
LOGGER.debug(message, e);
response.setEntity(message)
.setMediaType(MediaType.TEXT_PLAIN)
.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return false;
}
代码示例来源:origin: org.wso2.carbon.analytics-common/org.wso2.carbon.analytics.msf4j.interceptor.common
@Override
public boolean onRequestInterceptionError(Request request, Response response, Exception e) {
if (e instanceof AuthenticationException) {
LOGGER.debug("Authorization invalid for request '{}'.", request.getUri(), e);
response.setEntity(e.getMessage())
.setMediaType(MediaType.TEXT_PLAIN)
.setStatus(javax.ws.rs.core.Response.Status.UNAUTHORIZED.getStatusCode());
return false;
}
String message = "Exception while executing request interceptor '" + this.getClass() + "' for uri : '" +
request.getUri() + "'. Error: '" + e.getMessage() + "'";
LOGGER.debug(message, e);
response.setEntity(message)
.setMediaType(MediaType.TEXT_PLAIN)
.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return false;
}
}
代码示例来源: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.uiserver/org.wso2.carbon.uiserver
String rawUri = request.getUri();
int uriPathEndIndex = rawUri.indexOf('?');
String rawUriPath, rawQueryString;
代码示例来源: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
@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: 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
httpMonitoringEvent.setServiceName(serviceName);
httpMonitoringEvent.setServiceMethod(serviceMethod);
httpMonitoringEvent.setRequestUri(request.getUri());
httpMonitoringEvent.setServiceContext(servicePath);
代码示例来源: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: wso2/msf4j
serverTraceEvent.setParentId(traceParentId);
serverTraceEvent.setHttpMethod(request.getHttpMethod());
serverTraceEvent.setUrl(request.getUri());
TracingEventTracker.setTraceEvent(serverTraceEvent);
serviceMethodInfo.setAttribute(TRACE_EVENT_ATTRIBUTE, serverTraceEvent);
内容来源于网络,如有侵权,请联系作者删除!