use of org.wso2.carbon.apimgt.gateway.MethodStats in project carbon-apimgt by wso2.
the class APIKeyValidator method getResourceAuthenticationScheme.
@MethodStats
public String getResourceAuthenticationScheme(MessageContext synCtx) throws APISecurityException {
String authType = "";
List<VerbInfoDTO> verbInfoList;
try {
verbInfoList = findMatchingVerb(synCtx);
if (verbInfoList != null && verbInfoList.toArray().length > 0) {
for (VerbInfoDTO verb : verbInfoList) {
authType = verb.getAuthType();
if (authType == null || !StringUtils.capitalize(APIConstants.AUTH_TYPE_NONE.toLowerCase()).equals(authType)) {
authType = StringUtils.capitalize(APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN.toLowerCase());
break;
}
}
synCtx.setProperty(APIConstants.VERB_INFO_DTO, verbInfoList);
}
} catch (ResourceNotFoundException e) {
log.error("Could not find matching resource for request", e);
return APIConstants.NO_MATCHING_AUTH_SCHEME;
}
if (!authType.isEmpty()) {
return authType;
} else {
// No matching resource found. return the highest level of security
return APIConstants.NO_MATCHING_AUTH_SCHEME;
}
}
use of org.wso2.carbon.apimgt.gateway.MethodStats in project carbon-apimgt by wso2.
the class APIKeyValidator method getAPIProductURITemplates.
@MethodStats
protected ArrayList<URITemplate> getAPIProductURITemplates(MessageContext messageContext, String context, String apiVersion) throws APISecurityException {
if (uriTemplates == null) {
synchronized (this) {
if (uriTemplates == null) {
String swagger = (String) messageContext.getProperty(APIMgtGatewayConstants.OPEN_API_STRING);
if (swagger != null) {
APIDefinition oasParser;
try {
oasParser = OASParserUtil.getOASParser(swagger);
uriTemplates = new ArrayList<>();
uriTemplates.addAll(oasParser.getURITemplates(swagger));
return uriTemplates;
} catch (APIManagementException e) {
log.error("Error while parsing swagger content to get URI Templates", e);
}
}
uriTemplates = dataStore.getAPIProductURITemplates(context, apiVersion);
}
}
}
return uriTemplates;
}
use of org.wso2.carbon.apimgt.gateway.MethodStats in project carbon-apimgt by wso2.
the class APIManagerExtensionHandler method mediate.
@MethodStats
public boolean mediate(MessageContext messageContext, String direction) {
// In order to avoid a remote registry call occurring on each invocation, we
// directly get the extension sequences from the local registry.
Map localRegistry = messageContext.getConfiguration().getLocalRegistry();
Object sequence = localRegistry.get(EXT_SEQUENCE_PREFIX + direction);
if (sequence instanceof Mediator) {
if (!((Mediator) sequence).mediate(messageContext)) {
return false;
}
}
String apiName = (String) messageContext.getProperty(RESTConstants.SYNAPSE_REST_API);
sequence = localRegistry.get(apiName + "--" + direction);
if (sequence instanceof Mediator) {
return ((Mediator) sequence).mediate(messageContext);
}
return true;
}
use of org.wso2.carbon.apimgt.gateway.MethodStats in project carbon-apimgt by wso2.
the class APIManagerExtensionHandler method handleRequest.
@MethodStats
public boolean handleRequest(MessageContext messageContext) {
// (only for graphQL APIs)
if (messageContext.getProperty(APIConstants.API_TYPE) != null && APIConstants.GRAPHQL_API.equals(messageContext.getProperty(APIConstants.API_TYPE).toString())) {
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(Constants.Configuration.HTTP_METHOD, messageContext.getProperty(APIConstants.HTTP_VERB));
}
Timer.Context context = startMetricTimer(DIRECTION_IN);
long executionStartTime = System.nanoTime();
TracingSpan requestMediationSpan = null;
if (Util.tracingEnabled()) {
TracingSpan responseLatencySpan = (TracingSpan) messageContext.getProperty(APIMgtGatewayConstants.RESOURCE_SPAN);
TracingTracer tracer = Util.getGlobalTracer();
requestMediationSpan = Util.startSpan(APIMgtGatewayConstants.REQUEST_MEDIATION, responseLatencySpan, tracer);
}
try {
boolean isMediated = mediate(messageContext, DIRECTION_IN);
if (isMediated) {
String requestDestination = null;
EndpointReference objectTo = ((Axis2MessageContext) messageContext).getAxis2MessageContext().getOptions().getTo();
if (objectTo != null) {
requestDestination = objectTo.getAddress();
}
if (requestDestination != null) {
messageContext.setProperty(APIMgtGatewayConstants.SYNAPSE_ENDPOINT_ADDRESS, requestDestination);
}
}
return isMediated;
} catch (Exception e) {
if (Util.tracingEnabled() && requestMediationSpan != null) {
Util.setTag(requestMediationSpan, APIMgtGatewayConstants.ERROR, APIMgtGatewayConstants.REQUEST_MEDIATION_ERROR);
}
throw e;
} finally {
if (Util.tracingEnabled()) {
Util.finishSpan(requestMediationSpan);
}
messageContext.setProperty(APIMgtGatewayConstants.REQUEST_MEDIATION_LATENCY, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - executionStartTime));
stopMetricTimer(context);
}
}
use of org.wso2.carbon.apimgt.gateway.MethodStats in project carbon-apimgt by wso2.
the class APIManagerExtensionHandler method handleResponse.
@MethodStats
public boolean handleResponse(MessageContext messageContext) {
Timer.Context context = startMetricTimer(DIRECTION_OUT);
long executionStartTime = System.nanoTime();
TracingSpan responseMediationSpan = null;
if (Util.tracingEnabled()) {
TracingSpan responseLatencySpan = (TracingSpan) messageContext.getProperty(APIMgtGatewayConstants.RESOURCE_SPAN);
TracingTracer tracer = Util.getGlobalTracer();
responseMediationSpan = Util.startSpan(APIMgtGatewayConstants.RESPONSE_MEDIATION, responseLatencySpan, tracer);
}
try {
return mediate(messageContext, DIRECTION_OUT);
} catch (Exception e) {
if (Util.tracingEnabled() && responseMediationSpan != null) {
Util.setTag(responseMediationSpan, APIMgtGatewayConstants.ERROR, APIMgtGatewayConstants.RESPONSE_MEDIATION_ERROR);
}
throw e;
} finally {
if (Util.tracingEnabled()) {
Util.finishSpan(responseMediationSpan);
}
messageContext.setProperty(APIMgtGatewayConstants.RESPONSE_MEDIATION_LATENCY, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - executionStartTime));
stopMetricTimer(context);
}
}
Aggregations