List of usage examples for org.apache.commons.configuration Configuration getBoolean
boolean getBoolean(String key);
From source file:org.apache.wookie.proxy.ConnectionsPrefsManager.java
private static void init(Configuration properties) { fHostname = properties.getString("widget.proxy.hostname"); if (fHostname != null) { fIsProxySet = (fHostname.length() > 0 ? true : false); }/*from w w w . j a v a2 s. com*/ fUseNTLMAuthentication = properties.getBoolean("widget.proxy.usentlmauthentication"); fParsedFile = true; }
From source file:org.apache.wookie.proxy.ProxyServlet.java
/** * Check the validity of a proxy request, and execute it if it checks out * @param request// ww w . j av a 2 s . co m * @param response * @param httpMethod * @throws ServletException */ private void dealWithRequest(HttpServletRequest request, HttpServletResponse response, String httpMethod) throws ServletException { try { // Properties systemProperties = System.getProperties(); // systemProperties.setProperty("http.proxyHost", "wwwcache.open.ac.uk"); // systemProperties.setProperty("http.proxyPort", "80"); Configuration properties = (Configuration) request.getSession().getServletContext() .getAttribute("properties"); // System.out.println("properties"); // properties.addProperty("http.proxyHost", "wwwcache.open.ac.uk"); // properties.addProperty("http.proxyPort", "80"); // systemProperties.setProperty("http.proxyHost", "wwwcache.open.ac.uk"); // systemProperties.setProperty("http.proxyPort", "80"); //System.out.println("$$$ 1"); // Check that the request is coming from the same domain (i.e. from a widget served by this server) if (properties.getBoolean("widget.proxy.checkdomain") && !isSameDomain(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "<error>" + UNAUTHORISED_MESSAGE + "</error>"); return; } //System.out.println("$$$ 2"); // Check that the request is coming from a valid widget IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager(); IWidgetInstance instance = persistenceManager .findWidgetInstanceByIdKey(request.getParameter("instanceid_key")); if (instance == null && !isDefaultGadget(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "<error>" + UNAUTHORISED_MESSAGE + "</error>"); return; } //System.out.println("$$$ 3"); // Create the proxy bean for the request ProxyURLBean bean; try { bean = new ProxyURLBean(request); } catch (MalformedURLException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); return; } //System.out.println("$$$ 4"); // should we filter urls? if (properties.getBoolean("widget.proxy.usewhitelist") && !isAllowed(bean.getNewUrl().toURI(), instance)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "<error>URL Blocked</error>"); fLogger.warn("URL " + bean.getNewUrl().toExternalForm() + " Blocked"); return; } //System.out.println("$$$ 5"); ProxyClient proxyclient = new ProxyClient(request); PrintWriter out = response.getWriter(); //System.out.println("$$$ 6"); //TODO - find all the links etc & make them absolute - to make request come thru this servlet String output = ""; if (httpMethod.equals("get")) { output = proxyclient.get(bean.getNewUrl().toExternalForm(), properties); } else { output = proxyclient.post(bean.getNewUrl().toExternalForm(), getXmlData(request), properties); } response.setContentType(proxyclient.getCType()); out.print(output); } catch (Exception ex) { try { if (ex instanceof AuthenticationException) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); } fLogger.error(ex.getMessage()); } catch (IOException e) { // give up! fLogger.error(ex.getMessage()); throw new ServletException(e); } } }
From source file:org.apache.wookie.proxy.ProxyServlet.java
private boolean isDefaultGadget(HttpServletRequest request) { String instanceId = request.getParameter("instanceid_key"); // check if the default Shindig gadget key is being used Configuration properties = (Configuration) request.getSession().getServletContext() .getAttribute("opensocial"); if (properties.getBoolean("opensocial.enable") && properties.getString("opensocial.proxy.id").equals(instanceId)) { return true; }//ww w .j a va 2 s. co m return false; }
From source file:org.jkcsoft.java.util.JndiHelper.java
public static DirContext getDirContext(BehavioralContext bctx, Object principal, Object credentials) throws NamingException { DirContext ctx = null;//from www .j a v a 2 s.c o m Configuration tconfig = bctx.getConfig(); String ldapProvider = "ldap" + "://" + tconfig.getString(Constants.KEY_AD_HOST) + ":" + tconfig.getString(Constants.KEY_AD_PORT) + "/" + tconfig.getString(Constants.KEY_AD_ROOT_DN); log.info("Using LDAP url: [" + ldapProvider + "]"); // String url, String contextFactoryName, Hashtable jndiEnv = new Hashtable(); jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); jndiEnv.put(Context.PROVIDER_URL, ldapProvider); jndiEnv.put(Context.REFERRAL, "follow"); if (tconfig.getBoolean(Constants.KEY_AD_SSL)) { log.info("Using SSL for LDAP"); jndiEnv.put(Context.SECURITY_PROTOCOL, "ssl"); } jndiEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); if (principal != null) jndiEnv.put(Context.SECURITY_PRINCIPAL, principal); if (credentials != null) jndiEnv.put(Context.SECURITY_CREDENTIALS, credentials); try { // Creating the JNDI directory context (with LDAP context // factory), performs an LDAP bind to the LDAP provider thereby // authenticating the username/pw. ctx = new InitialDirContext(jndiEnv); } catch (NamingException ex) { log.error("Directory context init failed", ex); throw ex; } return ctx; }
From source file:org.kramerius.convert.input.ParametrizedConvertInputTemplateTest.java
@Test public void testInputTemplateTest() throws IOException { Provider<Locale> localeProvider = EasyMock.createMock(_TestLocaleProvider.class); EasyMock.expect(localeProvider.get()).andReturn(Locale.getDefault()).anyTimes(); ResourceBundleService resb = EasyMock.createMock(ResourceBundleService.class); PropertyResourceBundle resourceBundle = new PropertyResourceBundle(new StringReader(BUNDLES)); EasyMock.expect(resb.getResourceBundle("labels", Locale.getDefault())).andReturn(resourceBundle).anyTimes(); KConfiguration conf = EasyMock.createMock(KConfiguration.class); EasyMock.expect(conf.getProperty("import.directory")).andReturn(System.getProperty("user.dir")).anyTimes(); EasyMock.expect(conf.getProperty("convert.target.directory")).andReturn(System.getProperty("user.dir")) .anyTimes();/*from w ww . j a va 2 s. c o m*/ EasyMock.expect(conf.getProperty("convert.directory")).andReturn(System.getProperty("user.dir")).anyTimes(); Configuration subConfObject = EasyMock.createMock(Configuration.class); EasyMock.expect(conf.getConfiguration()).andReturn(subConfObject).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.skip")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.startIndexer")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("convert.defaultRights")).andReturn(true).anyTimes(); EasyMock.replay(localeProvider, resb, conf, subConfObject); ParametrizedConvertInputTemplate temp = new ParametrizedConvertInputTemplate(); temp.configuration = conf; temp.localesProvider = localeProvider; temp.resourceBundleService = resb; StringWriter nstr = new StringWriter(); temp.renderInput(null, nstr, new Properties()); Assert.assertNotNull(nstr.toString()); }
From source file:org.kramerius.k3replications.input.InputTemplateTest.java
@Test public void testInputTemplateTest() throws IOException { Provider<Locale> localeProvider = EasyMock.createMock(_TestLocaleProvider.class); EasyMock.expect(localeProvider.get()).andReturn(Locale.getDefault()).anyTimes(); ResourceBundleService resb = EasyMock.createMock(ResourceBundleService.class); PropertyResourceBundle resourceBundle = new PropertyResourceBundle(new StringReader(BUNDLES)); EasyMock.expect(resb.getResourceBundle("labels", Locale.getDefault())).andReturn(resourceBundle).anyTimes(); KConfiguration conf = EasyMock.createMock(KConfiguration.class); EasyMock.expect(conf.getProperty("migration.target.directory")).andReturn(System.getProperty("user.dir")) .anyTimes();/*from www .ja va 2 s. c o m*/ EasyMock.expect(conf.getProperty("migration.directory")).andReturn(System.getProperty("user.dir")) .anyTimes(); Configuration subConfObject = EasyMock.createMock(Configuration.class); EasyMock.expect(conf.getConfiguration()).andReturn(subConfObject).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.skip")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.startIndexer")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("convert.defaultRights")).andReturn(true).anyTimes(); EasyMock.replay(localeProvider, resb, conf, subConfObject); InputTemplate temp = new InputTemplate(); temp.configuration = conf; temp.localesProvider = localeProvider; temp.resourceBundleService = resb; StringWriter nstr = new StringWriter(); temp.renderInput(null, nstr, new Properties()); Assert.assertNotNull(nstr.toString()); }
From source file:org.lable.oss.dynamicconfig.core.commonsconfiguration.ConcurrentConfigurationTest.java
@Test public void testMethodWrappers() { CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class); Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null); concurrentConfiguration.subset("subset"); concurrentConfiguration.isEmpty();/*from w ww . j a v a 2 s . c o m*/ concurrentConfiguration.containsKey("key"); concurrentConfiguration.getProperty("getprop"); concurrentConfiguration.getKeys("getkeys"); concurrentConfiguration.getKeys(); concurrentConfiguration.getProperties("getprops"); concurrentConfiguration.getBoolean("getboolean1"); concurrentConfiguration.getBoolean("getboolean2", true); concurrentConfiguration.getBoolean("getboolean3", Boolean.FALSE); concurrentConfiguration.getByte("getbyte1"); concurrentConfiguration.getByte("getbyte2", (byte) 0); concurrentConfiguration.getByte("getbyte3", Byte.valueOf((byte) 0)); concurrentConfiguration.getDouble("getdouble1"); concurrentConfiguration.getDouble("getdouble2", 0.2); concurrentConfiguration.getDouble("getdouble3", Double.valueOf(0.2)); concurrentConfiguration.getFloat("getfloat1"); concurrentConfiguration.getFloat("getfloat2", 0f); concurrentConfiguration.getFloat("getfloat3", Float.valueOf(0f)); concurrentConfiguration.getInt("getint1"); concurrentConfiguration.getInt("getint2", 0); concurrentConfiguration.getInteger("getint3", 0); concurrentConfiguration.getLong("getlong1"); concurrentConfiguration.getLong("getlong2", 0L); concurrentConfiguration.getLong("getlong3", Long.valueOf(0L)); concurrentConfiguration.getShort("getshort1"); concurrentConfiguration.getShort("getshort2", (short) 0); concurrentConfiguration.getShort("getshort3", Short.valueOf((short) 0)); concurrentConfiguration.getBigDecimal("getbigd1"); concurrentConfiguration.getBigDecimal("getbigd2", BigDecimal.valueOf(0.4)); concurrentConfiguration.getBigInteger("getbigi1"); concurrentConfiguration.getBigInteger("getbigi2", BigInteger.valueOf(2L)); concurrentConfiguration.getString("getstring1"); concurrentConfiguration.getString("getstring2", "def"); concurrentConfiguration.getStringArray("stringarray"); concurrentConfiguration.getList("getlist1"); concurrentConfiguration.getList("getlist2", Arrays.asList("a", "b")); verify(mockConfiguration, times(1)).subset("subset"); verify(mockConfiguration, times(1)).isEmpty(); verify(mockConfiguration, times(1)).containsKey("key"); verify(mockConfiguration, times(1)).getProperty("getprop"); verify(mockConfiguration, times(1)).getKeys("getkeys"); verify(mockConfiguration, times(1)).getKeys(); verify(mockConfiguration, times(1)).getProperties("getprops"); verify(mockConfiguration, times(1)).getBoolean("getboolean1"); verify(mockConfiguration, times(1)).getBoolean("getboolean2", true); verify(mockConfiguration, times(1)).getBoolean("getboolean3", Boolean.FALSE); verify(mockConfiguration, times(1)).getByte("getbyte1"); verify(mockConfiguration, times(1)).getByte("getbyte2", (byte) 0); verify(mockConfiguration, times(1)).getByte("getbyte3", Byte.valueOf((byte) 0)); verify(mockConfiguration, times(1)).getDouble("getdouble1"); verify(mockConfiguration, times(1)).getDouble("getdouble2", 0.2); verify(mockConfiguration, times(1)).getDouble("getdouble3", Double.valueOf(0.2)); verify(mockConfiguration, times(1)).getFloat("getfloat1"); verify(mockConfiguration, times(1)).getFloat("getfloat2", 0f); verify(mockConfiguration, times(1)).getFloat("getfloat3", Float.valueOf(0f)); verify(mockConfiguration, times(1)).getInt("getint1"); verify(mockConfiguration, times(1)).getInt("getint2", 0); verify(mockConfiguration, times(1)).getInteger("getint3", Integer.valueOf(0)); verify(mockConfiguration, times(1)).getLong("getlong1"); verify(mockConfiguration, times(1)).getLong("getlong2", 0L); verify(mockConfiguration, times(1)).getLong("getlong3", Long.valueOf(0L)); verify(mockConfiguration, times(1)).getShort("getshort1"); verify(mockConfiguration, times(1)).getShort("getshort2", (short) 0); verify(mockConfiguration, times(1)).getShort("getshort3", Short.valueOf((short) 0)); verify(mockConfiguration, times(1)).getBigDecimal("getbigd1"); verify(mockConfiguration, times(1)).getBigDecimal("getbigd2", BigDecimal.valueOf(0.4)); verify(mockConfiguration, times(1)).getBigInteger("getbigi1"); verify(mockConfiguration, times(1)).getBigInteger("getbigi2", BigInteger.valueOf(2L)); verify(mockConfiguration, times(1)).getString("getstring1"); verify(mockConfiguration, times(1)).getString("getstring2", "def"); verify(mockConfiguration, times(1)).getStringArray("stringarray"); verify(mockConfiguration, times(1)).getList("getlist1"); verify(mockConfiguration, times(1)).getList("getlist2", Arrays.asList("a", "b")); }
From source file:org.mobicents.servlet.restcomm.asr.ISpeechAsr.java
public ISpeechAsr(final Configuration configuration) { super();/*w ww. j a v a 2s . c o m*/ key = configuration.getString("api-key"); production = configuration.getBoolean("api-key[@production]"); }
From source file:org.mobicents.servlet.restcomm.sms.smpp.SmppService.java
public SmppService(final ActorSystem system, final Configuration configuration, final SipFactory factory, final DaoManager storage, final ServletContext servletContext, final ActorRef smppMessageHandler) { super();/*from w w w. j av a 2s .c om*/ this.system = system; this.smppMessageHandler = smppMessageHandler; this.configuration = configuration; final Configuration runtime = configuration.subset("runtime-settings"); this.authenticateUsers = runtime.getBoolean("authenticate"); this.servletConfig = (ServletConfig) configuration.getProperty(ServletConfig.class.getName()); this.sipFactory = factory; this.storage = storage; this.servletContext = servletContext; Configuration config = this.configuration.subset("smpp"); smppActivated = config.getString("[@activateSmppConnection]"); //get smpp address map from restcomm.xml file this.smppSourceAddressMap = config.getString("connections.connection[@sourceAddressMap]"); this.smppDestinationAddressMap = config.getString("connections.connection[@destinationAddressMap]"); this.smppTonNpiValue = config.getString("connections.connection[@tonNpiValue]"); this.initializeSmppConnections(); }
From source file:org.mobicents.servlet.restcomm.sms.smpp.SmppService.java
private void initializeSmppConnections() { Configuration smppConfiguration = this.configuration.subset("smpp"); List<Object> smppConnections = smppConfiguration.getList("connections.connection.name"); int smppConnecsSize = smppConnections.size(); if (smppConnecsSize == 0) { logger.warning("No SMPP Connections defined!"); return;/*from w w w. j av a 2 s . c om*/ } for (int count = 0; count < smppConnecsSize; count++) { String name = smppConfiguration.getString("connections.connection(" + count + ").name"); String systemId = smppConfiguration.getString("connections.connection(" + count + ").systemid"); String peerIp = smppConfiguration.getString("connections.connection(" + count + ").peerip"); int peerPort = smppConfiguration.getInt("connections.connection(" + count + ").peerport"); SmppBindType bindtype = SmppBindType .valueOf(smppConfiguration.getString("connections.connection(" + count + ").bindtype")); if (bindtype == null) { logger.warning("Bindtype for SMPP name=" + name + " is not specified. Using default TRANSCEIVER"); } String password = smppConfiguration.getString("connections.connection(" + count + ").password"); String systemType = smppConfiguration.getString("connections.connection(" + count + ").systemtype"); byte interfaceVersion = smppConfiguration .getByte("connections.connection(" + count + ").interfaceversion"); byte ton = smppConfiguration.getByte("connections.connection(" + count + ").ton"); byte npi = smppConfiguration.getByte("connections.connection(" + count + ").npi"); String range = smppConfiguration.getString("connections.connection(" + count + ").range"); Address address = null; if (ton != -1 && npi != -1 && range != null) { address = new Address(ton, npi, range); } int windowSize = smppConfiguration.getInt("connections.connection(" + count + ").windowsize"); long windowWaitTimeout = smppConfiguration .getLong("connections.connection(" + count + ").windowwaittimeout"); long connectTimeout = smppConfiguration.getLong("connections.connection(" + count + ").connecttimeout"); long requestExpiryTimeout = smppConfiguration .getLong("connections.connection(" + count + ").requestexpirytimeout"); long windowMonitorInterval = smppConfiguration .getLong("connections.connection(" + count + ").windowmonitorinterval"); boolean logBytes = smppConfiguration.getBoolean("connections.connection(" + count + ").logbytes"); boolean countersEnabled = smppConfiguration .getBoolean("connections.connection(" + count + ").countersenabled"); long enquireLinkDelay = smppConfiguration .getLong("connections.connection(" + count + ").enquirelinkdelay"); Smpp smpp = new Smpp(name, systemId, peerIp, peerPort, bindtype, password, systemType, interfaceVersion, address, connectTimeout, windowSize, windowWaitTimeout, requestExpiryTimeout, windowMonitorInterval, countersEnabled, logBytes, enquireLinkDelay); this.smppList.add(smpp); if (logger.isInfoEnabled()) { logger.info("creating new SMPP connection " + smpp); } } // for monitoring thread use, it's preferable to create your own // instance of an executor and cast it to a ThreadPoolExecutor from // Executors.newCachedThreadPool() this permits exposing thinks like // executor.getActiveCount() via JMX possible no point renaming the // threads in a factory since underlying Netty framework does not easily // allow you to customize your thread names this.executor = (ThreadPoolExecutor) Executors.newCachedThreadPool(); // to enable automatic expiration of requests, a second scheduled // executor is required which is what a monitor task will be executed // with - this is probably a thread pool that can be shared with between // all client bootstraps this.monitorExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, new ThreadFactory() { private AtomicInteger sequence = new AtomicInteger(0); @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("SmppServer-SessionWindowMonitorPool-" + sequence.getAndIncrement()); return t; } }); // a single instance of a client bootstrap can technically be shared // between any sessions that are created (a session can go to any // different number of SMSCs) - each session created under a client // bootstrap will use the executor and monitorExecutor set in its // constructor - just be *very* careful with the "expectedSessions" // value to make sure it matches the actual number of total concurrent // open sessions you plan on handling - the underlying netty library // used for NIO sockets essentially uses this value as the max number of // threads it will ever use, despite the "max pool size", etc. set on // the executor passed in here // Setting expected session to be 25. May be this should be // configurable? this.clientBootstrap = new DefaultSmppClient(this.executor, 25, monitorExecutor); this.smppClientOpsThread = new SmppClientOpsThread(this.clientBootstrap, outboundInterface("udp").getPort(), smppMessageHandler); (new Thread(this.smppClientOpsThread)).start(); for (Smpp smpp : this.smppList) { this.smppClientOpsThread.scheduleConnect(smpp); } if (logger.isInfoEnabled()) { logger.info("SMPP Service started"); } }