下面列出了java.net.UnknownHostException#printStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public List<PeerInfo> parsePeerDiscoveryIpList(final String peerDiscoveryIpList){
final List<String> ipList = Arrays.asList( peerDiscoveryIpList.split(",") );
final List<PeerInfo> peers = new ArrayList<>();
for (String ip : ipList){
String[] addr = ip.trim().split(":");
String ip_trim = addr[0];
String port_trim = addr[1];
try {
InetAddress iAddr = InetAddress.getByName(ip_trim);
int port = Integer.parseInt(port_trim);
PeerInfo peerData = new PeerInfo(iAddr, port, "");
peers.add(peerData);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
return peers;
}
private void decode()throws MalformedPCEPObjectException {
if (this.TLVValueLength!=8){
throw new MalformedPCEPObjectException("Bad Length of PCE_ID_TLV");
}
int offset=4;
addresType=((this.tlv_bytes[offset]<<8)& 0xFF00) | (this.tlv_bytes[offset+1] & 0xFF);
byte[] ip=new byte[4];
offset=8;
System.arraycopy(this.tlv_bytes,offset, ip, 0, 4);
try {
pceId=(Inet4Address)Inet4Address.getByAddress(ip);
} catch (UnknownHostException e) {
e.printStackTrace();
throw new MalformedPCEPObjectException("Bad IP Address");
}
}
@Override
public boolean contains(Object key) {
// System.out.println("Looking for: " + key);
long address = 0;
if (key instanceof Long)
address = (long) key;
else
try {
InetAddress inetAddress = InetAddress.getByName((String) key);
ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE);
buffer.put(inetAddress.getAddress());
buffer.position(0);
address = buffer.getLong();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println("X = " + address);
return search(address);
}
/**
* BigInteger를 ip로 형변환
* @param bInt
* @return BigInteger를 ip로 형변환
* @throws UnknownHostException
*/
public static String BigIntegerToIp(BigInteger bInt) {
byte[] bytes = bInt.toByteArray();
int bytesLeg = bytes.length;
int ipLeg = (bInt.compareTo(new BigInteger("4294967295")) != 1) ? 4 : 16;
byte[] setBytes = new byte[ipLeg];
for(int i=0; i<ipLeg; i++) {
setBytes[i] = 0;
}
if((bytesLeg == 5 && ipLeg == 4) || (bytesLeg == 17 && ipLeg == 16)) {
System.arraycopy(bytes, 1, setBytes, 0, bytesLeg-1);
} else {
System.arraycopy(bytes, 0, setBytes, ipLeg-bytesLeg, bytesLeg);
}
InetAddress ia = null;
try {
ia = InetAddress.getByAddress(setBytes);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ia.toString().replaceFirst("/", "");
}
public void update(ByteBuffer buffer) {
try {
srcParent.update(buffer);
srcFile.update(buffer);
srcBlock.update(buffer);
dstParent.update(buffer);
dstFile.update(buffer);
dstBlock.update(buffer);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
/**
* Start client with specific network interface address.
* @param networkInterfaceAddress Network interface address to listen to.
*/
public void start(String networkInterfaceAddress)
{
try {
this.start(InetAddress.getByName(networkInterfaceAddress));
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
@Before
public void setUp() {
groupId = new Identifier<Group>(1L);
groupId2 = new Identifier<Group>(2L);
group = new Group(groupId, "the-ws-group-name");
group2 = new Group(groupId2, "the-ws-group-name-2");
try {
PowerMockito.mockStatic(JwalaUtils.class);
PowerMockito.when(JwalaUtils.getHostAddress("testServer")).thenReturn(Inet4Address.getLocalHost().getHostAddress());
PowerMockito.when(JwalaUtils.getHostAddress("testServer2")).thenReturn(Inet4Address.getLocalHost().getHostAddress());
} catch (UnknownHostException ex) {
ex.printStackTrace();
}
when(Config.mockApplication.getId()).thenReturn(new Identifier<Application>(1L));
when(Config.mockApplication.getWarPath()).thenReturn("the-ws-group-name/jwala-1.0.war");
when(Config.mockApplication.getName()).thenReturn("jwala 1.0");
when(Config.mockApplication.getGroup()).thenReturn(group);
when(Config.mockApplication.getWebAppContext()).thenReturn("/jwala");
when(Config.mockApplication.isSecure()).thenReturn(true);
when(Config.mockApplication2.getId()).thenReturn(new Identifier<Application>(2L));
when(Config.mockApplication2.getWarPath()).thenReturn("the-ws-group-name-2/jwala-1.1.war");
when(Config.mockApplication2.getName()).thenReturn("jwala 1.1");
when(Config.mockApplication2.getGroup()).thenReturn(group2);
when(Config.mockApplication2.getWebAppContext()).thenReturn("/jwala");
when(Config.mockApplication2.isSecure()).thenReturn(false);
applications2.add(Config.mockApplication);
applications2.add(Config.mockApplication2);
ByteBuffer buf = java.nio.ByteBuffer.allocate(2); // 2 byte file
buf.asShortBuffer().put((short) 0xc0de);
uploadedFile = new ByteArrayInputStream(buf.array());
SshConfiguration mockSshConfig = mock(SshConfiguration.class);
sshConfig = mock(SshConfig.class);
when(mockSshConfig.getUserName()).thenReturn("mockUser");
when(sshConfig.getSshConfiguration()).thenReturn(mockSshConfig);
}
@Before
public void setup() {
try {
hostTracker = new HostTracker(HOSTNAME, CONFIGURED_NODE_NUMBER, InetAddress.getByName(HOSTNAME));
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public void update(ByteBuffer buffer) {
try {
fileInfo.update(buffer);
int tmp = buffer.getInt();
close = (tmp == 1) ? true : false;
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public void update(ByteBuffer buffer) {
try {
blockInfo.update(buffer);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
this.spoutOutputCollector = spoutOutputCollector;
this.tid = topologyContext.getThisTaskId();
try {
this.host = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public void decode(){
//Decoding AutonomousSystemSubTLV
byte[] ip=new byte[4];
System.arraycopy(this.subtlv_bytes,4, ip, 0, 4);
try {
AS_ID=(Inet4Address)Inet4Address.getByAddress(ip);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 获取客户端IP
*
* @param request HttpServletRequest
* @return String
*/
public static String getHost(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (Strings.isNullOrEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (Strings.isNullOrEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (Strings.isNullOrEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (Strings.isNullOrEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
if ("127.0.0.1".equals(ip)) {
InetAddress inet;
try { // 根据网卡取本机配置的IP
inet = InetAddress.getLocalHost();
ip = inet.getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if (ip != null && ip.length() > 15) {
if (ip.indexOf(",") > 0) {
ip = ip.substring(0, ip.indexOf(","));
}
}
return ip;
}
private static String getLocalHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (final UnknownHostException e) {
e.printStackTrace();
return "unknown";
}
}
/**
* 获取域名 ip 地址
* <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
*
* @param domain 域名
* @return ip 地址
*/
public static String getDomainAddress(final String domain) {
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByName(domain);
return inetAddress.getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
return null;
}
}
/**
* 获取客户端的IP地址
*
* @return
*/
public String getIpAddr(HttpServletRequest request) {
String ipAddress = null;
ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) {
// 根据网卡取本机配置的IP
InetAddress inet = null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ipAddress = inet.getHostAddress();
}
}
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if (ipAddress != null && ipAddress.length() > 15) {
if (ipAddress.indexOf(",") > 0) {
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
}
}
return ipAddress;
}
/**
* クライアントをチェックする.
*
* @param headers ヘッダー
* @return 有効か否か (true: 有効, false: 無効)
*/
private boolean checkRemote(final Map<String, String> headers) {
String remoteAddr = headers.get("remote-addr");
try {
InetAddress addr = InetAddress.getByName(remoteAddr);
return addr.isSiteLocalAddress();
} catch (UnknownHostException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
return false;
}
}
static void testSerializedE1000gInet6Address() throws IOException {
System.err.println("\n testSerializedE1000gInet6Address: enter \n");
boolean testWithNetIf = true;
boolean useMockInet6Address = false;
NetworkInterface testNetIf = NetworkInterface
.getByName(NETWORK_IF_E1000G0);
Inet6Address expectedInet6Address = null;
if (testNetIf != null) {
System.err
.println("\n testSerializedE1000gInet6Address: using netif \n");
try {
expectedInet6Address = Inet6Address.getByAddress(
E1000G0HOSTNAME, E1000G0IPV6ADDRESS, testNetIf);
} catch (UnknownHostException ukhEx) {
ukhEx.printStackTrace();
testWithNetIf = true;
useMockInet6Address = true;
}
} else {
System.err
.println("\n testSerializedE1000gInet6Address: using index \n");
try {
expectedInet6Address = Inet6Address.getByAddress(
E1000G0HOSTNAME, E1000G0IPV6ADDRESS, SCOPE_ID_ZERO);
} catch (UnknownHostException ukhEx1) {
ukhEx1.printStackTrace();
useMockInet6Address = true;
}
testWithNetIf = false;
}
byte[] serializedAddress = SerialData_ifname_e1000g0;
// displayExpectedInet6Address(expectedInet6Address);
try (ByteArrayInputStream bis = new ByteArrayInputStream(
serializedAddress);
ObjectInputStream oin = new ObjectInputStream(bis)) {
Inet6Address deserializedIPV6Addr = (Inet6Address) oin.readObject();
System.err.println("Deserialized Inet6Address "
+ deserializedIPV6Addr);
if (!useMockInet6Address) {
assertHostNameEqual(expectedInet6Address.getHostName(),
deserializedIPV6Addr.getHostName());
if (testWithNetIf) {
assertHostAddressEqual(
expectedInet6Address.getHostAddress(),
deserializedIPV6Addr.getHostAddress());
} else {
assertHostAddressEqual(
MockE1000g0Inet6Address.getBareHostAddress(),
deserializedIPV6Addr.getHostAddress());
}
assertAddressEqual(expectedInet6Address.getAddress(),
deserializedIPV6Addr.getAddress());
assertScopeIdEqual(expectedInet6Address.getScopeId(),
deserializedIPV6Addr.getScopeId());
if (testWithNetIf) {
assertNetworkInterfaceEqual(
expectedInet6Address.getScopedInterface(),
deserializedIPV6Addr.getScopedInterface());
} else {
assertNetworkInterfaceEqual(null,
deserializedIPV6Addr.getScopedInterface());
}
} else { // use MockLo0Inet6Address
assertHostNameEqual(MockE1000g0Inet6Address.getHostName(),
deserializedIPV6Addr.getHostName());
if (testWithNetIf) {
assertHostAddressEqual(
MockE1000g0Inet6Address.getHostAddress(),
deserializedIPV6Addr.getHostAddress());
} else {
assertHostAddressEqual(
MockE1000g0Inet6Address.getHostAddressWithIndex(),
deserializedIPV6Addr.getHostAddress());
}
assertAddressEqual(MockE1000g0Inet6Address.getAddress(),
deserializedIPV6Addr.getAddress());
if (testWithNetIf) {
assertScopeIdEqual(MockE1000g0Inet6Address.getScopeId(),
deserializedIPV6Addr.getScopeId());
} else {
assertScopeIdEqual(MockE1000g0Inet6Address.getScopeZero(),
deserializedIPV6Addr.getScopeId());
}
assertNetworkInterfaceNameEqual(
MockE1000g0Inet6Address.getScopeIfName(),
deserializedIPV6Addr.getScopedInterface());
}
} catch (Exception e) {
System.err.println("Exception caught during deserialization");
failed = true;
e.printStackTrace();
}
}
/** {@inheritDoc} */
public Map<String, String> getCommitLogEntries( Set<String> _revs ) {
final Map<String, String> hits = new HashMap<String, String>();
if (!_revs.isEmpty() ) {
try {
Repository repository = this.getRepositoryFromPath( null );
RevWalk walk = new RevWalk( repository );
//walk.setRevFilter(RevFilter);
RevCommit commit = null;
Git git = new Git( repository );
Iterable<RevCommit> logs = git.log().call();
Iterator<RevCommit> i = logs.iterator();
String commitId = null;
String commitMsg = null;
// iterate over all commits
while ( i.hasNext() ) {
commit = walk.parseCommit( i.next() );
commitId = commit.getName();
commitMsg = commit.getFullMessage();
// iterate over all revisions to search for
for ( String sid : _revs ) {
if(sid.contains(":")){
sid= sid.substring(0,sid.indexOf(":")-1);
}
if ( !sid.equals( "" ) && sid.equals( commitId ) ) {
hits.put( commitId , commitMsg );
continue;
}
}
}
}
catch ( UnknownHostException e ) {
GitClient.log.error( "Proxy issues?" );
e.printStackTrace();
}
catch ( IOException ioe ) {
GitClient.log.error( "Something went wrong with the I/O" );
ioe.printStackTrace();
}
catch ( GitAPIException ge ) {
GitClient.log.error( "Something went wrong with the GIT API" );
ge.printStackTrace();
}
}
return hits;
}
private void fillITNodeInformation(ITNodeNLRI itNodeNLRI, String learntFrom){
/* try {
Thread.sleep(2000); //1000 milliseconds is one second.
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
*/ DomainTEDB domainTEDB= null;
domainTEDB=(DomainTEDB)intraTEDBs.get(itNodeNLRI.getNodeId());
SimpleTEDB simpleTEDB=null;
if (domainTEDB instanceof SimpleTEDB){
simpleTEDB = (SimpleTEDB) domainTEDB;
}else if (domainTEDB==null){
simpleTEDB = new SimpleTEDB();
simpleTEDB.createGraph();
try {
simpleTEDB.setDomainID((Inet4Address) InetAddress.getByName(itNodeNLRI.getNodeId()));
} catch (UnknownHostException e) {
e.printStackTrace();
}
this.intraTEDBs.put(itNodeNLRI.getNodeId(), simpleTEDB);
}
else {
log.error("PROBLEM: TEDB not compatible");
return;
}
log.info("Received IT info for domain "+itNodeNLRI.getNodeId()+" from peer "+learntFrom);
IT_Resources itResources = new IT_Resources();
itResources.setControllerIT(itNodeNLRI.getControllerIT());
itResources.setCpu(itNodeNLRI.getCpu());
itResources.setMem(itNodeNLRI.getMem());
itResources.setStorage(itNodeNLRI.getStorage());
itResources.setLearntFrom(learntFrom);
itResources.setITdomainID(itNodeNLRI.getNodeId());
simpleTEDB.setItResources(itResources);
}