List of usage examples for java.net MalformedURLException toString
public String toString()
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
private static boolean moveRemoteToRemote(NtlmPasswordAuthentication smb_auth, String fromUrl, String toUrl) { SmbFile ihf, hfd, ohf = null;//ww w .ja v a 2s . co m boolean result = false; if (!fileioThreadCtrl.isEnabled()) return false; sendDebugLogMsg(1, "I", "Move Remote to Remote from item=" + fromUrl + ", to item=" + toUrl); try { ihf = new SmbFile(fromUrl, smb_auth); if (ihf.isDirectory()) { // Directory copy result = true; hfd = new SmbFile(fromUrl + "/", smb_auth); ohf = new SmbFile(toUrl, smb_auth); String[] children = hfd.list(); for (String element : children) { if (!fileioThreadCtrl.isEnabled()) return false; boolean success = moveRemoteToRemote(smb_auth, fromUrl + "/" + element, toUrl + "/" + element); if (!success) return false; } makeRemoteDirs(smb_auth, toUrl + "/"); ihf = new SmbFile(fromUrl + "/", smb_auth); ihf.delete(); sendLogMsg("I", fromUrl + " was deleted."); } else { // file move if (!fileioThreadCtrl.isEnabled()) return false; makeRemoteDirs(smb_auth, toUrl); String f_f1 = fromUrl.replace("smb://", ""); String f_f2 = f_f1.substring(0, f_f1.indexOf("/")); f_f1.replace(f_f2 + "/", ""); String f_f3 = f_f1.substring(0, f_f1.indexOf("/")); String t_f1 = toUrl.replace("smb://", ""); String t_f2 = t_f1.substring(0, f_f1.indexOf("/")); f_f1.replace(t_f2 + "/", ""); String t_f3 = t_f1.substring(0, f_f1.indexOf("/")); //smb://1.1.1.1/share/dir if (t_f3.equals(f_f3)) { // rename?Move? ohf = new SmbFile(toUrl, smb_auth); ohf = new SmbFile(toUrl + "/", smb_auth); if (ohf.exists()) ohf.delete(); ihf.renameTo(ohf); result = ohf.exists(); } else { result = copyFileRemoteToRemote(ihf, ohf, fromUrl, toUrl, "Copying"); if (result) ihf.delete(); } if (result) sendLogMsg("I", fromUrl + " was moved to " + toUrl); else sendLogMsg("I", "Move was failed. fromUrl=" + fromUrl + ", toUrl=" + toUrl); } } catch (MalformedURLException e) { e.printStackTrace(); sendLogMsg("E", "Move error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Move error:" + e.toString()); result = false; return false; } catch (SmbException e) { e.printStackTrace(); sendLogMsg("E", "Move error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Move error:" + e.toString()); result = false; return false; } catch (IOException e) { e.printStackTrace(); sendLogMsg("E", "Move error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Move error:" + e.toString()); result = false; return false; } return result; }
From source file:com.novell.ldap.SPMLConnection.java
/** * Sets the host as the serverUrl, port is ignored * @param serverUrl The Server location and context * @param port The port (ignored)//from w ww . j a v a2 s. c om */ public void connect(String serverUrl, int port) throws LDAPException { this.serverString = serverUrl; host = serverUrl.substring(serverUrl.indexOf("//") + 2, serverUrl.indexOf("/", serverUrl.indexOf("//") + 2)); try { this.con.setUrl(serverUrl); } catch (MalformedURLException e) { throw new LDAPLocalException(e.toString(), 53, e); } this.isConnected = true; }
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
private static boolean copyLocalToLocal(String fromUrl, String toUrl) { File iLf;/*from w w w . j a v a 2 s .co m*/ boolean result = true; if (!fileioThreadCtrl.isEnabled()) return false; sendDebugLogMsg(1, "I", "Copy Local to Local from=" + fromUrl + ", to=" + toUrl); try { iLf = new File(fromUrl); // Log.v("","name="+iLf.getName()+", d="+iLf.isDirectory()+", r="+iLf.canRead()); if (iLf.isDirectory()) { // Directory copy iLf = new File(fromUrl + "/"); String[] children = iLf.list(); for (String element : children) { if (!fileioThreadCtrl.isEnabled()) return false; if (!copyLocalToLocal(fromUrl + "/" + element, toUrl + "/" + element)) return false; } makeLocalDirs(toUrl + "/"); } else { // file copy makeLocalDirs(toUrl); result = copyFileLocalToLocal(iLf, fromUrl, toUrl, "Copying"); } } catch (MalformedURLException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (FileNotFoundException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (IOException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } return result; }
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
private static boolean copyRemoteToLocal(NtlmPasswordAuthentication smb_auth, String fromUrl, String toUrl) { SmbFile hf, hfd;// ww w . ja v a2 s .c o m File lf; boolean result = false; if (!fileioThreadCtrl.isEnabled()) return false; sendDebugLogMsg(1, "I", "Copy Remote to Local from item=" + fromUrl + ", to item=" + toUrl); try { hf = new SmbFile(fromUrl, smb_auth); if (hf.isDirectory()) { // Directory copy result = true; hfd = new SmbFile(fromUrl + "/", smb_auth); String[] children = hfd.list(); for (String element : children) { if (!fileioThreadCtrl.isEnabled()) return false; result = copyRemoteToLocal(smb_auth, fromUrl + "/" + element, toUrl + "/" + element); if (!result) return false; } } else { // file copy if (hf.getAttributes() < 16384) { //no EA, copy was done makeLocalDirs(toUrl); lf = new File(toUrl); result = copyFileRemoteToLocal(hf, lf, toUrl, fromUrl, "Copying"); } else { result = false; sendLogMsg("E", "EA founded, copy canceled. path=" + fromUrl); fileioThreadCtrl.setThreadMessage("Copy error:" + "EA founded, copy canceled"); } } } catch (MalformedURLException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (SmbException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (UnknownHostException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (FileNotFoundException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (IOException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } return result; }
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
private static boolean copyLocalToRemote(NtlmPasswordAuthentication smb_auth, String fromUrl, String toUrl) { SmbFile ohf = null;/*w w w .j a v a 2 s.c om*/ File ilf, lfd; boolean result = false; if (!fileioThreadCtrl.isEnabled()) return false; sendDebugLogMsg(1, "I", "Copy Local to Remote from item=" + fromUrl + ", to item=" + toUrl); String tmp_toUrl = ""; try { ilf = new File(fromUrl); if (ilf.isDirectory()) { // Directory copy result = true; lfd = new File(fromUrl + "/"); ohf = new SmbFile(toUrl, smb_auth); String[] children = lfd.list(); for (String element : children) { if (!fileioThreadCtrl.isEnabled()) return false; result = copyLocalToRemote(smb_auth, fromUrl + "/" + element, toUrl + element + "/"); if (!result) return false; } } else { // file copy makeRemoteDirs(smb_auth, toUrl); tmp_toUrl = makeRemoteTempFilePath(toUrl); ohf = new SmbFile(tmp_toUrl, smb_auth); if (ohf.exists()) ohf.delete(); result = copyFileLocalToRemote(ohf, ilf, fromUrl, toUrl, "Copying"); if (result) { SmbFile hfd = new SmbFile(toUrl, smb_auth); if (hfd.exists()) hfd.delete(); ohf.renameTo(hfd); } } } catch (MalformedURLException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (SmbException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; if (!tmp_toUrl.equals("")) { try { if (ohf.exists()) ohf.delete(); } catch (SmbException e1) { } } return false; } catch (UnknownHostException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (FileNotFoundException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (IOException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendDebugLogMsg(1, "E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } return result; }
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
private static boolean copyRemoteToRemote(NtlmPasswordAuthentication smb_auth, String fromUrl, String toUrl) { SmbFile ihf, ohf = null;//from w w w. j a va 2s. co m boolean result = false; if (!fileioThreadCtrl.isEnabled()) return false; sendDebugLogMsg(1, "I", "copy Remote to Remote from item=" + fromUrl + ", to item=" + toUrl); String tmp_toUrl = ""; try { ihf = new SmbFile(fromUrl, smb_auth); if (ihf.isDirectory()) { // Directory copy result = true; ihf = new SmbFile(fromUrl + "/", smb_auth); ohf = new SmbFile(toUrl, smb_auth); String[] children = ihf.list(); for (String element : children) { if (!fileioThreadCtrl.isEnabled()) return false; boolean success = copyRemoteToRemote(smb_auth, fromUrl + "/" + element, toUrl + "/" + element); if (!success) return false; } makeRemoteDirs(smb_auth, toUrl + "/"); } else { // file copy makeRemoteDirs(smb_auth, toUrl); tmp_toUrl = makeRemoteTempFilePath(toUrl); ohf = new SmbFile(tmp_toUrl, smb_auth); if (ohf.exists()) ohf.delete(); result = true; if (!fileioThreadCtrl.isEnabled()) return false; if (ihf.getAttributes() < 16384) { //no EA, copy was done result = copyFileRemoteToRemote(ihf, ohf, fromUrl, toUrl, "Copying"); if (result) { SmbFile hfd = new SmbFile(toUrl, smb_auth); if (hfd.exists()) hfd.delete(); ohf.renameTo(hfd); } } else { result = false; sendLogMsg("E", "EA founded, copy canceled. path=" + fromUrl); fileioThreadCtrl.setThreadMessage("Copy error:" + "EA founded, copy canceled"); } } } catch (MalformedURLException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (SmbException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; if (!tmp_toUrl.equals("")) { try { if (ohf.exists()) ohf.delete(); } catch (SmbException e1) { } } return false; } catch (UnknownHostException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } catch (IOException e) { e.printStackTrace(); sendLogMsg("E", "Copy from=" + fromUrl + ", to=" + toUrl); sendLogMsg("E", "Copy error:" + e.toString()); fileioThreadCtrl.setThreadMessage("Copy error:" + e.toString()); result = false; return false; } return result; }
From source file:jp.ne.sakura.kkkon.java.net.inetaddress.testapp.android.NetworkConnectionCheckerTestApp.java
/** Called when the activity is first created. */ @Override//from w ww. j av a 2 s. c om public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { NetworkConnectionChecker.initialize(); } super.onCreate(savedInstanceState); /* Create a TextView and set its content. * the text is retrieved by calling a native * function. */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("reachable="); layout.addView(tv); this.textView = tv; Button btn1 = new Button(this); btn1.setText("invoke Exception"); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final int count = 2; int[] array = new int[count]; int value = array[count]; // invoke IndexOutOfBOundsException } }); layout.addView(btn1); { Button btn = new Button(this); btn.setText("disp isReachable"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final boolean isReachable = NetworkConnectionChecker.isReachable(); Toast toast = Toast.makeText(context, "IsReachable=" + isReachable, Toast.LENGTH_LONG); toast.show(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("upload http AsyncTask"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... paramss) { Boolean result = true; Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid()); try { //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); HttpPost httpPost = new HttpPost(paramss[0]); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); result = false; } Log.d(TAG, "upload finish"); return result; } }; asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug"); asyncTask.isCancelled(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(0.0.0.0)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { destHost = InetAddress.getByName("0.0.0.0"); if (null != destHost) { try { if (destHost.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + destHost.toString() + " reachable"); } else { Log.d(TAG, "destHost=" + destHost.toString() + " not reachable"); } } catch (IOException e) { } } } catch (UnknownHostException e) { } Log.d(TAG, "destHost=" + destHost); } }); thread.start(); try { thread.join(1000); } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(www.google.com)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { Log.d(TAG, "start"); try { InetAddress dest = InetAddress.getByName("www.google.com"); if (null == dest) { dest = destHost; } if (null != dest) { final String[] uris = new String[] { "http://www.google.com/", "https://www.google.com/" }; for (final String destURI : uris) { URI uri = null; try { uri = new URI(destURI); } catch (URISyntaxException e) { //Log.d( TAG, e.toString() ); } if (null != uri) { URL url = null; try { url = uri.toURL(); } catch (MalformedURLException ex) { Log.d(TAG, "got exception:" + ex.toString(), ex); } URLConnection conn = null; if (null != url) { Log.d(TAG, "openConnection before"); try { conn = url.openConnection(); if (null != conn) { conn.setConnectTimeout(3 * 1000); conn.setReadTimeout(3 * 1000); } } catch (IOException e) { //Log.d( TAG, "got Exception" + e.toString(), e ); } Log.d(TAG, "openConnection after"); if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; int responceCode = -1; try { Log.d(TAG, "getResponceCode before"); responceCode = httpConn.getResponseCode(); Log.d(TAG, "getResponceCode after"); } catch (IOException ex) { Log.d(TAG, "got exception:" + ex.toString(), ex); } Log.d(TAG, "responceCode=" + responceCode); if (0 < responceCode) { isReachable = true; destHost = dest; } Log.d(TAG, " HTTP ContentLength=" + httpConn.getContentLength()); httpConn.disconnect(); Log.d(TAG, " HTTP ContentLength=" + httpConn.getContentLength()); } } } // if uri if (isReachable) { //break; } } // for uris } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } Log.d(TAG, "end"); } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { Log.d(TAG, "start"); try { InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } Log.d(TAG, "end"); } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp) support proxy"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { String target = null; { ProxySelector proxySelector = ProxySelector.getDefault(); Log.d(TAG, "proxySelector=" + proxySelector); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { Log.d(TAG, e.toString()); } List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { Log.d(TAG, " proxy=" + proxy); if (null != proxy) { if (Proxy.Type.HTTP == proxy.type()) { final SocketAddress sa = proxy.address(); if (sa instanceof InetSocketAddress) { final InetSocketAddress isa = (InetSocketAddress) sa; target = isa.getHostName(); break; } } } } } } } if (null == target) { target = "kkkon.sakura.ne.jp"; } InetAddress dest = InetAddress.getByName(target); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); { ProxySelector proxySelector = ProxySelector.getDefault(); //Log.d( TAG, "proxySelector=" + proxySelector ); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { //Log.d( TAG, e.toString() ); } if (null != uri) { List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { //Log.d( TAG, " proxy=" + proxy ); if (null != proxy) { if (Proxy.Type.HTTP == proxy.type()) { URL url = uri.toURL(); URLConnection conn = null; if (null != url) { try { conn = url.openConnection(proxy); if (null != conn) { conn.setConnectTimeout( 3 * 1000); conn.setReadTimeout(3 * 1000); } } catch (IOException e) { Log.d(TAG, "got Exception" + e.toString(), e); } if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; if (0 < httpConn .getResponseCode()) { isReachable = true; } Log.d(TAG, " HTTP ContentLength=" + httpConn .getContentLength()); Log.d(TAG, " HTTP res=" + httpConn .getResponseCode()); //httpConn.setInstanceFollowRedirects( false ); //httpConn.setRequestMethod( "HEAD" ); //conn.connect(); httpConn.disconnect(); Log.d(TAG, " HTTP ContentLength=" + httpConn .getContentLength()); Log.d(TAG, " HTTP res=" + httpConn .getResponseCode()); } } } } } } } } } } destHost = dest; } catch (IOException e) { Log.d(TAG, "got Excpetion " + e.toString()); } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } setContentView(layout); }
From source file:net.yacy.cora.federate.opensearch.SRURSSConnector.java
/** * send a query to a yacy public search interface * @param rssSearchServiceURL the target url base (everything before the ? that follows the SRU request syntax properties). can null, then the local peer is used * @param query the query as string/*from w ww . j a va2s . co m*/ * @param startRecord number of first record * @param maximumRecords maximum number of records * @param verify if true, result entries are verified using the snippet fetch (slow); if false simply the result is returned * @param global if true also search results from other peers are included * @return */ public static RSSFeed loadSRURSS(final String rssSearchServiceURL, final String query, final int startRecord, final int maximumRecords, final CacheStrategy cacheStrategy, final boolean global, final ClientIdentification.Agent agent) throws IOException { MultiProtocolURL uri = null; try { uri = new MultiProtocolURL(rssSearchServiceURL); } catch (final MalformedURLException e) { throw new IOException( "cora.Search failed asking peer '" + rssSearchServiceURL + "': bad url, " + e.getMessage()); } // send request byte[] result = new byte[0]; try { final LinkedHashMap<String, ContentBody> parts = new LinkedHashMap<String, ContentBody>(); parts.put("query", UTF8.StringBody(query)); parts.put("startRecord", UTF8.StringBody(Integer.toString(startRecord))); parts.put("maximumRecords", UTF8.StringBody(Long.toString(maximumRecords))); parts.put("verify", cacheStrategy == null ? UTF8.StringBody("false") : UTF8.StringBody(cacheStrategy.toName())); parts.put("resource", UTF8.StringBody(global ? "global" : "local")); parts.put("nav", UTF8.StringBody("none")); // result = HTTPConnector.getConnector(userAgent == null ? MultiProtocolURI.yacybotUserAgent : userAgent).post(new MultiProtocolURI(rssSearchServiceURL), (int) timeout, uri.getHost(), parts); final HTTPClient httpClient = new HTTPClient(agent); result = httpClient.POSTbytes(new MultiProtocolURL(rssSearchServiceURL), uri.getHost(), parts, false, false); final RSSReader reader = RSSReader.parse(RSSFeed.DEFAULT_MAXSIZE, result); if (reader == null) { throw new IOException("cora.Search failed asking peer '" + uri.getHost() + "': probably bad response from remote peer (1), reader == null"); } final RSSFeed feed = reader.getFeed(); if (feed == null) { // case where the rss reader does not understand the content throw new IOException("cora.Search failed asking peer '" + uri.getHost() + "': probably bad response from remote peer (2)"); } return feed; } catch (final IOException e) { throw new IOException("cora.Search error asking peer '" + uri.getHost() + "':" + e.toString()); } }
From source file:com.sonymobile.tools.gerrit.gerritevents.workers.rest.AbstractRestCommandJob.java
@Override public void run() { ReviewInput reviewInput = createReview(); String reviewEndpoint = resolveEndpointURL(); HttpPost httpPost = createHttpPostEntity(reviewInput, reviewEndpoint); if (httpPost == null) { return;/*from w w w.j av a 2s . com*/ } DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, -1), config.getHttpCredentials()); if (config.getGerritProxy() != null && !config.getGerritProxy().isEmpty()) { try { URL url = new URL(config.getGerritProxy()); HttpHost proxy = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } catch (MalformedURLException e) { logger.error("Could not parse proxy URL, attempting without proxy.", e); if (altLogger != null) { altLogger.print("ERROR Could not parse proxy URL, attempting without proxy. " + e.getMessage()); } } } try { HttpResponse httpResponse = httpclient.execute(httpPost); String response = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"); if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { logger.error("Gerrit response: {}", httpResponse.getStatusLine().getReasonPhrase()); if (altLogger != null) { altLogger.print("ERROR Gerrit response: " + httpResponse.getStatusLine().getReasonPhrase()); } } } catch (Exception e) { logger.error("Failed to submit result to Gerrit", e); if (altLogger != null) { altLogger.print("ERROR Failed to submit result to Gerrit" + e.toString()); } } }