本文整理汇总了Java中javax.naming.NamingException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java NamingException.printStackTrace方法的具体用法?Java NamingException.printStackTrace怎么用?Java NamingException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.NamingException
的用法示例。
在下文中一共展示了NamingException.printStackTrace方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import javax.naming.NamingException; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain;UTF-8");
PrintWriter out = resp.getWriter();
try {
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/bug50351");
TesterObject to = (TesterObject) obj;
out.print(to.getFoo());
} catch (NamingException ne) {
ne.printStackTrace(out);
}
}
示例2: LdapUtil
import javax.naming.NamingException; //导入方法依赖的package包/类
public LdapUtil(String csUserId, String csPassword, String csServer)
{
try
{
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://"+csServer+"/");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, csUserId);
env.put(Context.SECURITY_CREDENTIALS, csPassword);
m_ctx = new InitialDirContext(env);
}
catch (NamingException e)
{
e.printStackTrace();
m_ctx = null ;
}
}
示例3: doGet
import javax.naming.NamingException; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain;UTF-8");
PrintWriter out = resp.getWriter();
try {
Context ctx = new InitialContext();
Object obj1 = ctx.lookup("java:comp/env/list/foo");
Object obj2 = ctx.lookup("java:comp/env/list/foo");
if (obj1 == obj2) {
out.print("EQUAL");
} else {
out.print("NOTEQUAL");
}
} catch (NamingException ne) {
ne.printStackTrace(out);
}
}
示例4: createJMSProviderObject
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* Creates an object using qpid/amq initial context factory.
*
* @param className can be any of the qpid/amq supported JNDI properties:
* connectionFactory, queue, topic, destination.
* @param address of the connection or node to create.
*/
protected Object createJMSProviderObject(String className, String address) {
final String initialContext = AMQ_INITIAL_CONTEXT;
Properties properties = new Properties();
/* Name of the object is the same as class of the object */
String name = className;
properties.setProperty("java.naming.factory.initial", initialContext);
properties.setProperty(className + "." + name, address);
Object jmsProviderObject = null;
try {
Context context = new InitialContext(properties);
jmsProviderObject = context.lookup(name);
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
return jmsProviderObject;
}
示例5: getOneAttribute
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* @param dn
* @param attributeName
* @return
* @throws NamingException
*/
public String getOneAttribute(String dn, String attributeName)
{
try
{
Attributes attrs = m_ctx.getAttributes(dn);
Attribute attr = attrs.get(attributeName);
if (attr != null)
{
Log.logDebug("getID : " + attr.getID());
NamingEnumeration enumeration = attr.getAll();
while (enumeration.hasMore())
{
Log.logDebug("getAll : " + enumeration.next());
}
return (String) attr.get();
}
}
catch (NamingException e)
{
e.printStackTrace();
return "" ;
}
return "" ;
}
示例6: createJMSProviderObject
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* Creates an object using qpid/amq initial context factory.
*
* @param className can be any of the qpid/amq supported JNDI properties:
* connectionFactory, queue, topic, destination.
* @param address of the connection or node to create.
*/
protected Object createJMSProviderObject(String className, String address) {
/* Name of the object is the same as class of the object */
String name = className;
properties.setProperty(className + "." + name, address);
Object jmsProviderObject = null;
try {
Context context = new InitialContext(properties);
jmsProviderObject = context.lookup(name);
context.close();
} catch (NamingException e) {
e.printStackTrace();
}
return jmsProviderObject;
}
示例7: jndiLookup
import javax.naming.NamingException; //导入方法依赖的package包/类
/** Effettua il lookup di una risorsa JMS. */
public Object jndiLookup(String resourceName) {
Object resource = null;
try {
logger.info("Lookup della risorsa JNDI: " + resourceName);
/* effettua il lookup della risorsa cercata */
resource = getContext().lookup(resourceName);
logger.fine("Lookup di " + resourceName + " riuscito");
} catch (NamingException e) {
logger.info("Lookup di " + resourceName + " fallito");
e.printStackTrace();
// System.exit(1);
}
return resource;
}
示例8: searchSubtree
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* @param dn
* @param filter
* @return
* @throws NamingException
*/
public NamingEnumeration searchSubtree(String dn, String filter)
{
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
try
{
return m_ctx.search(dn, filter, constraints);
}
catch (NamingException e)
{
e.printStackTrace();
return null ;
}
}
示例9: getObjectDn
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* Low level method: Retrieves a serialized Java Object,
* using the specified dn/pswd for authorization.
* See {@link #storeObjectDn storeObjectDn}.
*
* @param authDn the authorized dn (distinguished name) of the caller
* @param password the password associated with authDn
* @param objectDn the dn of the object.
*/
public Object getObjectDn(
String authDn,
String password,
String objectDn)
throws LdapException
{
chkstg( "object dn", objectDn);
Object obj = null;
DirContext dirctx = getDirContext( authDn, password);
try {
obj = dirctx.lookup( objectDn);
if (bugs >= 1 && obj instanceof Context) {
Context ctx = (Context) obj;
prtln("getObjectDn: got Context: " + ctx.getNameInNamespace());
}
}
catch( NamingException nexc) {
if (bugs >= 1) {
prtln("getObjectDn: nexc: " + nexc);
nexc.printStackTrace();
prtln();
prtln("authDn: \"" + authDn + "\"");
prtln("password: \"" + password + "\"");
prtln("objectDn: \"" + objectDn + "\"");
prtln();
}
throw new LdapException("getObjectDn: exception", nexc);
}
return obj;
}
示例10: renameEntryDn
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* <b>Deprecated:</b> Low level method: renames an entry in the LDAP database,
* using the specified dn/pswd for authorization.
*
* @param host the URI of the LDAP server.
* @param authDn the authorized dn (distinguished name) of the caller
* @param password the password associated with authDn
* @param oldDn the old dn.
* @param newDn the new dn.
*/
public void renameEntryDn(
String authDn,
String password,
String oldDn,
String newDn)
throws LdapException
{
chkstg( "old dn", oldDn);
chkstg( "new dn", newDn);
DirContext dirctx = getDirContext( authDn, password);
try { dirctx.rename( oldDn, newDn); }
catch( NamingException nexc) {
if (bugs >= 1) {
prtln("renameEntryDn: nexc: " + nexc);
nexc.printStackTrace();
prtln();
prtln("authDn: \"" + authDn + "\"");
prtln("password: \"" + password + "\"");
prtln("oldDn: \"" + oldDn + "\"");
prtln("newDn: \"" + newDn + "\"");
prtln();
}
throw new LdapException("renameEntryDn: exception", nexc);
}
}
示例11: removeEntryDn
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* Low level method: removes an entry from the LDAP database,
* using the specified dn/pswd for authorization.
* <p>
* Silly JNDI/LDAP spec: Returns void, with no exceptions, whether
* or not the subjectDn existed before the call.
*
* @param host the URI of the LDAP server.
* @param authDn the authorized dn (distinguished name) of the caller
* @param password the password associated with authDn
* @param subjectDn the dn to be removed.
*/
public void removeEntryDn(
String authDn,
String password,
String subjectDn)
throws LdapException
{
chkstg( "subject dn", subjectDn);
// Insure entry exists. If not, getAttributesDn will throw
// LdapNotFoundException.
getAttributesDn(
authDn,
password,
subjectDn,
null);
DirContext dirctx = getDirContext( authDn, password);
try { dirctx.unbind( subjectDn); }
catch( NamingException nexc) {
if (bugs >= 1) {
prtln("removeEntryDn: nexc: " + nexc);
nexc.printStackTrace();
prtln();
prtln("authDn: \"" + authDn + "\"");
prtln("password: \"" + password + "\"");
prtln("subjectDn: \"" + subjectDn + "\"");
prtln();
}
throw new LdapException("removeEntryDn: exception", nexc);
}
}
示例12: createInitialDirContext
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* Create InitialDirContext.
*
* @param server Server DNS name hosting LDAP service
* @param port Port at which server listens for requests
* @throws InvalidAlgorithmParameterException if creation fails
*/
private void createInitialDirContext(String server, int port)
throws InvalidAlgorithmParameterException {
String url = "ldap://" + server + ":" + port;
Hashtable<String,Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
// If property is set to true, disable application resource file lookup.
boolean disableAppResourceFiles = AccessController.doPrivileged(
new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES));
if (disableAppResourceFiles) {
if (debug != null) {
debug.println("LDAPCertStore disabling app resource files");
}
env.put("com.sun.naming.disable.app.resource.files", "true");
}
try {
ctx = new InitialDirContext(env);
/*
* By default, follow referrals unless application has
* overridden property in an application resource file.
*/
Hashtable<?,?> currentEnv = ctx.getEnvironment();
if (currentEnv.get(Context.REFERRAL) == null) {
ctx.addToEnvironment(Context.REFERRAL, "follow");
}
} catch (NamingException e) {
if (debug != null) {
debug.println("LDAPCertStore.engineInit about to throw "
+ "InvalidAlgorithmParameterException");
e.printStackTrace();
}
Exception ee = new InvalidAlgorithmParameterException
("unable to create InitialDirContext using supplied parameters");
ee.initCause(e);
throw (InvalidAlgorithmParameterException)ee;
}
}
示例13: createInitialDirContext
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* Create InitialDirContext.
*
* @param server Server DNS name hosting LDAP service
* @param port Port at which server listens for requests
* @throws InvalidAlgorithmParameterException if creation fails
*/
private void createInitialDirContext(String server, int port)
throws InvalidAlgorithmParameterException {
String url = "ldap://" + server + ":" + port;
Hashtable<String,Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
// If property is set to true, disable application resource file lookup.
boolean disableAppResourceFiles = AccessController.doPrivileged(
(PrivilegedAction<Boolean>) () -> Boolean.getBoolean(PROP_DISABLE_APP_RESOURCE_FILES));
if (disableAppResourceFiles) {
if (debug != null) {
debug.println("LDAPCertStore disabling app resource files");
}
env.put("com.sun.naming.disable.app.resource.files", "true");
}
try {
ctx = new InitialLdapContext(env, null);
/*
* By default, follow referrals unless application has
* overridden property in an application resource file.
*/
Hashtable<?,?> currentEnv = ctx.getEnvironment();
if (currentEnv.get(Context.REFERRAL) == null) {
ctx.addToEnvironment(Context.REFERRAL, "follow-scheme");
}
} catch (NamingException e) {
if (debug != null) {
debug.println("LDAPCertStore.engineInit about to throw "
+ "InvalidAlgorithmParameterException");
e.printStackTrace();
}
Exception ee = new InvalidAlgorithmParameterException
("unable to create InitialDirContext using supplied parameters");
ee.initCause(e);
throw (InvalidAlgorithmParameterException)ee;
}
}
示例14: decodeValues
import javax.naming.NamingException; //导入方法依赖的package包/类
/**
* Converts a JNDI BasicAttribute into an array of Object[].
* <p>
* The returned Object[] resvec has:<br>
* resvec[0] == The String attribute name<br>
* resvec[1] ... resvec[n] == The n values associated with the attribute.<br>
* <p>
* Note that the returned values may be any serializable Object,
* not necessarily Strings.
*/
private Object[] decodeValues( BasicAttribute battr)
throws LdapException
{
Object[] resvec = null;
String attrid = battr.getID();
if (bugs >= 1) prtln("decodeValues: attrid: \"" + attrid + "\"");
NamingEnumeration valenum = null;
ArrayExc valvec = null;
try { valenum = battr.getAll(); }
catch( NamingException nexc) {
if (bugs >= 1) {
prtln("decodeValues: nexc: " + nexc);
nexc.printStackTrace();
prtln();
prtln("battr: \"" + battr + "\"");
prtln("attrid: \"" + attrid + "\"");
prtln();
}
throw new LdapException("decodeValues: exception", nexc);
}
valvec = fixEnum( valenum);
if (valvec.exc != null)
throw new LdapException("valvec hidden exception", valvec.exc);
if (valvec.vals.length == 0) {
resvec = new Object[1];
resvec[0] = attrid;
}
else {
// Sort the values
Arrays.sort( valvec.vals, new Comparator() {
public int compare( Object obja, Object objb) {
String stga = obja.toString();
String stgb = objb.toString();
return stga.compareTo( stgb);
}
public boolean equals( Object obj) { return false; }
});
resvec = new Object[ 1 + valvec.vals.length];
resvec[0] = attrid;
for (int ival = 0; ival < valvec.vals.length; ival++) {
if (bugs >= 1) prtln("decodeValues: value " + ival + ": "
+ valvec.vals[ ival].getClass().getName() + " \""
+ valvec.vals[ ival] + "\"");
resvec[ 1 + ival] = valvec.vals[ ival];
}
}
return resvec;
}