use of java.net.UnknownHostException in project android_frameworks_base by ResurrectionRemix.
the class Log method printlns.
/**
* Helper function for long messages. Uses the LineBreakBufferedWriter to break
* up long messages and stacktraces along newlines, but tries to write in large
* chunks. This is to avoid truncation.
* @hide
*/
public static int printlns(int bufID, int priority, String tag, String msg, Throwable tr) {
ImmediateLogWriter logWriter = new ImmediateLogWriter(bufID, priority, tag);
// Acceptable buffer size. Get the native buffer size, subtract two zero terminators,
// and the length of the tag.
// Note: we implicitly accept possible truncation for Modified-UTF8 differences. It
// is too expensive to compute that ahead of time.
int bufferSize = // Base.
NoPreloadHolder.LOGGER_ENTRY_MAX_PAYLOAD - // Two terminators.
2 - // Tag length.
(tag != null ? tag.length() : 0) - // Some slack.
32;
// At least assume you can print *some* characters (tag is not too large).
bufferSize = Math.max(bufferSize, 100);
LineBreakBufferedWriter lbbw = new LineBreakBufferedWriter(logWriter, bufferSize);
lbbw.println(msg);
if (tr != null) {
// This is to reduce the amount of log spew that apps do in the non-error
// condition of the network being unavailable.
Throwable t = tr;
while (t != null) {
if (t instanceof UnknownHostException) {
break;
}
if (t instanceof DeadSystemException) {
lbbw.println("DeadSystemException: The system died; " + "earlier logs will point to the root cause");
break;
}
t = t.getCause();
}
if (t == null) {
tr.printStackTrace(lbbw);
}
}
lbbw.flush();
return logWriter.getWritten();
}
use of java.net.UnknownHostException in project OpenAM by OpenRock.
the class HttpsClient method doConnect.
/**
* Overrides HTTP protocol handler method so that we return an SSL
* socket, not a TCP socket. This establishes a secure tunnel if
* appropriate.
*
* @param host the host to connect to
* @param port the port on that host.
* @exception IOException on errors including a host doesn't
* authenicate corectly.
* @exception UnknownHostException if "host" is unknown
*/
protected Socket doConnect(String host, int port) throws IOException {
String hostname = null;
try {
hostname = InetAddress.getByName(host).getHostName();
} catch (UnknownHostException e) {
if (debug.messageEnabled()) {
debug.message("Error : HttpsClient.doConnect ", e);
}
hostname = host;
}
if (secureTunnelHost == null || isNonProxyHost()) {
if (debug.messageEnabled()) {
debug.message("HttpsClient: doConnect(" + hostname + ", " + port + ")");
}
sslSocket = new SSLSocket(InetAddress.getByName(hostname), port, null, 0, new ApprovalCallback(hostname), this);
} else {
if (debug.messageEnabled()) {
debug.message("HttpsClient: doConnect through proxy " + secureTunnelHost + ":" + secureTunnelPort);
}
if (debug.messageEnabled()) {
debug.message("HttpsClient: doConnect(" + hostname + ", " + port + ")");
}
sslSocket = new SSLSocket(InetAddress.getByName("localhost"), JSSProxy.serverPort, null, 0, new ApprovalCallback(hostname), this);
Integer localport = new Integer(sslSocket.getLocalPort());
String info = secureTunnelHost + " " + secureTunnelPort + " " + host + " " + port;
JSSProxy.connectHashMap.put(localport, info);
}
return sslSocket;
}
use of java.net.UnknownHostException in project OpenAM by OpenRock.
the class HttpsClient method isNonProxyHost.
/**
* Returns true if host is on the "don't proxy" list.
*/
protected boolean isNonProxyHost() {
if (dontProxy.match(url.getHost().toLowerCase()) != null) {
return true;
}
try {
InetAddress addr = InetAddress.getByName(url.getHost());
String host = addr.getHostAddress();
if (dontProxy.match(host) != null) {
return true;
}
} catch (UnknownHostException ignored) {
debug.error("Host name is unknown but ignored.", ignored);
}
return false;
}
use of java.net.UnknownHostException in project opennms by OpenNMS.
the class Nms4930NetworkBuilder method addMacNodeWithSnmpInterface.
public void addMacNodeWithSnmpInterface(String mac, String ip, Integer ifindex) {
NetworkBuilder nb = getNetworkBuilder();
nb.addNode(ip).setForeignSource("linkd").setForeignId(ip).setType(NodeType.ACTIVE);
nb.addInterface(ip).setIsSnmpPrimary("N").setIsManaged("M").addSnmpInterface(ifindex).setIfName("eth0").setIfType(6).setPhysAddr(mac).setIfDescr("eth0");
m_nodeDao.save(nb.getCurrentNode());
m_nodeDao.flush();
IpNetToMedia at0 = new IpNetToMedia();
at0.setSourceIfIndex(100);
at0.setPhysAddress(mac);
at0.setLastPollTime(at0.getCreateTime());
at0.setSourceNode(m_nodeDao.findByForeignId("linkd", ip));
try {
at0.setNetAddress(InetAddress.getByName(ip));
} catch (UnknownHostException e) {
e.printStackTrace();
}
at0.setIpNetToMediaType(IpNetToMediaType.IPNETTOMEDIA_TYPE_DYNAMIC);
m_ipNetToMediaDao.saveOrUpdate(at0);
m_ipNetToMediaDao.flush();
}
use of java.net.UnknownHostException in project OpenAM by OpenRock.
the class InteractionManager method handleInteraction.
/**
* Handles resource owner interactions on behalf of <code>WSP</code>.
* This is invoked at <code>WSP</code> side.
*
* @param requestMessage SOAP request that requires resource
* owner interactions
* @param inquiryElement query that <code>WSP</code> wants to pose to
* resource owner
* @param language language in which the query page needs to be rendered
* @return SOAP message that contains <code>InteractionResponse</code>,
* gathered by <code>InteractionManager</code>
*
* @throws InteractionException for generic interaction error
* @throws InteractionSOAPFaultException if a SOAP fault
* has to be returned to <code>WSC</code>
* @throws SOAPFaultException if the response message has SOAP fault
*
* @supported.api
*/
public Message handleInteraction(Message requestMessage, InquiryElement inquiryElement, String language) throws InteractionException, InteractionSOAPFaultException, SOAPFaultException {
if (debug.messageEnabled()) {
debug.message("InteractionManager.handleInteraction():entering");
}
//Check redirect is enabled for WSP
if (!interactionConfig.wspSupportsRedirect()) {
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + " WSP requests for interaction:wspWillRedirect=" + interactionConfig.wspSupportsRedirect());
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionException");
}
throw new InteractionException(INTERACTION_RB_NAME, "wsp_does_not_support_interaction", null);
}
//Check wsc provided UserInteraction header
UserInteractionElement ue = getUserInteractionElement(requestMessage);
if (ue == null) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + " WSP requests for interaction - WSC did not " + " provide UserInteractionHeader");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSC is willing to redirect
if (ue.isRedirect() == false) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP rquests for interaction - WSC " + " says redirect=false");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSC allowed interaction
if (ue.getInteract().equals(QNAME_DO_NOT_INTERACT)) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP rquests for interaction - WSC " + " UserInteractionHeader says doNotInteract");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSC allowed interaction for data
if (interactionConfig.wspRedirectsForData() && ue.getInteract().equals(QNAME_DO_NOT_INTERACT_FOR_DATA)) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_REQUIRED_FOR_DATA);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP rquests interaction for data - WSC " + " UserInteractionHeader says doNotInteractForData");
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
//Check WSP will not exceed maxInteractionTime specified by WSC
BigInteger uemi = ue.getMaxInteractTime();
if ((uemi != null) && (interactionConfig.getWSPRedirectTime() > uemi.intValue())) {
SOAPFaultException sfe = newRedirectFaultError(QNAME_INTERACTION_TIME_NOT_SUFFICEINT);
if (debug.warningEnabled()) {
debug.warning("InteractionManager.handleInteraction():" + "WSP inteaction time =" + interactionConfig.getWSPRedirectTime() + " exceeds WSC maxInteractTime= " + ue.getMaxInteractTime());
debug.warning("InteractionManager.handleInteraction():" + "throwing InteractionSOAPFaultException=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
}
String requestMessageID = requestMessage.getCorrelationHeader().getMessageID();
SOAPFaultException sfe = newRedirectFault(requestMessageID);
String redirectResponseID = getResponseID(sfe);
String requestIP = requestMessage.getIPAddress();
String requestHost = null;
if (interactionConfig.wspEnforcesReturnToHostEqualsRequestHost()) {
try {
InetAddress inetAddress = InetAddress.getByName(requestIP);
//requestHost = inetAddress.getCanonicalHostName();
requestHost = inetAddress.getHostName();
if (debug.messageEnabled()) {
debug.message("InteractionManager.handleInteraction():" + " caching requestHost=" + requestHost + ", for redirectResponseID= " + redirectResponseID);
}
setRequestHost(redirectResponseID, requestHost);
} catch (UnknownHostException uhe) {
debug.error("InteractionManager.handleInteraction():" + " can not resolve host name", uhe);
debug.error("InteractionManager.handleInteraction():" + " throwing InteractionSOAPFaultException", sfe);
SOAPFaultException sfe1 = newRedirectFaultError(QNAME_INTERACTION_CAN_NOT_DETERMINE_REQUEST_HOST);
throw new InteractionSOAPFaultException(sfe1);
}
}
setInquiryElement(redirectResponseID, inquiryElement);
setRequestMessageID(redirectResponseID, requestMessageID);
setLanguage(redirectResponseID, language);
if (debug.messageEnabled()) {
debug.message("InteractionManager.handleInteraction():" + " throwing InteractionSOAPFaultException " + " to redirect user agent=" + sfe);
}
throw new InteractionSOAPFaultException(sfe);
//return responseMessage;
}
Aggregations