use of org.ballerinalang.net.uri.URITemplateException in project ballerina by ballerina-lang.
the class WebSocketServicesRegistry method addUpgradableServiceByName.
public void addUpgradableServiceByName(WebSocketService service, String basePath) {
basePath = urlDecode(basePath);
service.setBasePath(basePath);
try {
getUriTemplate().parse(basePath, service, new WebSocketDataElementFactory());
} catch (URITemplateException | UnsupportedEncodingException e) {
throw new BallerinaConnectorException(e.getMessage());
}
logger.info("Service deployed : " + service.getName() + " with context " + basePath);
}
use of org.ballerinalang.net.uri.URITemplateException in project ballerina by ballerina-lang.
the class HttpResourceDispatcher method findResource.
public static HttpResource findResource(HttpService service, HTTPCarbonMessage inboundRequest) throws BallerinaConnectorException {
String method = (String) inboundRequest.getProperty(HttpConstants.HTTP_METHOD);
String subPath = (String) inboundRequest.getProperty(HttpConstants.SUB_PATH);
subPath = sanitizeSubPath(subPath);
Map<String, String> resourceArgumentValues = new HashMap<>();
try {
HttpResource resource = service.getUriTemplate().matches(subPath, resourceArgumentValues, inboundRequest);
if (resource != null) {
inboundRequest.setProperty(HttpConstants.RESOURCE_ARGS, resourceArgumentValues);
inboundRequest.setProperty(HttpConstants.RESOURCES_CORS, resource.getCorsHeaders());
return resource;
} else {
if (method.equals(HttpConstants.HTTP_METHOD_OPTIONS)) {
handleOptionsRequest(inboundRequest, service);
} else {
inboundRequest.setProperty(HttpConstants.HTTP_STATUS_CODE, 404);
throw new BallerinaConnectorException("no matching resource found for path : " + inboundRequest.getProperty(HttpConstants.TO) + " , method : " + method);
}
return null;
}
} catch (URITemplateException e) {
throw new BallerinaConnectorException(e.getMessage());
}
}
use of org.ballerinalang.net.uri.URITemplateException 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.net.uri.URITemplateException in project ballerina by ballerina-lang.
the class WebSocketServicesRegistry method registerService.
public void registerService(WebSocketService service) {
String basePath = findFullWebSocketUpgradePath(service);
if (basePath == null) {
basePath = "/";
}
basePath = urlDecode(basePath);
service.setBasePath(basePath);
// TODO: Add websocket services to the service registry when service creation get available.
try {
getUriTemplate().parse(basePath, service, new WebSocketDataElementFactory());
} catch (URITemplateException | UnsupportedEncodingException e) {
throw new BallerinaConnectorException(e.getMessage());
}
logger.info("Service deployed : " + service.getName() + " with context " + basePath);
}
Aggregations