@Override public Response handle(String dataType, Serializable data) throws HandlerNotFoundException { log.debug("handling datatype: " + dataType); RequestUploadHandler handler = Optional.ofNullable(uploadHandlers.get(dataType).getRequestHandlerInstance()) .orElseThrow(() -> new HandlerNotFoundException(dataType)); return handler.upload(dataType, data); }
public void uploadHandlerRemoved(ServiceReference<RequestUploadHandler> ref) { RequestUploadHandler handler = registeredUploadHandlers.remove(ref); System.out.println("Un-Registering Upload Handler: " + handler.getClass().getName()); handler .getHandlerDataTypes() .forEach( (k, v) -> { uploadHandlers.remove(k); }); uploadHandlers.remove(handler.getClass().getName()); }
@ServiceDependency(removed = "uploadHandlerRemoved", required = false) public void uploadHandlerAdded( ServiceReference<RequestUploadHandler> ref, RequestUploadHandler uploadHandler) { System.out.println("Registering Upload Handler: " + uploadHandler.getClass().getName()); registeredUploadHandlers.put(ref, uploadHandler); uploadHandler .getHandlerDataTypes() .forEach( (k, v) -> { uploadHandlers.put( k, new UploadHandlerMapping() .setDataType(k) .setAuthorizationHandlerClassName(v.getName()) .setRequestHandlerInstance(uploadHandler)); }); }