Skip to content
Open
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 @@ -48,9 +48,11 @@
import java.util.Arrays;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.Servlet;
Expand All @@ -67,6 +69,7 @@ public class UIBundleDeployer implements SynchronousBundleListener {
new BundleBasedUIResourceProvider(bundleResourcePath);
//Used to hide the menus in the management console.
private List<String> hideMenuIds = new ArrayList<>();
private Map<String, org.osgi.framework.ServiceRegistration<?>> servletRegistrations = new HashMap<>();

public UIResourceProvider getBundleBasedUIResourcePrvider() {
return bundleBasedUIResourceProvider;
Expand Down Expand Up @@ -290,34 +293,31 @@ private void processServletDefinitions(Component component, String action) throw
if (component != null
&& component.getServlets() != null
&& component.getServlets().length > 0) {
HttpService httpService;
try {
httpService = CarbonUIServiceComponent.getHttpService();
} catch (Exception e) {
throw new CarbonException("An instance of HttpService is not available");
}
org.wso2.carbon.ui.deployment.beans.Servlet[] servletDefinitions = component.getServlets();
for (int a = 0; a < servletDefinitions.length; a++) {
org.wso2.carbon.ui.deployment.beans.Servlet servlet = servletDefinitions[a];
if (CarbonConstants.ADD_UI_COMPONENT.equals(action)) {
if (log.isTraceEnabled()) {
log.trace("Registering sevlet : " + servlet);
log.trace("Registering servlet : " + servlet);
}
try {
Class clazz = Class.forName(servlet.getServletClass());
//TODO : allow servlet parameters to be passed
Dictionary params = new Hashtable();
httpService.registerServlet(servlet.getUrlPatten(),
(Servlet) clazz.newInstance(), params,
httpContext);
Servlet servletInstance = (Servlet) clazz.newInstance();
Dictionary<String, String> props = new Hashtable<>();
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN,
servlet.getUrlPatten());
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
"(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME
+ "=carbonContext)");
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME,
servlet.getName() != null ? servlet.getName()
: servlet.getServletClass());
org.osgi.framework.ServiceRegistration<?> reg =
Comment on lines +313 to +315
Copy link
Copy Markdown

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
servlet.getName() != null ? servlet.getName()
: servlet.getServletClass());
org.osgi.framework.ServiceRegistration<?> reg =
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME,
servlet.getName() != null ? servlet.getName()
: servlet.getServletClass());
log.info("Registering servlet: " + servlet.getServletClass() + " at path: " + servlet.getUrlPatten());

bundleContext.registerService(
Servlet.class.getName(), servletInstance, props);
servletRegistrations.put(servlet.getUrlPatten(), reg);
} catch (ClassNotFoundException e) {
log.error("Servlet class : " + servlet.getServletClass() + " not found.", e);
} catch (ServletException e) {
log.error("Problem registering Servlet class : " +
servlet.getServletClass() + ".", e);
} catch (NamespaceException e) {
log.error("Problem registering Servlet class : " +
servlet.getServletClass() + ".", e);
} catch (InstantiationException e) {
log.error("Problem registering Servlet class : " +
servlet.getServletClass() + ".", e);
Expand All @@ -327,15 +327,16 @@ private void processServletDefinitions(Component component, String action) throw
}
} else if (CarbonConstants.REMOVE_UI_COMPONENT.equals(action)) {
if (log.isTraceEnabled()) {
log.trace("Unregistering sevlet : " + servlet);
log.trace("Unregistering servlet : " + servlet);
}
org.osgi.framework.ServiceRegistration<?> reg =
servletRegistrations.remove(servlet.getUrlPatten());
if (reg != null) {
reg.unregister();
}
Comment on lines +334 to 336
Copy link
Copy Markdown

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
if (reg != null) {
reg.unregister();
}
if (reg != null) {
reg.unregister();
}
log.info("Unregistered servlet at path: " + servlet.getUrlPatten());

httpService.unregister(servlet.getUrlPatten());
}
}

}


}

private void processCustomRegistryDefinitions(Component component, String action) throws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,17 @@ private static String getServerURL(String url, ConfigurationContext configCtx) {
String carbonMgtParam = "${carbon.management.port}";
String mgtTransport = getManagementTransport();
String returnUrl = url;
if (returnUrl == null) {
String httpsPort =
CarbonUtils.getTransportPort(configCtx, mgtTransport) + "";
Comment on lines 841 to +844
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 3

Suggested change
String returnUrl = url;
if (returnUrl == null) {
String httpsPort =
CarbonUtils.getTransportPort(configCtx, mgtTransport) + "";
String returnUrl = url;
if (returnUrl == null) {
log.debug("Server URL is null, constructing default URL");
String httpsPort =

String host = System.getProperty(ServerConstants.LOCAL_IP_ADDRESS, "localhost");
String context = ServerConfiguration.getInstance().getFirstProperty("WebContextRoot");
if (context == null || context.equals("/")) {
context = "";
}
returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/";
return returnUrl;
}
Comment on lines +849 to +852
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 4

Suggested change
}
returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/";
return returnUrl;
}
}
returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/";
log.info("Constructed server URL: " + returnUrl);
return returnUrl;

if (returnUrl.indexOf(carbonMgtParam) != -1) {
String httpsPort =
CarbonUtils.getTransportPort(configCtx, mgtTransport) + "";
Expand Down