List of usage examples for java.net MalformedURLException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java
private void runTests() { MobileServiceClient client = null;/*from w w w. j a v a2 s.c om*/ try { client = createMobileServiceClient(); } catch (MalformedURLException e) { createAndShowDialog(e, "Error"); } // getMobileServiceRuntimeFeatures(client); final TestGroup group = (TestGroup) mTestGroupSpinner.getSelectedItem(); logWithTimestamp(new Date(), "Tests for group \'" + group.getName() + "\'"); logSeparator(); final MobileServiceClient currentClient = client; if (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 || Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // For android versions 4.0.x // Run a first Void AsyncTask on UI thread to enable the possibility // of running others on sub threads new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { return null; } }.execute(); } Thread thread = new Thread() { @Override public void run() { group.runTests(currentClient, new TestExecutionCallback() { @Override public void onTestStart(TestCase test) { final TestCaseAdapter adapter = (TestCaseAdapter) mTestCaseList.getAdapter(); runOnUiThread(new Runnable() { @Override public void run() { adapter.notifyDataSetChanged(); } }); log("TEST START", test.getName()); } @Override public void onTestGroupComplete(TestGroup group, List<TestResult> results) { log("TEST GROUP COMPLETED", group.getName() + " - " + group.getStatus().toString()); logSeparator(); if (group.getName().startsWith(TestGroup.AllTestsGroupName)) { List<TestCase> tests = new ArrayList<TestCase>(); for (TestResult result : results) { tests.add(result.getTestCase()); } DaylightLogger logger = new DaylightLogger(getDaylightURL(), getDaylightProject(), getDaylightClientId(), getDaylightClientSecret(), getDaylightRuntime(), getDaylightRunId()); try { logger.reportResultsToDaylight(group.getFailedTestCount(), group.getStartTime(), group.getEndTime(), tests, group.getSourceMap()); } catch (Throwable e) { log(e.getMessage()); } } if (shouldRunUnattended()) { // String logContent = mLog.toString(); // postLogs(logContent, true); boolean passed = true; for (TestResult result : results) { if (result.getStatus() != TestStatus.Passed) { passed = false; break; } } try { String sdCard = Environment.getExternalStorageDirectory().getPath(); FileOutputStream fos = new FileOutputStream(sdCard + "/done_android_e2e.txt"); OutputStreamWriter osw = new OutputStreamWriter(fos); BufferedWriter bw = new BufferedWriter(osw); bw.write("Completed successfully.\n"); bw.write(passed ? "PASSED" : "FAILED"); bw.write("\n"); bw.close(); osw.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } } @Override public void onTestComplete(TestCase test, TestResult result) { Throwable e = result.getException(); if (e != null) { StringBuilder sb = new StringBuilder(); while (e != null) { sb.append(e.getClass().getSimpleName() + ": "); sb.append(e.getMessage()); sb.append("\n"); sb.append(Log.getStackTraceString(e)); sb.append("\n\n"); e = e.getCause(); } test.log("Exception: " + sb.toString()); } final TestCaseAdapter adapter = (TestCaseAdapter) mTestCaseList.getAdapter(); runOnUiThread(new Runnable() { @Override public void run() { adapter.notifyDataSetChanged(); } }); logWithTimestamp(test.getStartTime(), "Logs for test " + test.getName() + " (" + result.getStatus().toString() + ")"); String testLogs = test.getLog(); if (testLogs.length() > 0) { if (testLogs.endsWith("\n")) { testLogs = testLogs.substring(0, testLogs.length() - 1); } log(testLogs); } logWithTimestamp(test.getEndTime(), "Test " + result.getStatus().toString()); logWithTimestamp(test.getEndTime(), "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-"); logSeparator(); } }); } }; thread.start(); }
From source file:org.openlaszlo.servlets.responders.ResponderDATA.java
@Override protected void respondImpl(HttpServletRequest req, HttpServletResponse res) { String path = req.getServletPath(); String url;//from ww w .ja v a 2s . co m try { url = DataSource.getURL(req); } catch (java.net.MalformedURLException e) { respondWithErrorSWF(res, "bad url: " + e.getMessage()); if (mCollectStat) { mURLStat.error(URLStat.ERRTYPE_MALFORMED_URL, "bad-url"); } return; } if (path.endsWith(".lzo")) { path = path.substring(0, path.length() - 1) + "x"; } if (req.getMethod().intern() == "POST") { float fpv = getFlashPlayerVersion(req); String ua = req.getHeader(LZHttpUtils.USER_AGENT); mLogger.debug( /* (non-Javadoc) * @i18n.test * @org-mes="POST request, flash player version: " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-328", new Object[] { new Float(fpv) })); if (fpv < 6.47 && LPS.configuration.optionAllows("disable-post-keep-alive", ua)) { // Prevent browser keep-alive to get around bug 4048. mLogger.debug( /* (non-Javadoc) * @i18n.test * @org-mes="Disabling keep-alive for " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-339", new Object[] { ua })); res.setHeader("Connection", "close"); res.setHeader("Keep-Alive", "close"); } } if (!LPS.configuration.optionAllows(path, "proxy-security-urls", url)) { String err = "Forbidden url: " + url; respondWithError(res, err, HttpServletResponse.SC_FORBIDDEN); mLogger.error(err); if (mCollectStat) { mURLStat.error(URLStat.ERRTYPE_FORBIDDEN, url); } return; } int errType = URLStat.ERRTYPE_NONE; try { DataSource source = getDataSource(req, res); if (source == null) { return; } res.setContentType(MimeType.SWF); String app = LZHttpUtils.getRealPath(mContext, req); boolean isClientCacheable = DataSource.isClientCacheable(req); if (mCache.isCacheable(req)) { if (isClientCacheable) { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", cacheable on server and client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-377", new Object[] { url })); } else { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", cacheable on server and not client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-386", new Object[] { url })); } mCache.getAsSWF(app, req, res, source); } else { if (isClientCacheable) { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", not cacheable on server and cacheable on the client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-398", new Object[] { url })); } else { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", not cacheable on server or client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-407", new Object[] { url })); } source.getAsSWF(app, req, res, getConverter()); } } catch (ConversionException e) { respondWithErrorSWF(res, /* (non-Javadoc) * @i18n.test * @org-mes="data conversion error for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-419", new Object[] { url, e.getMessage() })); errType = URLStat.ERRTYPE_CONVERSION; } catch (DataSourceException e) { respondWithErrorSWF(res, /* (non-Javadoc) * @i18n.test * @org-mes="data source error for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-428", new Object[] { url, e.getMessage() })); errType = URLStat.ERRTYPE_DATA_SOURCE; } catch (UnknownHostException e) { respondWithErrorSWF(res, /* (non-Javadoc) * @i18n.test * @org-mes="unknown host for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-437", new Object[] { url, e.getMessage() })); errType = URLStat.ERRTYPE_UNKNOWN_HOST; } catch (URIException e) { respondWithErrorSWF(res, /* (non-Javadoc) * @i18n.test * @org-mes="bad url: " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-446", new Object[] { e.getMessage() })); errType = URLStat.ERRTYPE_MALFORMED_URL; } catch (MalformedURLException e) { respondWithErrorSWF(res, /* (non-Javadoc) * @i18n.test * @org-mes="bad url: " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-446", new Object[] { e.getMessage() })); errType = URLStat.ERRTYPE_MALFORMED_URL; } catch (InterruptedIOException e) { respondWithErrorSWF(res, /* (non-Javadoc) * @i18n.test * @org-mes="backend timeout for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-466", new Object[] { url, e.getMessage() })); errType = URLStat.ERRTYPE_TIMEOUT; } catch (IOException e) { // Handle SocketTimeoutExceptions as timeouts instead of IO issues Class<?> stec = null; try { stec = Class.forName("java.net.SocketTimeoutException"); } catch (ClassNotFoundException cfne) { } if (stec != null && stec.isAssignableFrom(e.getClass())) { errType = URLStat.ERRTYPE_TIMEOUT; respondWithErrorSWF(res, /* (non-Javadoc) * @i18n.test * @org-mes="backend timeout for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-466", new Object[] { url, e.getMessage() })); } else { respondWithExceptionSWF(res, e); errType = URLStat.ERRTYPE_IO; } } catch (IllegalArgumentException e) { respondWithExceptionSWF(res, e); errType = URLStat.ERRTYPE_ILLEGAL_ARGUMENT; } catch (Throwable e) { // Makes much easier to debug runtime exceptions // but perhaps not strictly correct. respondWithExceptionSWF(res, e); errType = URLStat.ERRTYPE_OTHER; } if (mCollectStat) { if (errType == URLStat.ERRTYPE_NONE) mURLStat.success(url); else mURLStat.error(errType, url); } }
From source file:org.openlaszlo.servlets.responders.ResponderXMLDATA.java
@Override protected void respondImpl(HttpServletRequest req, HttpServletResponse res) { String path = req.getServletPath(); String url;//from www . ja va 2 s . com try { url = DataSource.getURL(req); } catch (java.net.MalformedURLException e) { respondWithError(res, "bad url: " + e.getMessage(), 0); if (mCollectStat) { mURLStat.error(URLStat.ERRTYPE_MALFORMED_URL, "bad-url"); } return; } res.setContentType("application/xml"); if (req.getMethod().intern() == "POST") { float fpv = getFlashPlayerVersion(req); String ua = req.getHeader(LZHttpUtils.USER_AGENT); mLogger.debug( /* (non-Javadoc) * @i18n.test * @org-mes="POST request, flash player version: " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-328", new Object[] { new Float(fpv) })); if (fpv < 6.47 && LPS.configuration.optionAllows("disable-post-keep-alive", ua)) { // Prevent browser keep-alive to get around bug 4048. mLogger.debug( /* (non-Javadoc) * @i18n.test * @org-mes="Disabling keep-alive for " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-339", new Object[] { ua })); res.setHeader("Connection", "close"); res.setHeader("Keep-Alive", "close"); } } if (!LPS.configuration.optionAllows(path, "proxy-security-urls", url)) { String err = "Forbidden url: " + url; respondWithError(res, err, 0); mLogger.error(err); if (mCollectStat) { mURLStat.error(URLStat.ERRTYPE_FORBIDDEN, url); } return; } int errType = URLStat.ERRTYPE_NONE; try { DataSource source = getDataSource(req, res); if (source == null) { return; } res.setContentType("application/xml"); String app = LZHttpUtils.getRealPath(mContext, req); boolean isClientCacheable = DataSource.isClientCacheable(req); if (mCache.isCacheable(req)) { if (isClientCacheable) { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", cacheable on server and client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-377", new Object[] { url })); } else { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", cacheable on server and not client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-386", new Object[] { url })); } mCache.getAsSWF(app, req, res, source); } else { if (isClientCacheable) { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", not cacheable on server and cacheable on the client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-398", new Object[] { url })); } else { mLogger.info( /* (non-Javadoc) * @i18n.test * @org-mes="proxying " + p[0] + ", not cacheable on server or client" */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-407", new Object[] { url })); } source.getAsSWF(app, req, res, getConverter()); } } catch (ConversionException e) { respondWithError(res, /* (non-Javadoc) * @i18n.test * @org-mes="data conversion error for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-419", new Object[] { url, e.getMessage() }), 0); errType = URLStat.ERRTYPE_CONVERSION; } catch (DataSourceException e) { respondWithError(res, /* (non-Javadoc) * @i18n.test * @org-mes="data source error for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-428", new Object[] { url, e.getMessage() }), 0); errType = URLStat.ERRTYPE_DATA_SOURCE; } catch (UnknownHostException e) { respondWithError(res, /* (non-Javadoc) * @i18n.test * @org-mes="unknown host for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-437", new Object[] { url, e.getMessage() }), 0); errType = URLStat.ERRTYPE_UNKNOWN_HOST; } catch (URIException e) { respondWithError(res, /* (non-Javadoc) * @i18n.test * @org-mes="bad url: " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-446", new Object[] { e.getMessage() }), 0); errType = URLStat.ERRTYPE_MALFORMED_URL; } catch (MalformedURLException e) { respondWithError(res, /* (non-Javadoc) * @i18n.test * @org-mes="bad url: " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-446", new Object[] { e.getMessage() }), 0); errType = URLStat.ERRTYPE_MALFORMED_URL; } catch (InterruptedIOException e) { respondWithError(res, /* (non-Javadoc) * @i18n.test * @org-mes="backend timeout for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-466", new Object[] { url, e.getMessage() }), 0); errType = URLStat.ERRTYPE_TIMEOUT; } catch (IOException e) { // Handle SocketTimeoutExceptions as timeouts instead of IO issues Class<?> stec = null; try { stec = Class.forName("java.net.SocketTimeoutException"); } catch (ClassNotFoundException cfne) { } if (stec != null && stec.isAssignableFrom(e.getClass())) { errType = URLStat.ERRTYPE_TIMEOUT; respondWithError(res, /* (non-Javadoc) * @i18n.test * @org-mes="backend timeout for " + p[0] + ": " + p[1] */ org.openlaszlo.i18n.LaszloMessages.getMessage(ResponderCache.class.getName(), "051018-466", new Object[] { url, e.getMessage() }), 0); } else { respondWithException(res, e); errType = URLStat.ERRTYPE_IO; } } catch (IllegalArgumentException e) { respondWithException(res, e); errType = URLStat.ERRTYPE_ILLEGAL_ARGUMENT; } catch (Throwable e) { // Makes much easier to debug runtime exceptions // but perhaps not strictly correct. respondWithException(res, e); errType = URLStat.ERRTYPE_OTHER; } if (mCollectStat) { if (errType == URLStat.ERRTYPE_NONE) mURLStat.success(url); else mURLStat.error(errType, url); } }