use of org.apache.struts2.config in project jdk8u_jdk by JetBrains.
the class DNS method main.
public static void main(String[] args) throws Exception {
System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") + "/no-such-file.conf");
Config config = Config.getInstance();
try {
String r = config.getDefaultRealm();
throw new Exception("What? There is a default realm " + r + "?");
} catch (KrbException ke) {
ke.printStackTrace();
if (ke.getCause() != null) {
throw new Exception("There should be no cause. Won't try DNS");
}
}
String kdcs = config.getKDCList("X");
if (!kdcs.equals("a.com.:88 b.com.:99") && !kdcs.equals("a.com. b.com.:99")) {
throw new Exception("Strange KDC: [" + kdcs + "]");
}
;
}
use of org.apache.struts2.config in project jdk8u_jdk by JetBrains.
the class SCDynamicConfigTest method main.
public static void main(String[] args) throws Exception {
// Reconstruct a typical SCDynamicConfig.getKerberosConfig() output
Hashtable<String, Object> conf = new Hashtable<>();
Hashtable<String, Object> libdefaults = new Hashtable<>();
libdefaults.put("default_realm", "REALM.COM");
conf.put("libdefaults", libdefaults);
Hashtable<String, Object> realms = new Hashtable<>();
Hashtable<String, Object> thisRealm = new Hashtable<>();
realms.put("REALM.COM", thisRealm);
thisRealm.put("kpasswd", hosts());
thisRealm.put("kadmin", hosts());
thisRealm.put("kdc", hosts());
conf.put("realms", realms);
Hashtable<String, Object> domain_realm = new Hashtable<>();
domain_realm.put(".realm.com", "REALM.COM");
domain_realm.put("realm.com", "REALM.COM");
conf.put("domain_realm", domain_realm);
System.out.println("SCDynamicConfig:\n");
System.out.println(conf);
// Simulate SCDynamicConfig.getConfig() output
Method m = SCDynamicStoreConfig.class.getDeclaredMethod("convertNativeConfig", Hashtable.class);
m.setAccessible(true);
conf = (Hashtable) m.invoke(null, conf);
System.out.println("\nkrb5.conf:\n");
System.out.println(conf);
// Feed it into a Config object
System.setProperty("java.security.krb5.conf", "not-a-file");
Config cf = Config.getInstance();
Field f = Config.class.getDeclaredField("stanzaTable");
f.setAccessible(true);
f.set(cf, conf);
System.out.println("\nConfig:\n");
System.out.println(cf);
if (!cf.getDefaultRealm().equals("REALM.COM")) {
throw new Exception();
}
if (!cf.getKDCList("REALM.COM").equals("127.0.0.1 127.0.0.2")) {
throw new Exception();
}
if (!cf.get("domain_realm", ".realm.com").equals("REALM.COM")) {
throw new Exception();
}
}
use of org.apache.struts2.config in project jdk8u_jdk by JetBrains.
the class Duplicates method main.
public static void main(String[] args) throws Exception {
System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") + "/k1.conf");
Config config = Config.getInstance();
config.listTable();
String s;
// Latter overwrites former for root section
s = config.get("libdefaults", "default_realm");
if (s != null) {
throw new Exception();
}
// Latter overwrites former for strings
s = config.get("libdefaults", "default_tkt_enctypes");
if (!s.equals("aes256-cts")) {
throw new Exception();
}
// Latter overwrites former for sub-section
s = config.get("realms", "R1", "kdc");
if (!s.equals("k2")) {
throw new Exception(s);
}
// Duplicate keys in [realms] are merged
s = config.getAll("realms", "R2", "kdc");
if (!s.equals("k1 k2 k3 k4")) {
throw new Exception(s);
}
// Duplicate keys in [capaths] are merged
s = config.getAll("capaths", "R1", "R2");
if (!s.equals("R3 R4 R5 R6")) {
throw new Exception(s);
}
// We can be very deep now
s = config.get("new", "x", "y", "z", "a", "b", "c");
if (!s.equals("d")) {
throw new Exception(s);
}
}
use of org.apache.struts2.config in project controller by opendaylight.
the class TracingBrokerTest method testPrintOpenTransactions.
@Test
// Finding resource leaks is the point of this test
@SuppressWarnings({ "resource", "unused" })
public void testPrintOpenTransactions() {
DOMDataBroker domDataBroker = mock(DOMDataBroker.class, RETURNS_DEEP_STUBS);
Config config = new ConfigBuilder().setTransactionDebugContextEnabled(true).build();
BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
DOMDataReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
boolean printReturnValue = tracingBroker.printOpenTransactions(ps);
String output = new String(baos.toByteArray(), UTF_8);
assertThat(printReturnValue).isTrue();
// Assert expections about stack trace
assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
assertThat(output).doesNotContain(TracingBroker.class.getName());
String previousLine = "";
for (String line : output.split("\n")) {
if (line.contains("(...")) {
assertThat(previousLine.contains("(...)")).isFalse();
}
previousLine = line;
}
// We don't do any verify/times on the mocks,
// because the main point of the test is just to verify that
// printOpenTransactions runs through without any exceptions
// (e.g. it used to have a ClassCastException).
}
use of org.apache.struts2.config in project qi4j-sdk by Qi4j.
the class Qi4jCodebehindPackageProvider method processActionClass.
/**
* Create a default action mapping for a class instance.
*
* The namespace annotation is honored, if found, otherwise
* the Java package is converted into the namespace
* by changing the dots (".") to slashes ("/").
*
* @param cls Action or POJO instance to process
* @param pkgs List of packages that were scanned for Actions
*/
protected void processActionClass(Class<?> cls, String[] pkgs) {
String name = cls.getName();
String actionPackage = cls.getPackage().getName();
String actionNamespace = null;
String actionName = null;
org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) cls.getAnnotation(org.apache.struts2.config.Action.class);
if (actionAnn != null) {
actionName = actionAnn.name();
if (actionAnn.namespace().equals(org.apache.struts2.config.Action.DEFAULT_NAMESPACE)) {
actionNamespace = "";
} else {
actionNamespace = actionAnn.namespace();
}
} else {
for (String pkg : pkgs) {
if (name.startsWith(pkg)) {
if (LOG.isDebugEnabled()) {
LOG.debug("ClasspathPackageProvider: Processing class " + name);
}
name = name.substring(pkg.length() + 1);
actionNamespace = "";
actionName = name;
int pos = name.lastIndexOf('.');
if (pos > -1) {
actionNamespace = "/" + name.substring(0, pos).replace('.', '/');
actionName = name.substring(pos + 1);
}
break;
}
}
// Truncate Action suffix if found
if (actionName.endsWith(getClassSuffix())) {
actionName = actionName.substring(0, actionName.length() - getClassSuffix().length());
}
// Force initial letter of action to lowercase, if desired
if ((forceLowerCase) && (actionName.length() > 1)) {
int lowerPos = actionName.lastIndexOf('/') + 1;
StringBuilder sb = new StringBuilder();
sb.append(actionName.substring(0, lowerPos));
sb.append(Character.toLowerCase(actionName.charAt(lowerPos)));
sb.append(actionName.substring(lowerPos + 1));
actionName = sb.toString();
}
}
PackageConfig.Builder pkgConfig = loadPackageConfig(actionNamespace, actionPackage, cls);
// In case the package changed due to namespace annotation processing
if (!actionPackage.equals(pkgConfig.getName())) {
actionPackage = pkgConfig.getName();
}
Annotation annotation = cls.getAnnotation(ParentPackage.class);
if (annotation != null) {
String parent = ((ParentPackage) annotation).value()[0];
PackageConfig parentPkg = configuration.getPackageConfig(parent);
if (parentPkg == null) {
throw new ConfigurationException("ClasspathPackageProvider: Unable to locate parent package " + parent, annotation);
}
pkgConfig.addParent(parentPkg);
if (!isNotEmpty(pkgConfig.getNamespace()) && isNotEmpty(parentPkg.getNamespace())) {
pkgConfig.namespace(parentPkg.getNamespace());
}
}
ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig);
ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName()).addResultConfigs(new ResultMap<String, ResultConfig>(cls, actionName, defaultResultType)).build();
pkgConfig.addActionConfig(actionName, actionConfig);
}
Aggregations