/** * Validate that a given alias is legal. * * @param alias input alias * @throws NamespaceException is thrown if alias is illegal */ private void validateAlias( String alias ) throws NamespaceException { if (alias == null) { throw new NamespaceException( "Alias is null." ); } if (alias.trim().length() == 0) { throw new NamespaceException( "Alias is an empty string." ); } if (!alias.startsWith( "/" )) { throw new NamespaceException( "Alias must begin with '/'." ); } } }
/** * Validate that a given alias is legal. * * @param alias input alias * @throws NamespaceException is thrown if alias is illegal */ private void validateAlias( String alias ) throws NamespaceException { if (alias == null) { throw new NamespaceException( "Alias is null." ); } if (alias.trim().length() == 0) { throw new NamespaceException( "Alias is an empty string." ); } if (!alias.startsWith( "/" )) { throw new NamespaceException( "Alias must begin with '/'." ); } } }
private void validateName(String name) throws NamespaceException { // The name parameter must also not end with slash ('/') with the exception // that a name of the form "/" is used to denote the root of the bundle. if (name == null || (name.length() > 1 && name.endsWith("/"))) throw new NamespaceException(OSGiMessages.MESSAGES.invalidResourceName(name)); }
/** * Chek if <code>alias</code> has been already registered. * * @param alias Alias to check. * @throws NamespaceException If <code>alias</code> has been registered. */ private void validateAlias4RegOk(String alias) throws NamespaceException { if (!alias.startsWith("/")) { // have to start with "/" String msg = "Invalid alias '" + alias + "', have to start with '/'."; logger.warn(msg); throw new NamespaceException(msg); } if (alias.length() > 1 && alias.endsWith("/")) { // if longer than "/", should not end with "/" String msg = "Alias '" + alias + "' can't and with '/' with exception to alias '/'."; logger.warn(msg); throw new NamespaceException(msg); } if (OSGiCleanMapper.containsAlias(alias)) { String msg = "Alias: '" + alias + "', already registered"; logger.warn(msg); throw new NamespaceException(msg); } }
/** * Chek if <code>alias</code> has been already registered. * * @param alias Alias to check. * @throws NamespaceException If <code>alias</code> has been registered. */ private void validateAlias4RegOk(String alias) throws NamespaceException { if (!alias.startsWith("/")) { // have to start with "/" String msg = "Invalid alias '" + alias + "', have to start with '/'."; logger.warn(msg); throw new NamespaceException(msg); } if (alias.length() > 1 && alias.endsWith("/")) { // if longer than "/", should not end with "/" String msg = "Alias '" + alias + "' can't and with '/' with exception to alias '/'."; logger.warn(msg); throw new NamespaceException(msg); } if (OSGiCleanMapper.containsAlias(alias)) { String msg = "Alias: '" + alias + "', already registered"; logger.warn(msg); throw new NamespaceException(msg); } }
private void validateAlias(String alias, boolean exists) throws NamespaceException { // An alias must begin with slash ('/') and must not end with slash ('/'), with the exception // that an alias of the form "/" is used to denote the root alias if (alias == null || !alias.startsWith("/")) throw new IllegalArgumentException(OSGiMessages.MESSAGES.invalidServletAlias(alias)); if (alias.length() > 1 && alias.endsWith("/")) throw new IllegalArgumentException(OSGiMessages.MESSAGES.invalidServletAlias(alias)); if (exists && !registry.exists(alias)) throw new IllegalArgumentException(OSGiMessages.MESSAGES.aliasMappingDoesNotExist(alias)); if (!exists && registry.exists(alias)) throw new NamespaceException(OSGiMessages.MESSAGES.aliasMappingAlreadyExists(alias)); }
/** * Register a servlet */ public void registerServlet(@NotNull final String alias, @NotNull final ExtServletContext httpContext, @NotNull final Servlet servlet, @NotNull final ServletInfo servletInfo) throws ServletException, NamespaceException { final ServletHandler handler = new HttpServiceServletHandler(httpContext, servletInfo, servlet); synchronized (this.aliasMap) { if (this.aliasMap.containsKey(alias)) { throw new NamespaceException("Alias " + alias + " is already in use."); } this.handlerRegistry.getRegistry(handler.getContextServiceId()).registerServlet(handler); this.aliasMap.put(alias, handler); } }
/** * Register a servlet */ public void registerServlet(@NotNull final String alias, @NotNull final ExtServletContext httpContext, @NotNull final Servlet servlet, @NotNull final ServletInfo servletInfo) throws ServletException, NamespaceException { final ServletHandler handler = new HttpServiceServletHandler(httpContext, servletInfo, servlet); synchronized (this.aliasMap) { if (this.aliasMap.containsKey(alias)) { throw new NamespaceException("Alias " + alias + " is already in use."); } this.handlerRegistry.getRegistry(handler.getContextServiceId()).registerServlet(handler); this.aliasMap.put(alias, handler); } }
public synchronized void addServlet(ServletHandler handler) throws ServletException, NamespaceException { if (this.servletMap.containsKey(handler.getServlet())) { throw new ServletException("Servlet instance already registered"); } if (this.aliasMap.containsKey(handler.getAlias())) { throw new NamespaceException("Servlet with alias already registered"); } handler.init(); this.servletMap.put(handler.getServlet(), handler); this.aliasMap.put(handler.getAlias(), handler.getServlet()); updateServletArray(); }
@Override public void registerResources(final String alias, final String name, final HttpContext httpContext) throws NamespaceException { synchronized (lock) { final ContextModel contextModel = getOrCreateContext(httpContext); LOG.debug("Register resources (alias={}). Using context [" + contextModel + "]"); // PAXWEB-1085, OSGi Enterprise R6 140.6 "Registering Resources", JavaEE Servlet spec "12.2 Specification of Mappings" // "A string beginning with a ‘ / ’ character and ending with a ‘ /* ’ suffix is used for path mapping." String osgiAlias = alias; if (osgiAlias != null && osgiAlias.endsWith("/*")) { osgiAlias = osgiAlias.substring(0, osgiAlias.length() - 2); } final Servlet servlet = serverController.createResourceServlet(contextModel, osgiAlias, name); String resourceModelName = name; if (!"default".equals(name)) { // PAXWEB-1099 - we should be able to register multiple "resources" for same name (==basePath) // but under different alias resourceModelName = String.format("%s:%s", alias, "/".equals(name) ? "" : name); } final ResourceModel model = new ResourceModel(contextModel, servlet, alias, resourceModelName); try { registerServlet(model); } catch (ServletException e) { LOG.error("Caught ServletException: ", e); throw new NamespaceException("Resource cant be resolved: ", e); } } }
synchronized Registration register(String alias, Bundle bundle, StandardContext context, Servlet servlet, Registration.Type type) throws NamespaceException { if (exists(alias)) throw new NamespaceException(OSGiMessages.MESSAGES.aliasMappingAlreadyExists(alias)); LOGGER.infoRegisterHttpServiceAlias(alias); Registration result = new Registration(alias, bundle, context, servlet, type); registrations.put(alias, result); return result; }
public synchronized void addServlet(ServletHandler handler) throws ServletException, NamespaceException { if (this.servletMap.containsKey(handler.getServlet())) { throw new ServletException("Servlet instance already registered"); } if (this.aliasMap.containsKey(handler.getAlias())) { throw new NamespaceException("Servlet with alias already registered"); } handler.init(); this.servletMap.put(handler.getServlet(), handler); this.aliasMap.put(handler.getAlias(), handler.getServlet()); updateServletArray(); }
public void registerResources(final String alias, final String name, final HttpContext context) throws NamespaceException { validateAlias(alias); synchronized (m_servletMap) { if (m_servletMap.containsKey(alias)) { throw new NamespaceException("Alias " + alias + " has already been registered."); } } if (context == null) { m_servletMap.put(alias, new ServiceRegistration(alias, name, createDefaultHttpContext(), m_logger)); } else { m_servletMap.put(alias, new ServiceRegistration(alias, name, context, m_logger)); } m_logger.log(Logger.LOG_DEBUG, "Registered resource for alias: " + alias); }
public void registerResources(final String alias, final String name, final HttpContext context) throws NamespaceException { validateAlias(alias); synchronized (m_servletMap) { if (m_servletMap.containsKey(alias)) { throw new NamespaceException("Alias " + alias + " has already been registered."); } } if (context == null) { m_servletMap.put(alias, new ServiceRegistration(alias, name, createDefaultHttpContext(), m_logger)); } else { m_servletMap.put(alias, new ServiceRegistration(alias, name, context, m_logger)); } m_logger.log(Logger.LOG_DEBUG, "Registered resource for alias: " + alias); }
public void registerServlet(final String alias, final Servlet servlet, final Dictionary initparams, final HttpContext context) throws ServletException, NamespaceException { validateAlias(alias); if (m_servletMap.containsKey(alias)) { throw new NamespaceException("Alias " + alias + " has already been registered."); } if (context == null) { m_servletMap.put(alias, new ServiceRegistration(alias, servlet, initparams, new DefaultContextImpl(m_bundle), m_logger)); } else { m_servletMap.put(alias, new ServiceRegistration(alias, servlet, initparams, context, m_logger)); } m_logger.log(Logger.LOG_DEBUG, "Registered servlet for alias: " + alias); }
public void registerServlet(final String alias, final Servlet servlet, final Dictionary initparams, final HttpContext context) throws ServletException, NamespaceException { validateAlias(alias); if (m_servletMap.containsKey(alias)) { throw new NamespaceException("Alias " + alias + " has already been registered."); } if (context == null) { m_servletMap.put(alias, new ServiceRegistration(alias, servlet, initparams, new DefaultContextImpl(m_bundle), m_logger)); } else { m_servletMap.put(alias, new ServiceRegistration(alias, servlet, initparams, context, m_logger)); } m_logger.log(Logger.LOG_DEBUG, "Registered servlet for alias: " + alias); }
ctx.create(); } catch (Exception ex) { throw new NamespaceException(WebMessages.MESSAGES.createContextFailed(), ex); throw new NamespaceException(WebMessages.MESSAGES.startContextFailed(), ex);