use of org.ballerinalang.connector.api.Annotation in project ballerina by ballerina-lang.
the class WebSocketServicesRegistry method findFullWebSocketUpgradePath.
/**
* Find the Full path for WebSocket upgrade.
*
* @param service {@link WebSocketService} which the full path should be found.
* @return the full path of the WebSocket upgrade.
*/
private String findFullWebSocketUpgradePath(WebSocketService service) {
// Find Base path for WebSocket
Annotation configAnnotation = WebSocketUtil.getServiceConfigAnnotation(service, HttpConstants.PROTOCOL_PACKAGE_HTTP);
String basePath = null;
if (configAnnotation != null) {
Struct annStruct = configAnnotation.getValue();
String annotationValue = annStruct.getStringField(HttpConstants.ANN_CONFIG_ATTR_BASE_PATH);
if (annotationValue != null && !annotationValue.trim().isEmpty()) {
basePath = refactorUri(annotationValue);
}
}
return basePath;
}
use of org.ballerinalang.connector.api.Annotation in project ballerina by ballerina-lang.
the class HttpResource method buildHttpResource.
public static HttpResource buildHttpResource(Resource resource, HttpService httpService) {
HttpResource httpResource = new HttpResource(resource, httpService);
Annotation resourceConfigAnnotation = getResourceConfigAnnotation(resource);
if (resourceConfigAnnotation == null) {
if (log.isDebugEnabled()) {
log.debug("resourceConfig not specified in the Resource instance, using default sub path");
}
httpResource.setPath(resource.getName());
httpResource.prepareAndValidateSignatureParams();
return httpResource;
}
Struct resourceConfig = resourceConfigAnnotation.getValue();
httpResource.setPath(resourceConfig.getStringField(PATH_FIELD));
httpResource.setMethods(getAsStringList(resourceConfig.getArrayField(METHODS_FIELD)));
httpResource.setConsumes(getAsStringList(resourceConfig.getArrayField(CONSUMES_FIELD)));
httpResource.setProduces(getAsStringList(resourceConfig.getArrayField(PRODUCES_FIELD)));
httpResource.setEntityBodyAttributeValue(resourceConfig.getStringField(BODY_FIELD));
httpResource.setCorsHeaders(CorsHeaders.buildCorsHeaders(resourceConfig.getStructField(CORS_FIELD)));
httpResource.setTransactionInfectable(resourceConfig.getBooleanField(TRANSACTION_INFECTABLE_FIELD));
processResourceCors(httpResource, httpService);
httpResource.prepareAndValidateSignatureParams();
return httpResource;
}
use of org.ballerinalang.connector.api.Annotation in project ballerina by ballerina-lang.
the class HttpService method buildHttpService.
public static HttpService buildHttpService(Service service) {
HttpService httpService = new HttpService(service);
Annotation serviceConfigAnnotation = getHttpServiceConfigAnnotation(service);
if (serviceConfigAnnotation == null) {
log.debug("serviceConfig not specified in the Service instance, using default base path");
// service name cannot start with / hence concat
httpService.setBasePath(HttpConstants.DEFAULT_BASE_PATH.concat(httpService.getName()));
} else {
Struct serviceConfig = serviceConfigAnnotation.getValue();
httpService.setBasePath(serviceConfig.getStringField(BASE_PATH_FIELD));
httpService.setCompression(serviceConfig.getEnumField(COMPRESSION_FIELD));
httpService.setCorsHeaders(CorsHeaders.buildCorsHeaders(serviceConfig.getStructField(CORS_FIELD)));
httpService.setWebSocketUpgradeConfig(serviceConfig.getStructField(WEBSOCKET_UPGRADE_FIELD));
}
List<HttpResource> resources = new ArrayList<>();
for (Resource resource : httpService.getBallerinaService().getResources()) {
HttpResource httpResource = HttpResource.buildHttpResource(resource, httpService);
try {
httpService.getUriTemplate().parse(httpResource.getPath(), httpResource, new HttpResourceElementFactory());
} catch (URITemplateException | UnsupportedEncodingException e) {
throw new BallerinaConnectorException(e.getMessage());
}
resources.add(httpResource);
}
httpService.setResources(resources);
httpService.setAllAllowedMethods(DispatcherUtil.getAllResourceMethods(httpService));
return httpService;
}
use of org.ballerinalang.connector.api.Annotation in project ballerina by ballerina-lang.
the class HttpUtil method setCompressionHeaders.
private static void setCompressionHeaders(Context context, HTTPCarbonMessage requestMsg, HTTPCarbonMessage outboundResponseMsg) {
Service serviceInstance = BLangConnectorSPIUtil.getService(context.getProgramFile(), context.getServiceInfo().getType());
Annotation configAnnot = getServiceConfigAnnotation(serviceInstance, PROTOCOL_PACKAGE_HTTP);
if (configAnnot == null) {
return;
}
String contentEncoding = outboundResponseMsg.getHeaders().get(HttpHeaderNames.CONTENT_ENCODING);
if (contentEncoding != null) {
return;
}
String compressionValue = configAnnot.getValue().getEnumField(ANN_CONFIG_ATTR_COMPRESSION);
String acceptEncodingValue = requestMsg.getHeaders().get(HttpHeaderNames.ACCEPT_ENCODING);
if (ALWAYS.equalsIgnoreCase(compressionValue)) {
if (acceptEncodingValue == null || HTTP_TRANSFER_ENCODING_IDENTITY.equals(acceptEncodingValue)) {
outboundResponseMsg.getHeaders().set(HttpHeaderNames.CONTENT_ENCODING, ENCODING_GZIP);
}
} else if (NEVER.equalsIgnoreCase(compressionValue)) {
outboundResponseMsg.getHeaders().set(HttpHeaderNames.CONTENT_ENCODING, HTTP_TRANSFER_ENCODING_IDENTITY);
}
}
use of org.ballerinalang.connector.api.Annotation in project ballerina by ballerina-lang.
the class WebSubHttpService method buildWebSubSubscriberHttpService.
/**
* Builds the HTTP service representation of the service.
*
* @param service the service for which the HTTP representation is built
* @return the built HttpService representation
*/
static HttpService buildWebSubSubscriberHttpService(Service service) {
WebSubHttpService httpService = new WebSubHttpService(service);
Annotation serviceConfigAnnotation = getWebSubSubscriberServiceConfigAnnotation(service);
if (serviceConfigAnnotation == null) {
logger.debug("ServiceConfig not specified in the Service instance, using default base path");
// service name cannot start with / hence concat
httpService.setBasePath(HttpConstants.DEFAULT_BASE_PATH.concat(httpService.getName()));
return httpService;
}
Struct serviceConfig = serviceConfigAnnotation.getValue();
httpService.setBasePath(serviceConfig.getStringField(BASE_PATH_FIELD));
List<HttpResource> resources = new ArrayList<>();
for (Resource resource : httpService.getBallerinaService().getResources()) {
HttpResource httpResource = WebSubHttpResource.buildWebSubHttpResource(resource, httpService);
resources.add(httpResource);
}
httpService.setResources(resources);
httpService.setAllAllowedMethods(DispatcherUtil.getAllResourceMethods(httpService));
return httpService;
}
Aggregations