private void addInitParameters(final Wrapper wrapper, final Map<String, String> initParameters) {
   NullArgumentException.validateNotNull(initParameters, "initParameters");
   NullArgumentException.validateNotNull(wrapper, "wrapper");
   for (final Map.Entry<String, String> initParam : initParameters.entrySet()) {
     wrapper.addInitParameter(initParam.getKey(), initParam.getValue());
   }
 }
  /**
   * All the BND magic happens here.
   *
   * @param jarInputStream On what to operate.
   * @param instructions BND instructions from user API
   * @param symbolicName Mandatory Header. In case user does not set it.
   * @return Bundle Jar Stream
   * @throws Exception Problems go here
   */
  private InputStream createBundle(
      InputStream jarInputStream, Properties instructions, String symbolicName) throws Exception {
    NullArgumentException.validateNotNull(jarInputStream, "Jar URL");
    NullArgumentException.validateNotNull(instructions, "Instructions");
    NullArgumentException.validateNotEmpty(symbolicName, "Jar info");

    final Jar jar = new Jar("dot", sink(jarInputStream));

    final Properties properties = new Properties();
    properties.putAll(instructions);

    final Analyzer analyzer = new Analyzer();
    analyzer.setJar(jar);
    analyzer.setProperties(properties);

    // throw away already existing headers that we overwrite:

    analyzer.mergeManifest(jar.getManifest());

    checkMandatoryProperties(analyzer, jar, symbolicName);
    Manifest manifest = analyzer.calcManifest();
    jar.setManifest(manifest);

    return createInputStream(jar);
  }
  /**
   * Creates a new connection.
   *
   * @param url url to be handled; cannot be null.
   * @param configuration protocol configuration; cannot be null
   * @throws MalformedURLException - If url path is empty
   * @throws IOException - If cache name cannot be generated
   * @throws NullArgumentException - If url or configuration is null
   */
  protected Connection(final URL url, final Configuration configuration) throws IOException {
    super(url);

    NullArgumentException.validateNotNull(url, "URL");
    NullArgumentException.validateNotNull(configuration, "Configuration");

    m_parser = new Parser(url.getPath());
    m_configuration = configuration;
    m_cacheName = generateCacheName(m_parser.getUrl());
  }
 private ErrorPage createErrorPage(final ErrorPageModel model) {
   NullArgumentException.validateNotNull(model, "model");
   NullArgumentException.validateNotNull(model.getLocation(), "model#location");
   NullArgumentException.validateNotNull(model.getError(), "model#error");
   final ErrorPage errorPage = new ErrorPage();
   errorPage.setLocation(model.getLocation());
   final Integer errorCode = parseErrorCode(model.getError());
   if (errorCode != null) {
     errorPage.setErrorCode(errorCode);
   } else {
     errorPage.setExceptionType(model.getError());
   }
   return errorPage;
 }
 /**
  * Creates a new web.xml observer.
  *
  * @param parser parser for web.xml
  * @param publisher web app publisher
  * @param bundleContext
  * @throws NullArgumentException if parser or publisher is null
  */
 WebXmlObserver(
     final WebXmlParser parser,
     final WebAppPublisher publisher,
     final WebEventDispatcher eventDispatcher,
     BundleContext bundleContext) {
   NullArgumentException.validateNotNull(parser, "Web.xml Parser");
   NullArgumentException.validateNotNull(publisher, "Web App Publisher");
   NullArgumentException.validateNotNull(eventDispatcher, "WebEvent Dispatcher");
   NullArgumentException.validateNotNull(bundleContext, "BundleContext");
   m_parser = parser;
   m_publisher = publisher;
   this.bundleContext = bundleContext;
   this.eventDispatcher = eventDispatcher;
 }
 @Override
 public void removeEventListener(final EventListenerModel eventListenerModel) {
   LOG.debug("remove event listener: [{}]", eventListenerModel);
   NullArgumentException.validateNotNull(eventListenerModel, "eventListenerModel");
   NullArgumentException.validateNotNull(
       eventListenerModel.getEventListener(), "eventListenerModel#weventListener");
   final Context context = findOrCreateContext(eventListenerModel);
   // TODO open a bug in tomcat
   if (!removeApplicationEventListener(context, eventListenerModel.getEventListener())) {
     if (!removeApplicationLifecycleListener(context, eventListenerModel.getEventListener())) {
       throw new RemoveEventListenerException(
           "cannot remove the event lister it is a not support class : " + eventListenerModel);
     }
   }
 }
 /**
  * Constructor.
  *
  * @param extenderContext extender context; cannot be null
  * @param bundleContext extender bundle context; cannot be null
  * @param classes array of class of the tracked objects; cannot be null
  */
 AbstractHttpContextTracker(
     final ExtenderContext extenderContext,
     final BundleContext bundleContext,
     final Class<? extends T>... classes) {
   super(validateBundleContext(bundleContext), createFilter(bundleContext, classes), null);
   NullArgumentException.validateNotNull(extenderContext, "Extender context");
   m_extenderContext = extenderContext;
 }
  @Override
  public void handle(
      final String target,
      final Request baseRequest,
      final HttpServletRequest request,
      final HttpServletResponse response)
      throws IOException, ServletException {
    if (!isStarted()) {
      return;
    }

    final ContextModel matched = serverModel.matchPathToContext(target);
    if (matched != null) {
      // check for nulls and start complaining
      NullArgumentException.validateNotNull(
          matched.getHttpContext(), "The http Context of " + matched.getContextName() + " is null");
      NullArgumentException.validateNotNull(getServer(), "The server is null!");

      final ContextHandler context =
          ((JettyServerWrapper) getServer()).getContext(matched.getHttpContext());

      try {
        NullArgumentException.validateNotNull(context, "Found context is Null");
        context.handle(target, baseRequest, request, response);

        // CHECKSTYLE:OFF
      } catch (EofException e) {
        throw e;
      } catch (RuntimeException e) {
        throw e;
      } catch (Exception e) {
        throw new ServletException(e);
      }
      // CHECKSTYLE:ON

    }
    // now handle all other handlers
    for (Handler handler : getHandlers()) {
      if (matched != null && matchedContextEqualsHandler(matched, handler)) {
        continue;
      }
      handler.handle(target, baseRequest, request, response);
    }
  }
 private void addServletMappings(
     final Context context, final String servletName, final String[] urlPatterns) {
   NullArgumentException.validateNotNull(urlPatterns, "urlPatterns");
   for (final String urlPattern : urlPatterns) { // TODO add a enhancement
     // to tomcat it is in
     // the specification so
     // tomcat should provide
     // it out of the box
     context.addServletMapping(urlPattern, servletName);
   }
 }
Exemplo n.º 10
0
  /**
   * Creates a new connection.
   *
   * @param url the url; cannot be null.
   * @param configuration service configuration; cannot be null
   * @throws MalformedURLException in case of a malformed url
   */
  public Connection(final URL url, final MavenConfiguration configuration)
      throws MalformedURLException {
    super(url);
    NullArgumentException.validateNotNull(url, "URL cannot be null");
    NullArgumentException.validateNotNull(configuration, "Service configuration");
    m_parser = new Parser(url.getPath());

    ArrayList<String> r = new ArrayList<String>();

    for (MavenRepositoryURL s : configuration.getRepositories()) {
      if (!s.isFileRepository()) {
        r.add(s.getURL().toExternalForm());
      }
    }

    // String[] repos = "http://repo1.maven.org/maven2/".split(",");

    String local = configuration.getLocalRepository().getFile().getAbsolutePath();

    m_aetherBasedResolver = new AetherBasedResolver(local, r.toArray(new String[r.size()]));
  }
Exemplo n.º 11
0
 @Override
 public void addingEntries(Bundle bundle, List<ManifestEntry> list) {
   NullArgumentException.validateNotNull(bundle, "Bundle");
   NullArgumentException.validateNotNull(list, "ManifestEntry");
   synchronized (connectorInfoCache) {
     if (!connectorInfoCache.containsKey(bundle.getSymbolicName())) {
       Pair<Bundle, List<ConnectorInfo>> info = processBundle(bundle, list);
       if (null != info) {
         connectorInfoCache.put(bundle.getSymbolicName(), info);
         for (ConnectorInfo connectorInfo : info.second) {
           notifyListeners(
               buildEvent(
                   ConnectorEvent.CONNECTOR_REGISTERED,
                   info.first,
                   connectorInfo.getConnectorKey()));
         }
       }
       logger.info("Add Connector {}, list: {}", bundle.getSymbolicName(), list);
     }
   }
 }
Exemplo n.º 12
0
    public FabResolverImpl(URL url) throws MalformedURLException {
      super();
      this.url = url;

      NullArgumentException.validateNotNull(url, "URL");

      this.bundleContext = FabResolverFactoryImpl.this.bundleContext;

      String path = url.getPath();
      if (path == null || path.trim().length() == 0) {
        throw new MalformedURLException("Path cannot empty");
      }
    }
Exemplo n.º 13
0
 @Override
 public void removingEntries(Bundle bundle, List<ManifestEntry> list) {
   NullArgumentException.validateNotNull(bundle, "Bundle");
   synchronized (connectorInfoCache) {
     Pair<Bundle, List<ConnectorInfo>> info = connectorInfoCache.remove(bundle.getSymbolicName());
     if (null != info) {
       for (ConnectorInfo connectorInfo : info.second) {
         notifyListeners(
             buildEvent(
                 ConnectorEvent.CONNECTOR_UNREGISTERING,
                 info.first,
                 connectorInfo.getConnectorKey()));
       }
     }
   }
   logger.info("Remove Connector {}, list: {}", bundle.getSymbolicName(), list);
 }
 private Context findOrCreateContext(final Model model) {
   NullArgumentException.validateNotNull(model, "model");
   return findOrCreateContext(model.getContextModel());
 }
 /**
  * Validates that the bundle context is not null. If null will throw IllegalArgumentException.
  *
  * @param bundleContext a bundle context
  * @return the bundle context if not null
  */
 private static BundleContext validateBundleContext(final BundleContext bundleContext) {
   NullArgumentException.validateNotNull(bundleContext, "Bundle context");
   return bundleContext;
 }
  /**
   * Parse the web.xml and publish the corresponding web app. The received list is expected to
   * contain one URL of an web.xml (only first is used. The web.xml will be parsed and resulting web
   * application structure will be registered with the http service.
   *
   * @throws NullArgumentException if bundle or list of web xmls is null
   * @throws PreConditionException if the list of web xmls is empty or more then one xml
   * @see BundleObserver#addingEntries(Bundle,List)
   */
  public void addingEntries(final Bundle bundle, final List<URL> entries) {
    NullArgumentException.validateNotNull(bundle, "Bundle");
    NullArgumentException.validateNotNull(entries, "List of *.xml's");

    // Context name is also needed for some of the pre-condition checks, therefore it is retrieved
    // here.
    String contextName = extractContextName(bundle);
    LOG.info(String.format("Using [%s] as web application context name", contextName));

    List<String> virtualHostList = extractVirtualHostList(bundle);
    LOG.info(String.format("[%d] virtual hosts defined in bundle header", virtualHostList.size()));

    List<String> connectorList = extractConnectorList(bundle);
    LOG.info(String.format("[%d] connectors defined in bundle header", connectorList.size()));

    // try-catch only to inform framework and listeners of an event.
    try {
      //	        PreConditionException.validateLesserThan( entries.size(), 3, "Number of xml's" );
      PreConditionException.validateEqualTo(
          "WEB-INF".compareToIgnoreCase(Path.getDirectParent(entries.get(0))),
          0,
          "Direct parent of web.xml");
    } catch (PreConditionException pce) {
      LOG.error(pce.getMessage(), pce);
      eventDispatcher.webEvent(
          new WebEvent(WebEvent.FAILED, "/" + contextName, bundle, bundleContext.getBundle(), pce));
      throw pce;
    }

    if (webApps.containsKey(bundle.getBundleId())) {
      LOG.debug(
          String.format("Already found a web application in bundle %d", bundle.getBundleId()));
      return;
    }

    URL webXmlURL = null; // = entries.get( 0 );
    URL jettyWebXmlURL = null;

    for (URL url : entries) {
      if (isJettyWebXml(url)) {
        // it's the jetty-web.xml
        jettyWebXmlURL = url;
      } else if (isWebXml(url)) {
        // it's the web.xml
        webXmlURL = url;
      } else {
        // just another one
      }
    }
    if (webXmlURL == null) {
      PreConditionException pce =
          new PreConditionException("no web.xml configured in web-application");
      LOG.error(pce.getMessage(), pce);
      eventDispatcher.webEvent(
          new WebEvent(WebEvent.FAILED, "/" + contextName, bundle, bundleContext.getBundle(), pce));
      throw pce;
    }

    LOG.debug("Parsing a web application from [" + webXmlURL + "]");

    String rootPath = extractRootPath(bundle);
    LOG.info(String.format("Using [%s] as web application root path", rootPath));

    InputStream is = null;
    try {
      is = webXmlURL.openStream();
      final WebApp webApp = m_parser.parse(bundle, is);
      if (webApp != null) {
        LOG.debug("Parsed web app [" + webApp + "]");

        webApp.setWebXmlURL(webXmlURL);
        webApp.setJettyWebXmlURL(jettyWebXmlURL);
        webApp.setVirtualHostList(virtualHostList);
        webApp.setConnectorList(connectorList);
        webApp.setBundle(bundle);
        webApp.setContextName(contextName);
        webApp.setRootPath(rootPath);
        webApp.setDeploymentState(WebApp.UNDEPLOYED_STATE);

        webApps.put(bundle.getBundleId(), webApp);

        // The Webapp-Deploy header controls if the app is deployed on
        // startup.
        if ("true".equals(opt(getHeader(bundle, "Webapp-Deploy"), "true"))) {
          deploy(webApp);
        } else {
          eventDispatcher.webEvent(
              new WebEvent(
                  WebEvent.UNDEPLOYED,
                  "/" + webApp.getContextName(),
                  webApp.getBundle(),
                  bundleContext.getBundle()));
        }
      }
    } catch (Exception ignore) {
      LOG.error("Could not parse web.xml", ignore);
      eventDispatcher.webEvent(
          new WebEvent(
              WebEvent.FAILED, "/" + contextName, bundle, bundleContext.getBundle(), ignore));
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ignore) {
          // just ignore
        }
      }
    }
  }
 /**
  * Setter.
  *
  * @param mimeType value to set. Cannot be null.
  * @throws NullArgumentException if mime type is null
  */
 public void setMimeType(final String mimeType) {
   NullArgumentException.validateNotNull(mimeType, "Mime type");
   this.mimeType = mimeType;
 }
 /**
  * Setter.
  *
  * @param extension value to set. Cannot be null.
  * @throws NullArgumentException if extension is null
  */
 public void setExtension(final String extension) {
   NullArgumentException.validateNotNull(extension, "Extension");
   this.extension = extension;
 }
 JettyServerHandlerCollection(final ServerModel serverModel) {
   super(true);
   NullArgumentException.validateNotNull(serverModel, "Service model");
   this.serverModel = serverModel;
 }
 private TomcatServerWrapper(final EmbeddedTomcat server) {
   NullArgumentException.validateNotNull(server, "server");
   this.m_server = server;
   ((ContainerBase) m_server.getHost()).setStartChildren(false);
 }