本文整理汇总了Java中org.osgi.service.http.HttpContext类的典型用法代码示例。如果您正苦于以下问题:Java HttpContext类的具体用法?Java HttpContext怎么用?Java HttpContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpContext类属于org.osgi.service.http包,在下文中一共展示了HttpContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerServlet
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
public void registerServlet(String path, Servlet servlet, Dictionary dictionary, HttpContext httpContext) {
Map info = new Hashtable<>();
info.put(Servlet, servlet);
if(dictionary != null) info.put(Dictionary, dictionary);
if(httpContext != null) info.put(HttpContext, httpContext);
servletsAndResources.put(path, info);
if (httpService != null) {
try {
httpService.registerServlet(path, servlet, dictionary, httpContext);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
示例2: activate
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
protected void activate(BundleContext context) {
HttpContext httpContext = new DefaultHttpContext(m_httpService.createDefaultHttpContext());
try {
m_httpService.registerResources("/weblog", "www/index.html", httpContext);
m_httpService.registerResources("/weblogjs", "www/weblogjs", httpContext);
m_httpService.registerResources("/weblogcss", "www/weblogcss", httpContext);
m_httpService.registerServlet("/weblogapi", new LogLevelApi(), null, httpContext);
m_httpService.registerServlet("/weblogviewapi", new LogViewApi(), null, httpContext);
} catch (NamespaceException|ServletException e) {
s_logger.error("Error registering weblog", e);
throw new ComponentException(e);
}
s_logger.info("WebLog activated");
}
示例3: addingBundle
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
@Override
public Object addingBundle(Bundle bundle, BundleEvent event) {
ArrayList<String> aliases = new ArrayList<String>();
String[] resources = findResources(bundle);
if ( resources != null ) {
HttpContext ctx = new ProxyHttpContext(bundle);
for ( String p : resources ) {
String[] split = p.split("\\s*=\\s*");
String alias = split[0];
String file = split.length == 1 ? split[0] : split[1];
try {
System.out.println( "Registering " + alias + "->" + file );
http.registerResources(alias, file, ctx);
aliases.add( alias );
} catch (NamespaceException e) {
e.printStackTrace();
}
}
}
return aliases.isEmpty() ? null : aliases.toArray(new String[aliases.size()]);
}
示例4: getHttpContext
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
/**
* Decorates the given HttpContext with a @{link FileSystemAwareUIHttpContext} if dynamic resource loading
* is set up.
* @param httpContext the default http context for a given bundle
* @param bundle the bundle for which this http context will be registered
* @return the decorated instance of the provided context if dynamic loading was set up, the original instance otherwise
*/
public static HttpContext getHttpContext(HttpContext httpContext, Bundle bundle) {
LOGGER.info("Environment is " + ApplicationEnvironment.getEnvironment());
if (!ApplicationEnvironment.isInDevelopmentMode()) {
return httpContext;
}
String resourceDirPath = ApplicationEnvironment.getModulePath(new BundleName(bundle.getSymbolicName()));
if (isBlank(resourceDirPath)) {
LOGGER.info(String.format("Resource path not given for bundle %s", bundle.getSymbolicName()));
return httpContext;
}
LOGGER.info(String.format("Resource path for bundle %s is %s", bundle.getSymbolicName(), resourceDirPath));
return new FileSystemAwareUIHttpContext(httpContext, resourceDirPath);
}
示例5: testStart_dmFound
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
@Test
public void testStart_dmFound() throws Exception {
// Mock
Bundle b = Mockito.mock( Bundle.class );
Mockito.when( b.getSymbolicName()).thenReturn( "net.roboconf.dm" );
this.factory.httpService = Mockito.mock( HttpService.class );
this.factory.bundleContext = Mockito.mock( BundleContext.class );
Mockito.when( this.factory.bundleContext.getBundles()).thenReturn( new Bundle[] { b });
// Start
this.factory.start();
// Check
Mockito.verify( this.factory.httpService, Mockito.times( 1 )).registerServlet(
Mockito.eq( HttpConstants.DM_SOCKET_PATH ),
Mockito.any( Servlet.class ),
Mockito.any( Dictionary.class ),
Mockito.isNull( HttpContext.class ));
}
示例6: registerServlet
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
public void registerServlet(String context, Servlet servlet, Dictionary dictionary, HttpContext httpContext) throws ServletException, NamespaceException {
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/",
ServletContextHandler.SESSIONS);
ServletHolder servletHolder = new ServletHolder(servlet);
root.addServlet(servletHolder, context);
if (!server.getServer().getState().equals(server.STARTED)) {
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例7: shouldCreateFileSystemAwareUiHttpContext
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
@Test
public void shouldCreateFileSystemAwareUiHttpContext() {
HttpContext httpContext = mock(HttpContext.class);
PowerMockito.mockStatic(ApplicationEnvironment.class);
MockBundle bundle = new MockBundle("org.motechproject.com-sms-api-bundle");
when(ApplicationEnvironment.isInDevelopmentMode()).thenReturn(true);
when(ApplicationEnvironment.getModulePath(new BundleName("org.motechproject.com-sms-api-bundle"))).thenReturn("/Users/s/project/motech/modules/sms/src/main/resources");
FileSystemAwareUIHttpContext fileSystemAwareUIHttpContext = (FileSystemAwareUIHttpContext) HttpContextFactory.getHttpContext(httpContext, bundle);
assertThat(fileSystemAwareUIHttpContext, IsNot.not(notNull()));
assertThat(fileSystemAwareUIHttpContext.getResourceRootDirectoryPath(), Is.is("/Users/s/project/motech/modules/sms/src/main/resources"));
}
示例8: register
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
public void register() throws Exception {
ObjectHelper.notEmpty(alias, "alias", this);
ObjectHelper.notEmpty(servletName, "servletName", this);
HttpContext actualHttpContext = (httpContext == null)
? httpService.createDefaultHttpContext()
: httpContext;
final Dictionary<String, String> initParams = new Hashtable<String, String>();
initParams.put("matchOnUriPrefix", matchOnUriPrefix ? "true" : "false");
initParams.put("servlet-name", servletName);
httpService.registerServlet(alias, servlet, initParams, actualHttpContext);
alreadyRegistered = true;
}
示例9: registerQueue
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
private void registerQueue() {
if (servletsAndResources != null && httpService != null) {
for (String path : servletsAndResources.keySet()) {
Map info = servletsAndResources.get(path);
if (info.containsKey(Servlet)) {
registerServlet(path, (Servlet)info.get(Servlet), (Dictionary)info.get(Dictionary), (HttpContext)info.get(HttpContext));
} else if (info.containsKey(FilePath)) {
registerResources(path, (String)info.get(FilePath), (HttpContext)info.get(HttpContext));
}
}
}
}
示例10: registerResources
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
public void registerResources(String path, String filePath, HttpContext httpContext) {
if (httpService != null) {
try {
httpService.registerResources(path, filePath, httpContext);
} catch (Exception exception) {
exception.printStackTrace();
}
} else {
Map info = new Hashtable<>();
info.put(FilePath, filePath);
if(httpContext != null) info.put(HttpContext, httpContext);
servletsAndResources.put(path, info);
}
}
示例11: JspBundle
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
public JspBundle ( final Bundle bundle, final HttpService service, final HttpContext context ) throws ServletException, NamespaceException
{
this.service = service;
this.alias = String.format ( "/bundle/%s/WEB-INF", bundle.getBundleId () );
this.servlet = new JspServlet ( bundle, "/WEB-INF", this.alias );
logger.info ( "Registering JSP servlet - resources: /WEB-INF, alias: {}, bundle: {}", this.alias, bundle.getSymbolicName () );
final Dictionary<String, String> initparams = new Hashtable<> ( 2 );
initparams.put ( "compilerSourceVM", "1.8" );
initparams.put ( "compilerTargetVM", "1.8" );
this.service.registerServlet ( this.alias, this.servlet, initparams, context );
}
示例12: createHttpContext
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
/**
* Creates a {@link SecureHttpContext} which handles the security for this
* servlet
*
* @return a {@link SecureHttpContext}
*/
protected HttpContext createHttpContext() {
if (this.httpService == null) {
logger.error("cannot create http context httpservice null");
return null;
} else {
HttpContext defaultHttpContext = httpService.createDefaultHttpContext();
return new SecureHttpContext(defaultHttpContext, "openHAB.org");
}
}
示例13: computeAuthHeader
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
/**
* Parses the given <code>authHeader</code>, extracts username and password
* and tries to authenticate with these credentials. If the login succeeded
* it sets the appropriate headers to the <code>request</code>
*
* @param request
* @param authHeader
* @param realm
*
* @return <code>true</code> if the login succeeded and <code>false</code>
* in all other cases.
*/
private boolean computeAuthHeader(HttpServletRequest request, final String authHeader, final String realm) {
logger.trace("received authentication request '{}'", authHeader);
String[] authHeaders = authHeader.trim().split(" ");
if (authHeaders.length == 2) {
String authType = StringUtils.trim(authHeaders[0]);
String authInfo = StringUtils.trim(authHeaders[1]);
if (HttpServletRequest.BASIC_AUTH.equalsIgnoreCase(authType)) {
String authInfoString = new String(Base64.decodeBase64(authInfo));
String[] authInfos = authInfoString.split(":");
if (authInfos.length < 2) {
logger.warn("authInfos '{}' must contain two elements separated by a colon", authInfoString);
return false;
}
String username = authInfos[0];
String password = authInfos[1];
Subject subject = authenticate(realm, username, password);
if (subject != null) {
request.setAttribute(
HttpContext.AUTHENTICATION_TYPE,
HttpServletRequest.BASIC_AUTH);
request.setAttribute(HttpContext.REMOTE_USER, username);
logger.trace("authentication of user '{}' succeeded!", username);
return true;
}
}
else {
logger.warn("we don't support '{}' authentication -> processing aborted", authType);
}
}
else {
logger.warn("authentication header '{}' must contain of two parts separated by a blank", authHeader);
}
return false;
}
示例14: JspBundle
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
public JspBundle ( final Bundle bundle, final HttpService service, final HttpContext context ) throws ServletException, NamespaceException
{
this.service = service;
this.alias = String.format ( "/bundle/%s/WEB-INF", bundle.getBundleId () );
this.servlet = new JspServlet ( bundle, "/WEB-INF", this.alias );
logger.info ( "Registering JSP servlet - resources: /WEB-INF, alias: {}, bundle: {}", this.alias, bundle.getSymbolicName () );
final Dictionary<String, Object> initparams = new Hashtable<> ( 2 );
initparams.put ( "compilerSourceVM", "1.8" );
initparams.put ( "compilerTargetVM", "1.8" );
this.service.registerServlet ( this.alias, this.servlet, initparams, context );
}
示例15: registerServlet
import org.osgi.service.http.HttpContext; //导入依赖的package包/类
@Override
public void registerServlet( String context, Servlet servlet, Dictionary dictionary, HttpContext httpContext )
throws ServletException, NamespaceException {
if( ! context.endsWith( "/*" ))
context += "/*";
ServletHolder servletHolder = new ServletHolder( servlet );
servletHolder.setName((String) dictionary.get( "servlet-name" ));
this.context.addServlet( servletHolder, context );
System.out.println( "New servlet reachable at " + context );
}