Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.wso2.carbon.ui.tracker.AuthenticatorRegistry;
import org.wso2.carbon.ui.transports.FileDownloadServlet;
import org.wso2.carbon.ui.transports.FileUploadServlet;
import org.wso2.carbon.ui.transports.fileupload.FileUploadExecutorManager;
import org.wso2.carbon.ui.util.UIAnnouncementDeployer;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService;
Expand Down Expand Up @@ -228,6 +229,14 @@ public void start(BundleContext context) throws Exception {
uiResourceRegistry.setDefaultUIResourceProvider(
uiBundleDeployer.getBundleBasedUIResourcePrvider());

// Create FileUploadExecutorManager early and register it as an OSGi service
// This must be done BEFORE uiBundleDeployer.deploy() so that bundles with
// FileUploadExecutor configurations can be processed properly
ConfigurationContext contextForUpload = isLocalTransportMode ? serverConfigContext : clientConfigContext;
FileUploadExecutorManager fileUploadExecutorManager =
new FileUploadExecutorManager(context, contextForUpload, webContext);
context.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);
Comment on lines +235 to +238

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
ConfigurationContext contextForUpload = isLocalTransportMode ? serverConfigContext : clientConfigContext;
FileUploadExecutorManager fileUploadExecutorManager =
new FileUploadExecutorManager(context, contextForUpload, webContext);
context.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);
ConfigurationContext contextForUpload = isLocalTransportMode ? serverConfigContext : clientConfigContext;
FileUploadExecutorManager fileUploadExecutorManager =
new FileUploadExecutorManager(context, contextForUpload, webContext);
log.info("FileUploadExecutorManager initialized for context: " + (isLocalTransportMode ? "server" : "client"));
context.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);

Comment on lines +236 to +238

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
FileUploadExecutorManager fileUploadExecutorManager =
new FileUploadExecutorManager(context, contextForUpload, webContext);
context.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);
FileUploadExecutorManager fileUploadExecutorManager =
new FileUploadExecutorManager(context, contextForUpload, webContext);
log.info("FileUploadExecutorManager created for context: " + webContext);
context.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);


HttpContext commonContext =
new CarbonSecuredHttpContext(context.getBundle(), "/web", uiResourceRegistry, registry);

Expand All @@ -251,12 +260,8 @@ public void start(BundleContext context) throws Exception {
context.registerService(Servlet.class, fileDownloadServlet, fileDownloadServletProperties);

// Register file upload servlet using HTTP Whiteboard pattern
Servlet fileUploadServlet;
if (isLocalTransportMode) {
fileUploadServlet = new FileUploadServlet(context, serverConfigContext, webContext);
} else {
fileUploadServlet = new FileUploadServlet(context, clientConfigContext, webContext);
}
// Use the already-created fileUploadExecutorManager
Servlet fileUploadServlet = new FileUploadServlet(context, contextForUpload, webContext, fileUploadExecutorManager);
Comment on lines +263 to +264

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
// Use the already-created fileUploadExecutorManager
Servlet fileUploadServlet = new FileUploadServlet(context, contextForUpload, webContext, fileUploadExecutorManager);
// Use the already-created fileUploadExecutorManager
Servlet fileUploadServlet = new FileUploadServlet(context, contextForUpload, webContext, fileUploadExecutorManager);
if (log.isDebugEnabled()) {
log.debug("FileUploadServlet created with existing FileUploadExecutorManager");
}

Comment on lines +263 to +264

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
// Use the already-created fileUploadExecutorManager
Servlet fileUploadServlet = new FileUploadServlet(context, contextForUpload, webContext, fileUploadExecutorManager);
// Use the already-created fileUploadExecutorManager
Servlet fileUploadServlet = new FileUploadServlet(context, contextForUpload, webContext, fileUploadExecutorManager);
log.debug("FileUploadServlet created with FileUploadExecutorManager");

Dictionary<String, String> fileUploadServletProperties = new Hashtable<>();
fileUploadServletProperties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN,
"/carbon/fileupload/*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ public FileUploadServlet(BundleContext context, ConfigurationContext configCtx,
this.webContext = webContext;
}

/**
* Constructor that accepts a pre-created FileUploadExecutorManager.
* This is used when the manager needs to be registered as an OSGi service before
* bundle deployment occurs.
*/
public FileUploadServlet(BundleContext context, ConfigurationContext configCtx,
String webContext, FileUploadExecutorManager executorManager) {
this.bundleContext = context;
this.configContext = configCtx;
this.webContext = webContext;
this.fileUploadExecutorManager = executorManager;
}

protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

Expand All @@ -71,9 +84,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res)
public void init(ServletConfig servletConfig) throws ServletException {
this.servletConfig = servletConfig;
try {
fileUploadExecutorManager = new FileUploadExecutorManager(bundleContext, configContext, webContext);
//Registering FileUploadExecutor Manager as an OSGi service
bundleContext.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);
// Only create a new FileUploadExecutorManager if one wasn't provided via constructor
if (fileUploadExecutorManager == null) {
fileUploadExecutorManager = new FileUploadExecutorManager(bundleContext, configContext, webContext);
//Registering FileUploadExecutor Manager as an OSGi service
bundleContext.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);
}
} catch (CarbonException e) {
log.error("Exception occurred while trying to initialize FileUploadServlet", e);
throw new ServletException(e);
Expand All @@ -83,4 +99,4 @@ public void init(ServletConfig servletConfig) throws ServletException {
public ServletConfig getServletConfig() {
return this.servletConfig;
}
}
}