本文整理匯總了Java中javax.naming.CommunicationException類的典型用法代碼示例。如果您正苦於以下問題:Java CommunicationException類的具體用法?Java CommunicationException怎麽用?Java CommunicationException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CommunicationException類屬於javax.naming包,在下文中一共展示了CommunicationException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRDNS
import javax.naming.CommunicationException; //導入依賴的package包/類
/**
* TestCase: get our local address and reverse look it up
*/
@Test
public void testRDNS() throws Exception {
InetAddress localhost = getLocalIPAddr();
try {
String s = DNS.reverseDns(localhost, null);
LOG.info("Local reverse DNS hostname is " + s);
} catch (NameNotFoundException | CommunicationException e) {
if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) {
//these addresses probably won't work with rDNS anyway, unless someone
//has unusual entries in their DNS server mapping 1.0.0.127 to localhost
LOG.info("Reverse DNS failing as due to incomplete networking", e);
LOG.info("Address is " + localhost
+ " Loopback=" + localhost.isLoopbackAddress()
+ " Linklocal=" + localhost.isLinkLocalAddress());
}
}
}
示例2: loginUser
import javax.naming.CommunicationException; //導入依賴的package包/類
void loginUser(VOUser voUser, String password,
HttpServletRequest httpRequest, HttpSession session)
throws LoginException, CommunicationException {
ServiceAccess serviceAccess = ServiceAccess
.getServiceAcccessFor(session);
IdentityService service = getIdService();
// authenticate the user
httpRequest.getSession();
try {
httpRequest.login(String.valueOf(voUser.getKey()), password);
} catch (ServletException e) {
throw new LoginException(e.getMessage());
}
serviceAccess.login(voUser, password, httpRequest, getResponse());
// log info on the successful login
logger.logInfo(Log4jLogger.ACCESS_LOG,
LogMessageIdentifier.INFO_USER_LOGIN_SUCCESS,
voUser.getUserId(), IPResolver.resolveIpAddress(httpRequest),
voUser.getTenantId());
// read the user details value object and store it in the session
session.setAttribute(Constants.SESS_ATTR_USER,
service.getCurrentUserDetails());
}
示例3: getCausedByCommunicationException
import javax.naming.CommunicationException; //導入依賴的package包/類
/**
* Determines if the caught exception was caused by a communication
* exception and return it. If so, the LDAP server cannot be reached.
*
* @param caughtException
* The exception to check the cause for.
* @return The first found CommunicationException or null.
*/
private CommunicationException getCausedByCommunicationException(
Throwable caughtException) {
Throwable cause = caughtException.getCause();
while (cause != null) {
if (cause instanceof CommunicationException) {
return (CommunicationException) cause;
}
if (cause.getMessage()
.contains("javax.naming.CommunicationException")) {
return new CommunicationException();
}
cause = cause.getCause();
}
return null;
}
示例4: decodeSoa
import javax.naming.CommunicationException; //導入依賴的package包/類
private String decodeSoa(int pos) throws CommunicationException {
DnsName mname = new DnsName();
pos = decodeName(pos, mname);
DnsName rname = new DnsName();
pos = decodeName(pos, rname);
long serial = getUInt(pos);
pos += 4;
long refresh = getUInt(pos);
pos += 4;
long retry = getUInt(pos);
pos += 4;
long expire = getUInt(pos);
pos += 4;
long minimum = getUInt(pos); // now used as negative TTL
pos += 4;
return (mname + " " + rname + " " + serial + " " +
refresh + " " + retry + " " + expire + " " + minimum);
}
示例5: decodeNaptr
import javax.naming.CommunicationException; //導入依賴的package包/類
private String decodeNaptr(int pos) throws CommunicationException {
int order = getUShort(pos);
pos += 2;
int preference = getUShort(pos);
pos += 2;
StringBuffer flags = new StringBuffer();
pos += decodeCharString(pos, flags);
StringBuffer services = new StringBuffer();
pos += decodeCharString(pos, services);
StringBuffer regexp = new StringBuffer(rdlen);
pos += decodeCharString(pos, regexp);
DnsName replacement = decodeName(pos);
return (order + " " + preference + " " + flags + " " +
services + " " + regexp + " " + replacement);
}
示例6: toResponse
import javax.naming.CommunicationException; //導入依賴的package包/類
@Override
public Response toResponse(final Throwable exception) {
/*
* Check LDAP communication issue. As this exception is wrapped by a runtime exception brought bySpring-LDAP
* (optional dependency), there is no way a create a specific Mapper.
*/
if (exception.getCause() instanceof CommunicationException) {
log.error("LDAP exception", exception);
return toResponse(Status.SERVICE_UNAVAILABLE, "ldap-down", exception.getCause());
}
// Really not managed exception
log.error("Non managed error", exception);
// Don't expose the associated exception or message since we ignore the content
return toResponse(Status.INTERNAL_SERVER_ERROR, "internal", null);
}
示例7: loginUser
import javax.naming.CommunicationException; //導入依賴的package包/類
void loginUser(VOUser voUser, String password, HttpServletRequest httpRequest,
HttpSession session) throws LoginException, CommunicationException{
ServiceAccess serviceAccess = ServiceAccess
.getServiceAcccessFor(session);
IdentityService service = getIdService();
// authenticate the user
serviceAccess.login(voUser, password, httpRequest,
getResponse());
// log info on the successful login
logger.logInfo(Log4jLogger.ACCESS_LOG,
LogMessageIdentifier.INFO_USER_LOGIN_SUCCESS,
voUser.getUserId(),
IPResolver.resolveIpAddress(httpRequest), voUser.getTenantId());
// read the user details value object and store it in the session
session.setAttribute(Constants.SESS_ATTR_USER,
service.getCurrentUserDetails());
}
示例8: getCausedByCommunicationException
import javax.naming.CommunicationException; //導入依賴的package包/類
/**
* Determines if the caught exception was caused by a communication
* exception and return it. If so, the LDAP server cannot be reached.
*
* @param caughtException
* The exception to check the cause for.
* @return The first found CommunicationException or null.
*/
private CommunicationException getCausedByCommunicationException(
Throwable caughtException) {
Throwable cause = caughtException.getCause();
while (cause != null) {
if (cause instanceof CommunicationException) {
return (CommunicationException) cause;
}
if (cause.getMessage().contains(
"javax.naming.CommunicationException")) {
return new CommunicationException();
}
cause = cause.getCause();
}
return null;
}
示例9: search
import javax.naming.CommunicationException; //導入依賴的package包/類
private NamingEnumeration<SearchResult> search(String name, Attributes matchAttrs) throws NamingException {
try {
return searchWithoutRetry(name, matchAttrs);
} catch (CommunicationException first) {
// I've seen ldap queries fail occasionally with a CommunicationException "connection closed". So try it twice.
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// fall-through
}
try {
return searchWithoutRetry(name, matchAttrs);
} catch (NamingException second) {
second.addSuppressed(first);
throw second;
}
}
}
示例10: testEnsureOnetimeException
import javax.naming.CommunicationException; //導入依賴的package包/類
@Test
public void testEnsureOnetimeException() throws Exception {
MockLdapContext ldapContext = new MockLdapContext() {
boolean firstTime = true;
@Override
public Attributes getAttributes(String name) throws NamingException {
if (firstTime) {
firstTime = false;
throw new CommunicationException("testing");
} else {
return super.getAttributes(name);
}
}
};
addStandardKeysAndResults(ldapContext);
AdServer adServer = new AdServer("localhost", "" /*userSearchBaseDN*/,
"" /*groupSearchBaseDN*/, "" /*userSearchFilter*/,
"" /*groupSearchFilter*/, ldapContext) {
@Override
void recreateLdapContext() {
// do nothing
}
};
adServer.initialize();
}
示例11: testEnsureConnectionOnetimeException
import javax.naming.CommunicationException; //導入依賴的package包/類
@Test
public void testEnsureConnectionOnetimeException() throws Exception {
MockLdapContext ldapContext = new MockLdapContext() {
boolean firstTime = true;
@Override
public Attributes getAttributes(String name) throws NamingException {
if (firstTime) {
firstTime = false;
throw new CommunicationException("testing");
} else {
return super.getAttributes(name);
}
}
};
LdapServer ldapServer = new LdapServer("localhost", "nickname",
"ou=basedn", "userFilter", "cn,dn" /* attributes */,
1000 /* traversalRate */, "dn={dn}, cn={cn}", ldapContext) {
@Override
void recreateLdapContext() {
// do nothing
}
};
ldapServer.initialize();
}
示例12: testEnsureConnectionWrapsStartupException
import javax.naming.CommunicationException; //導入依賴的package包/類
@Test
public void testEnsureConnectionWrapsStartupException() throws Exception {
MockLdapContext ldapContext = new MockLdapContext() {
@Override
public Attributes getAttributes(String name) throws NamingException {
throw new CommunicationException("testing");
}
};
LdapServer ldapServer = new LdapServer("localhost", "nickname",
"ou=basedn", "userFilter", "cn,dn" /* attributes */,
1000 /* traversalRate */, "dn={dn}, cn={cn}", ldapContext) {
@Override
void recreateLdapContext() {
throw new StartupException("persistent problem");
}
};
try {
ldapServer.initialize();
} catch (RuntimeException re) {
assertTrue(re.getCause() instanceof NamingException);
NamingException ne = (NamingException) re.getCause();
assertTrue(ne.getMessage().contains("recreateLdapContext"));
assertTrue(ne.getRootCause() instanceof StartupException);
}
}
示例13: removeNamingListener
import javax.naming.CommunicationException; //導入依賴的package包/類
public void removeNamingListener(NamingListener namingListener)
throws NamingException {
if (listeners == null || !listeners.containsKey(namingListener)) {
return;
}
if (namingListener instanceof UnsolicitedNotificationListener) {
unls.remove(namingListener);
}
List<Integer> idList = listeners.remove(namingListener);
if (idList == null) {
return;
}
try {
for (Integer id : idList) {
client.removePersistentSearch(id.intValue(), requestControls);
}
} catch (IOException e) {
CommunicationException ex = new CommunicationException();
ex.setRootCause(e);
}
}
示例14: next
import javax.naming.CommunicationException; //導入依賴的package包/類
/**
* Retrieves the next element. <code>NoSuchElementException</code> will be
* thrown, if there is no other elements or <code>close()</code> has been
* invoked.
*/
public T next() throws NamingException {
if (values == null || (values.isEmpty() && isFinished)) {
throw new NoSuchElementException();
}
synchronized (values) {
if (values.isEmpty() && !isFinished) {
waitMoreElement();
// wait timeout
if (values.isEmpty() && !isFinished) {
if (exception != null) {
throw exception;
}
// ldap.31=Read LDAP response message time out
throw new CommunicationException(Messages
.getString("ldap.31")); //$NON-NLS-1$
} else if (values.isEmpty()) {
throw new NoSuchElementException();
}
}
return values.poll();
}
}
示例15: test_getExceptionFromResult
import javax.naming.CommunicationException; //導入依賴的package包/類
public void test_getExceptionFromResult() {
String message = "error message";
LdapResult result = getLdapResult(0, message);
NamingException ex = LdapUtils.getExceptionFromResult(result);
assertNull(ex);
// error code map to CommunicationException
result = getLdapResult(2, message);
ex = LdapUtils.getExceptionFromResult(result);
assertTrue(ex instanceof CommunicationException);
assertEquals("[LDAP: error code 2 - error message]", ex.getMessage());
// error code not in map
result = getLdapResult(100, message);
ex = LdapUtils.getExceptionFromResult(result);
assertTrue(ex instanceof NamingException);
assertEquals("[LDAP: error code 100 - error message]", ex.getMessage());
// empty error message
result = getLdapResult(3, "");
ex = LdapUtils.getExceptionFromResult(result);
assertTrue(ex instanceof TimeLimitExceededException);
assertEquals("[LDAP: error code 3]", ex.getMessage());
}