List of usage examples for java.lang IllegalStateException printStackTrace
public void printStackTrace()
From source file:ca.ualberta.cmput301f13t13.storyhoard.serverClasses.ESUpdates.java
/** * Inserts a story object into the server. The story must be a complete * story, in other words, have all its chapters, choices, and media. It is * all stored as one story, not individual components like in the database. * </br> The story is inserted using HttpPost, not HttpGet. * // ww w. ja va 2 s. c o m * @param story * The complete story to post to server. It is first converted to * a Json string, and then is posted onto the server. */ protected void insertStory(Story story, String server) { HttpPost httpPost = new HttpPost(server + story.getId().toString()); StringEntity stringentity = null; try { stringentity = new StringEntity(gson.toJson(story)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } httpPost.setHeader("Accept", "application/json"); httpPost.setEntity(stringentity); HttpResponse response = null; try { response = httpclient.execute(httpPost); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String status = response.getStatusLine().toString(); System.out.println(status); HttpEntity entity = response.getEntity(); InputStreamReader is = null; try { is = new InputStreamReader(entity.getContent()); } catch (IllegalStateException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } BufferedReader br = new BufferedReader(is); String output; System.err.println("Output from ESUpdates -> "); try { while ((output = br.readLine()) != null) { System.err.println(output); } entity.consumeContent(); is.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.privatenotes.sync.web.WebConnection.java
protected String parseResponse(HttpResponse response) { if (response == null) return ""; String result = null;//from www. j av a2s .co m // Examine the response status if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Response status : " + response.getStatusLine().toString()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { try { InputStream instream; instream = entity.getContent(); result = convertStreamToString(instream); if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Received : " + result); // Closing the input stream will trigger connection release instream.close(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
From source file:org.changhong.sync.web.WebConnection.java
protected String parseResponse(HttpResponse response) { if (response == null) return ""; String result = null;/* w ww. j av a2 s . com*/ // Examine the response status TLog.i(TAG, "Response status : {0}", response.getStatusLine().toString()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { try { InputStream instream; instream = entity.getContent(); result = convertStreamToString(instream); TLog.i(TAG, "Received : {0}", result); // Closing the input stream will trigger connection release instream.close(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
From source file:it.geosolutions.tools.io.CopyTreeTest.java
@Test public void stopCopyTest() throws Exception { LOGGER.info("BEGIN: stopCopyTest"); File srcMount = TestData.file(this, "."); final CopyTree act = new CopyTree( FileFilterUtils.or(FileFilterUtils.directoryFileFilter(), FileFilterUtils.fileFileFilter()), cs, srcMount, destMount);//w w w. j a va 2 s .c om final Thread copier = new Thread(new Runnable() { public void run() { act.setCancelled(); try { Assert.assertEquals("Returned list should be null", 0, act.copy()); } catch (IllegalStateException e) { e.printStackTrace(); Assert.fail(e.getLocalizedMessage()); } catch (IOException e) { e.printStackTrace(); Assert.fail(e.getLocalizedMessage()); } } }); copier.start(); try { copier.join(); } catch (InterruptedException e) { LOGGER.info(e.getLocalizedMessage(), e); Assert.fail(); } LOGGER.info("STOP: stopCopyTest"); }
From source file:com.sharky.RemovePurchaseFromQueuePurchase.java
@Override public FREObject call(FREContext arg0, FREObject[] arg1) { String receipt = null;//from w w w . java2 s . c o m try { receipt = arg1[1].getAsString(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (FRETypeMismatchException e) { e.printStackTrace(); } catch (FREInvalidObjectException e) { e.printStackTrace(); } catch (FREWrongThreadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (receipt == null) { return null; } JSONObject object = null; try { object = new JSONObject(receipt); } catch (JSONException e) { e.printStackTrace(); } if (object == null) { return null; } String signedData = null; try { signedData = object.getString("signedData"); } catch (JSONException e) { e.printStackTrace(); } if (signedData == null) { return null; } JSONObject signedObject = null; try { signedObject = new JSONObject(signedData); } catch (JSONException e) { e.printStackTrace(); } if (signedObject == null) { return null; } Long nonce = 0L; try { nonce = signedObject.getLong("nonce"); } catch (JSONException e) { e.printStackTrace(); } JSONArray orders = null; try { orders = signedObject.getJSONArray("orders"); } catch (JSONException e) { e.printStackTrace(); } String[] notifyIds = new String[orders.length()]; for (int i = 0; i < orders.length(); i++) { JSONObject order = null; try { order = orders.getJSONObject(i); } catch (JSONException e) { e.printStackTrace(); } if (order == null) { continue; } try { notifyIds[i] = order.getString("notificationId"); } catch (JSONException e) { e.printStackTrace(); } } Intent intent = new Intent(Consts.ACTION_CONFIRM_NOTIFICATION); intent.setClass(arg0.getActivity(), BillingService.class); intent.putExtra(Consts.NOTIFICATION_ID, notifyIds); arg0.getActivity().startService(intent); Security.removeNonce(nonce); return null; }
From source file:com.nextgis.maplibui.util.NGWCreateNewResourceTask.java
@Override protected String doInBackground(Void... voids) { if (mConnection.connect()) { mVer = null;/*ww w. j a v a 2s . c o m*/ try { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mConnection.getName()); if (null == accountData.url) return "404"; mVer = NGWUtil.getNgwVersion(accountData.url, accountData.login, accountData.password); } catch (IllegalStateException e) { return "401"; } catch (JSONException | IOException | NumberFormatException e) { e.printStackTrace(); } if (mLayer != null) return NGWUtil.createNewLayer(mConnection, mLayer, mParentId); else return NGWUtil.createNewGroup(mContext, mConnection, mParentId, mName); } return "0"; }
From source file:com.oneteam.framework.android.net.AbstractHttpConnection.java
protected void connect(HttpRequestBase httpMethod) { DefaultHttpClient httpClient = new DefaultHttpClient(); try {// w w w . ja v a2 s . c o m mHttpResponse = httpClient.execute(httpMethod); } catch (IllegalStateException e) { Logger.w("Invalid url, Error > " + e.getMessage()); e.printStackTrace(); } catch (ClientProtocolException e) { Logger.w("HTTP Protocol Error > " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { Logger.w("IO Error > " + e.getMessage()); e.printStackTrace(); } }
From source file:com.micro.rent.common.comm.aio.AsyncClientHttpExchangeFutureCallback.java
public void httpAsync() throws Exception { RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectTimeout(3000).build(); final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig) .build();// ww w . j a v a 2 s . co m try { httpclient.start(); final HttpGet[] requests = new HttpGet[list.size()]; for (int i = 0; i < list.size(); i++) { BigDecimal lat = list.get(i).getLatitude(); BigDecimal lon = list.get(i).getLongitude(); RequestParam reqParam = new RequestParam(); reqParam.setDestination(lat.toString().concat(",").concat(lon.toString())); reqParam.setOrigin(String.valueOf(wpLat).concat(",").concat(String.valueOf(wpLon))); reqParam.setMode(queryVo.getTrafficType()); switch (ETranfficType.getSelfByCode(queryVo.getTrafficType())) { case DRIVING: reqParam.setOrigin_region(queryVo.getCityName()); reqParam.setDestination_region(queryVo.getCityName()); break; case TRANSIT: case WALKING: reqParam.setRegion(queryVo.getCityName()); break; default: break; } requests[i] = new HttpGet(timeUrl(reqParam)); } long start = System.currentTimeMillis(); final CountDownLatch latch = new CountDownLatch(requests.length); for (int j = 0; j < requests.length; j++) { final HttpGet request = requests[j]; final int k = j; httpclient.execute(request, new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { latch.countDown(); try { InputStream a = response.getEntity().getContent(); String responseString = readInputStream(a); String duration = duration(responseString); list.get(k).setDuration(duration); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void failed(final Exception ex) { latch.countDown(); } public void cancelled() { latch.countDown(); } }); } latch.await(); log.info(System.currentTimeMillis() - start + "-----------------ms----"); } finally { httpclient.close(); } }
From source file:edu.pdx.cecs.orcycle.UserFeedbackUploader.java
boolean uploadUserInfoV4() { boolean result = false; final String postUrl = mCtx.getResources().getString(R.string.post_url); try {//from w ww .j a v a 2 s .c o m URL url = new URL(postUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); // Allow Inputs conn.setDoOutput(true); // Allow Outputs conn.setUseCaches(false); // Don't use a Cached Copy conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("ENCTYPE", "multipart/form-data"); conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); conn.setRequestProperty("Cycleatl-Protocol-Version", "4"); DataOutputStream dos = new DataOutputStream(conn.getOutputStream()); JSONObject jsonUser; if (null != (jsonUser = getUserJSON())) { try { String deviceId = userId; dos.writeBytes(fieldSep + ContentField("user") + jsonUser.toString() + "\r\n"); dos.writeBytes( fieldSep + ContentField("version") + String.valueOf(kSaveProtocolVersion4) + "\r\n"); dos.writeBytes(fieldSep + ContentField("device") + deviceId + "\r\n"); dos.writeBytes(fieldSep); dos.flush(); } catch (Exception ex) { Log.e(MODULE_TAG, ex.getMessage()); return false; } finally { dos.close(); } int serverResponseCode = conn.getResponseCode(); String serverResponseMessage = conn.getResponseMessage(); // JSONObject responseData = new JSONObject(serverResponseMessage); Log.v("Jason", "HTTP Response is : " + serverResponseMessage + ": " + serverResponseCode); if (serverResponseCode == 201 || serverResponseCode == 202) { // TODO: Record somehow that data was uploaded successfully result = true; } } else { result = false; } } catch (IllegalStateException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } catch (JSONException e) { e.printStackTrace(); return false; } return result; }
From source file:com.TwentyCodes.android.IOIOTruck.MapFragment.java
/** * Called when a point is selected on the map * (non-Javadoc)// www. ja v a 2s . c o m * @see com.TwentyCodes.android.location.LocationSelectedListener#onLocationSelected(com.google.android.maps.GeoPoint) */ @Override public void onLocationSelected(final GeoPoint point) { if (mDirectionsCompleteListener != null) new Thread(new Runnable() { @Override public void run() { try { new DirectionsOverlay(getMap(), getUserLocation(), point, MapFragment.this); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); removePath(); setDestination(point); if (mLocationSelectedListener != null) mLocationSelectedListener.onLocationSelected(point); if (point != null) { if (Debug.DEBUG) Log.d(TAG, "onLocationSelected() " + point.toString()); if (this.mRadiusOverlay != null) this.mRadiusOverlay.setLocation(point); } else if (Debug.DEBUG) Log.d(TAG, "onLocationSelected() Location was null"); }