Example usage for java.net UnknownHostException UnknownHostException

List of usage examples for java.net UnknownHostException UnknownHostException

Introduction

In this page you can find the example usage for java.net UnknownHostException UnknownHostException.

Prototype

public UnknownHostException() 

Source Link

Document

Constructs a new UnknownHostException with no detail message.

Usage

From source file:org.restcomm.connect.testsuite.http.util.CustomDnsResolver.java

@Override
public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException {
    if (domainIpMap != null) {
        if (domainIpMap.containsKey(host)) {
            final byte[] arrayOfByte = sun.net.util.IPAddressUtil.textToNumericFormatV4(domainIpMap.get(host));
            final InetAddress address = InetAddress.getByAddress(host, arrayOfByte);
            return new InetAddress[] { address };
        } else {//from   w ww. ja  v a  2  s  .c  o  m
            throw new UnknownHostException();
        }
    } else {
        final byte[] arrayOfByte = sun.net.util.IPAddressUtil.textToNumericFormatV4(LOCALHOST);
        final InetAddress address = InetAddress.getByAddress(host, arrayOfByte);
        return new InetAddress[] { address };
    }
}

From source file:org.restcomm.connect.testsuite.http.util.CustomDnsResolver.java

@Override
public String getHostByAddr(byte[] bytes) throws UnknownHostException {
    throw new UnknownHostException();
}

From source file:org.zalando.logbook.httpclient.RequestTest.java

@Test
public void shouldHandleUnknownHostException() throws UnknownHostException {
    when(localhost.getAddress()).thenThrow(new UnknownHostException());

    exception.expect(IllegalStateException.class);
    exception.expectCause(instanceOf(UnknownHostException.class));

    unit(get("/")).getRemote();
}

From source file:pl.otros.logview.gui.actions.ConnectToSocketHubAppenderActionTest.java

@Test
public void tryToConnectFail() throws IOException {
    OtrosApplication otrosApplication = new OtrosApplication();
    ConnectToSocketHubAppenderAction action = new ConnectToSocketHubAppenderAction(otrosApplication);
    DataConfiguration dc = new DataConfiguration(new BaseConfiguration());
    String hostAndPort = "abc:50";
    SocketFactory socketFactory = mock(SocketFactory.class);
    Socket mockSocket = mock(Socket.class);
    when(socketFactory.createSocket("abc", 50)).thenThrow(new UnknownHostException());

    try {//ww  w.  j  av a 2 s .  c o  m
        action.tryToConnectToSocket(dc, hostAndPort, socketFactory);
        Assert.fail();
    } catch (UnknownHostException e) {
        //success
    }

    assertEquals(0, dc.getList(ConfKeys.SOCKET_HUB_APPENDER_ADDRESSES).size());
}

From source file:com.googlecode.jsendnsca.builders.MessagePayloadBuilderTest.java

@Test
public void shouldConstructPayloadWithoutUsingLocalHostname() {
    MessagePayload messagePayload = new MessagePayloadBuilder() {
        @Override/*from ww w .  j  a v a  2  s .  co m*/
        MessagePayload createMessagePayload() {
            return new MessagePayload(false) {
                @Override
                public void useLocalHostname() {
                    throw new UnknownHostRuntimeException(new UnknownHostException());
                }
            };
        }
    }.create();

    assertEquals("UNKNOWN", messagePayload.getHostname());
    assertEquals(Level.UNKNOWN, messagePayload.getLevel());
    assertEquals("UNDEFINED", messagePayload.getServiceName());
    assertEquals(StringUtils.EMPTY, messagePayload.getMessage());
}

From source file:ac.dynam.rundeck.plugin.resources.ovirt.InstanceToNodeMapper.java

/**
 * Convert an oVirt Instance to a RunDeck INodeEntry based on the mapping input
 *//* w  ww .j av a  2s .  c om*/
@SuppressWarnings("unchecked")
static INodeEntry instanceToNode(final VM inst) throws GeneratorException {
    final NodeEntryImpl node = new NodeEntryImpl();

    node.setNodename(inst.getName());
    node.setOsArch(inst.getCpu().getArchitecture());
    node.setOsName(inst.getOs().getType());
    node.setDescription(inst.getDescription());
    node.setUsername("root");
    InetAddress address = null;
    if (inst.getGuestInfo() != null) {
        try {
            address = InetAddress.getByName(inst.getGuestInfo().getFqdn());
            logger.debug("Host " + node.getNodename() + " Guest FQDN " + inst.getGuestInfo().getFqdn()
                    + " Address: " + address.getHostName());
            if (address.getHostName() == "localhost")
                throw new UnknownHostException();
        } catch (UnknownHostException e) {
            /* try the first IP instead then */
            logger.warn("Host " + node.getNodename() + " address " + inst.getGuestInfo().getFqdn()
                    + " does not resolve. Trying IP addresses instead");
            for (int i = 0; i < inst.getGuestInfo().getIps().getIPs().size(); i++) {
                logger.debug("Host " + node.getNodename() + " Trying "
                        + inst.getGuestInfo().getIps().getIPs().get(i).getAddress());
                try {
                    address = InetAddress.getByName(inst.getGuestInfo().getIps().getIPs().get(i).getAddress());
                    if (address != null) {
                        if (address.isLinkLocalAddress() || address.isMulticastAddress()) {
                            logger.warn("Host " + node.getNodename() + " ip address is not valid: "
                                    + inst.getGuestInfo().getIps().getIPs().get(i).getAddress());
                            continue;
                        }
                        logger.debug("Host " + node.getNodename() + " ip address " + address.getHostAddress()
                                + " will be used instead");
                        break;
                    }
                } catch (UnknownHostException e1) {
                    logger.warn("Host " + node.getNodename() + " IP Address "
                            + inst.getGuestInfo().getIps().getIPs().get(i).getAddress() + " is invalid");
                }
            }
        }
    }
    if (address == null) {
        /* try resolving based on name */
        try {
            address = InetAddress.getByName(node.getNodename());
        } catch (UnknownHostException e) {
            logger.warn("Unable to Find IP address for Host " + node.getNodename());
            return null;
        }
    }

    if (address != null)
        node.setHostname(address.getCanonicalHostName());

    if (inst.getTags() != null) {
        VMTags tags = inst.getTags();
        final HashSet<String> tagset = new HashSet<String>();
        try {
            for (int j = 0; j < tags.list().size(); j++) {
                tagset.add(tags.list().get(j).getName());
            }
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ServerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (null == node.getTags()) {
            node.setTags(tagset);
        } else {
            final HashSet<String> orig = new HashSet<String>(node.getTags());
            orig.addAll(tagset);
            node.setTags(orig);
        }
    }

    if (inst.getHighAvailability().getEnabled())
        node.setAttribute("HighAvailability", "true");
    if (inst.getType() != null)
        node.setAttribute("Host Type", inst.getType());
    node.setAttribute("oVirt VM", "true");
    node.setAttribute("oVirt Host", inst.getHost().getName());

    return node;
}

From source file:uk.me.sa.lightswitch.android.net.TestRequestMessage.java

@Before
public void mock() throws Exception {
    mockStatic(Log.class);

    mockStatic(InetAddress.class);
    when(InetAddress.getAllByName("test.node.invalid")).thenReturn(new InetAddress[] { address1 });
    when(InetAddress.getAllByName("test.nodes.invalid"))
            .thenReturn(new InetAddress[] { address1, address2, address3 });
    when(InetAddress.getAllByName("unknown.node.invalid")).thenThrow(new UnknownHostException());
    when(InetAddress.getAllByName("empty.node.invalid")).thenReturn(new InetAddress[0]);

    whenNew(DatagramSocket.class).withAnyArguments().thenReturn(socket);

    mockStatic(System.class);
}

From source file:com.spotify.helios.client.EndpointsTest.java

@Test
public void testUnableToResolve() throws Exception {
    final DnsResolver resolver = mock(DnsResolver.class);
    when(resolver.resolve("example.com")).thenThrow(new UnknownHostException());
    when(resolver.resolve("example.net")).thenThrow(new UnknownHostException());
    final List<Endpoint> endpoints = Endpoints.of(uris, resolver);

    assertThat(endpoints.size(), equalTo(0));
}

From source file:org.tt.core.fetch.lexx.LexxDataFetcher.java

/**
 * Parsing method. It is dedicated to be able to override it in the test method.
 * @param link The link to the SSU endpoint.
 * @return DOM-parsed XML file.//from  w ww.  ja  v  a 2 s  . c o m
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
protected Document getDocFromURL(String link) throws IOException, SAXException, ParserConfigurationException {
    DocumentBuilder builder = factory.newDocumentBuilder();
    URL url;
    URLConnection conn = null;
    try {
        url = new URL(link);
        conn = url.openConnection();
        String encoded = Base64.encodeBase64String(StringUtils.getBytesUtf8(loginPassword));
        conn.setRequestProperty("Authorization", "Basic " + encoded);
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (conn != null) {
        return builder.parse(conn.getInputStream());
    } else
        throw new UnknownHostException();
}

From source file:eu.alefzero.owncloud.syncadapter.AbstractOwnCloudSyncAdapter.java

protected WebdavClient getClient() throws OperationCanceledException, AuthenticatorException, IOException {
    if (mClient == null) {
        if (this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL) == null) {
            throw new UnknownHostException();
        }//from   w  w w .  ja  v  a  2 s . c o  m
        mClient = new WebdavClient(account, getContext());
        // mHost = mClient.getTargetHost();
    }

    return mClient;
}