The code example below requests the resource of the HTTP server start page, if such is present.
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.prosyst.mbs.services.http.HttpHelper;
. . .
BundleContext bc = null;
ServiceReference helperRef = null;
HttpHelper helper = null;
. . .
// Retrieving the HTTP Helper from the server framework
helperRef = bc.getServiceReference("com.prosyst.mbs.services.http.HttpHelper");
helper = (HttpHelper)bc.getService(helperRef);
// Processing a simple HTTP Request
String input = "GET / HTTP/1.0\r\n\r\n";
byte[] outputBytes = helperServ.getOutput(input.getBytes());
String output = new String(outBytes);
. . .
You can retrieve the essential attributes of an alias using the HttpHelper interface and the AliasProperties interface. For clarification, consider the following code example:
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.prosyst.mbs.services.http.HttpHelper;
import com.prosyst.mbs.services.http.AliasProperties;
BundleContext bc = null;
ServiceReference helperRef = null;
HttpHelper helper = null;
String servName = "com.prosyst.mbs.services.http.HttpHelper";
. . .
// Retrieving the HTTP Helper from the server framework
helperRef = bc.getServiceReference(servName);
HttpHelper helper = (HttpHelper) bc.getService(helperRef);
AliasProperties[] aliases = helper.getAliases();
// Extracting registered aliases
for(int i=0; i<aliases.length; i++) {
String aliasName = aliases[i].getAlias();
}
. . .
For more technical details about the features of the HTTP Helper Service explore the OSGi Java APIs.