List of usage examples for java.lang IllegalStateException toString
public String toString()
From source file:com.vmware.identity.samlservice.impl.LogoutStateValidator.java
/** * Validate LogoutResponse/*from w w w. j av a 2 s .c o m*/ * * @param vr * @param accessor * @param response * @return */ private com.vmware.identity.samlservice.SamlValidator.ValidationResult validateLogoutResponse( com.vmware.identity.samlservice.SamlValidator.ValidationResult vr, IdmAccessor accessor, LogoutResponse response, SessionManager sm) { Validate.notNull(response.getIssuer()); // Validate single logout service first, if that is valid, we can send // SAML replies try { @SuppressWarnings("unused") String acsUrl = accessor.getSloForRelyingParty(response.getIssuer().getValue(), OasisNames.HTTP_REDIRECT); } catch (IllegalStateException e) { // set validation result to 400 log.debug("Caught illegal state exception while Validating " + e.toString() + ", returning 400"); vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), null); } // Validate ID if (vr == null && response.getID() == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Request ID is missing"); } // Validate version if (vr == null) { SAMLVersion version = response.getVersion(); if ((version.getMajorVersion() > Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() > Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too high vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_HIGH); log.debug("Validation FAILED - Version is too high"); } else if ((version.getMajorVersion() < Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() < Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too low vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_LOW); log.debug("Validation FAILED - Version is too low"); } } // Validate IssueInstant if (vr == null) { DateTime dtPlus = response.getIssueInstant(); DateTime dtMinus = response.getIssueInstant(); DateTime instant = new DateTime(); long clockTolerance = accessor.getClockTolerance(); if (dtPlus == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant is missing"); } else { dtPlus = dtPlus.plus(clockTolerance); dtMinus = dtMinus.minus(clockTolerance); // dtPlus must be after now and dtMinus must be before now // in order to satisfy clock tolerance if (dtPlus.isBefore(instant) || dtMinus.isAfter(instant)) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant outside of clock tolerance"); log.debug("clockTolerance {} ", clockTolerance); log.debug("now {}", instant); log.debug("dtPlus {}", dtPlus.toString()); log.debug("dtMinus {}", dtMinus.toString()); } } } // Destination URL skipped, this is already done by OpenSAML when // parsing // validate inResponseTo (which is the corresponding SLO request ID that // this response is targetting at) if (vr == null) { String inResponseTo = response.getInResponseTo(); if (inResponseTo == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - inResponseTo is missing"); } else { // try to find a session by LogoutRequest id that we have Session session = sm.getByLogoutRequestId(inResponseTo); if (session == null) { // No session found using the SLO request ID. This could // happen due to // fail-over (node switch). So here we ignore rather than // throw error at browser log.info( "Unable to identify a session the SLO response is referring to. This could be caused by site-affinity switch."); } } } // check response status code if (vr == null) { Status status = null; StatusCode statusCode = null; if (vr == null) { // check LogoutResponse status code here status = response.getStatus(); if (status == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - unable to find status code"); } } if (vr == null) { statusCode = status.getStatusCode(); if (statusCode == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - unable to find status code"); } } if (vr == null) { String code = statusCode.getValue(); if (!OasisNames.SUCCESS.equals(code)) { vr = new ValidationResult(OasisNames.SUCCESS, OasisNames.PARTIAL_LOGOUT); log.debug("Validation FAILED - partially logged out session"); } } } // validation done if (vr == null) { vr = new ValidationResult(); // success } return vr; }
From source file:com.gaze.webpaser.StackWidgetService.java
private void getDatafromNetwork() { new AsyncTask<String, Void, String>() { @Override/*from w ww .ja va2 s . c o m*/ protected void onPreExecute() { super.onPreExecute(); onStartDataLoading(); } @Override protected String doInBackground(String... params) { ArrayList<NameValuePair> param = new ArrayList<NameValuePair>(); try { // Set up HTTP post // HttpClient is more then less deprecated. Need to change // to // URLConnection HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(listUrl); httpPost.setEntity(new UrlEncodedFormEntity(param)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); Log.i(LOG_TAG, "finish http"); // Read content & Log inputStream = httpEntity.getContent(); } catch (UnsupportedEncodingException e1) { Log.e("UnsupportedEncodingException", e1.toString()); e1.printStackTrace(); } catch (ClientProtocolException e2) { Log.e("ClientProtocolException", e2.toString()); e2.printStackTrace(); } catch (IllegalStateException e3) { Log.e("IllegalStateException", e3.toString()); e3.printStackTrace(); } catch (IOException e4) { Log.e("IOException", e4.toString()); e4.printStackTrace(); } // Convert response to string using String Builder try { BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8); StringBuilder sBuilder = new StringBuilder(); String line = null; while ((line = bReader.readLine()) != null) { sBuilder.append(line + "\n"); } inputStream.close(); result = sBuilder.toString(); Log.i(LOG_TAG, "finish read stream: " + result); if (!isStreamTheTargetJson(result)) { result = ""; sBuilder.delete(0, sBuilder.length() - 1); } // parse json string here if (!result.isEmpty()) { if (result.startsWith("<html>")) return ""; JSONObject titleJson = new JSONObject(result); JSONArray datajson = titleJson.getJSONArray("data"); JSONArray urlQueue = datajson.getJSONArray(0); for (int i = 0; i < urlQueue.length(); i++) { JSONObject item = urlQueue.getJSONObject(i); String url = item.getString("link"); String introtext = item.getString("introtext"); String title = item.getString("title"); String images = item.getString("images"); String name = item.getString("name"); String time = item.getString("publish_up"); if (url != null) { // addToQueue(GlobalData.baseUrl+'/'+url); addToList(url, introtext, title, images, name, time); } } } } catch (Exception e) { Log.e("StringBuilding & BufferedReader", "Error converting result " + e.toString()); } return result; } @Override protected void onPostExecute(String msg) { // mDisplay.append(msg + "\n"); Log.i(LOG_TAG, msg.toString()); onFinishDataLoading(); } }.execute(); }
From source file:com.prey.net.PreyRestHttpClient.java
public StringBuilder getStringHttpResponse(HttpResponse httpResponse) throws Exception { HttpEntity httpEntity = null;/*from w w w . j a va2s. c o m*/ InputStream is = null; InputStreamReader input = null; BufferedReader reader = null; StringBuilder sb = null; try { httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); input = new InputStreamReader(is, "iso-8859-1"); reader = new BufferedReader(input, 8); sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } sb.toString().trim(); } catch (IllegalStateException e) { } catch (Exception e) { PreyLogger.e("Buffer Error, Error converting result " + e.toString(), e); } finally { try { if (is != null) is.close(); } catch (IOException e) { } try { if (reader != null) reader.close(); } catch (IOException e) { } try { if (input != null) input.close(); } catch (IOException e) { } } return sb; }
From source file:com.projeto_les.easymeal.MainActivity.java
/** * Change the current displayed fragment by a new one. * - if the fragment is in backstack, it will pop it * - if the fragment is already displayed (trying to change the fragment with the same), it will not do anything * * @param frag the new fragment to display * @param saveInBackstack if we want the fragment to be in backstack */// w w w .ja v a2s . co m public void changeFragment(Fragment frag, String tag, boolean saveInBackstack) { try { FragmentManager manager = getSupportFragmentManager(); //fragment not in back stack, create it. FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.content_layout, frag, tag); if (saveInBackstack) { Log.d(TAG, "Change Fragment: addToBackTack " + tag); transaction.addToBackStack(tag); } else { Log.d(TAG, "Change Fragment: NO addToBackTack"); } transaction.commit(); // custom effect if fragment is already instanciated } catch (IllegalStateException exception) { Log.w(TAG, "Unable to commit fragment, could be activity as been killed in background. " + exception.toString()); } }
From source file:org.polymap.core.runtime.event.EventManager.java
protected EventManager() { // always keep one listener in the list so that SessionEventDispatcher // propery counts #pendingEvents subscribe(this, new EventFilter<EventObject>() { public boolean apply(EventObject input) { return false; }/* ww w. j a va 2 s . co m*/ }); // install UICallbackPhaseListener try { // seems that a PhaseListener is installed just once for all sessions if (phaseListener == null) { phaseListener = new UICallbackPhaseListener(); RWT.getLifeCycle().addPhaseListener(phaseListener); } } catch (IllegalStateException e) { phaseListener = null; // outside request lifecycle -> no UICallback handling log.warn(e.toString()); } dispatcher.start(); }
From source file:cvut.fel.mobilevoting.murinrad.communications.Connection.java
/** * Initializes the HTTP connection/*from w w w. j a v a 2 s. c om*/ */ public void InitializeUnsecure() { try { run = false; port = server.getPort(); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 3000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); schemeRegistry = new SchemeRegistry(); Scheme http = new Scheme("http", new PlainSocketFactory(), port); schemeRegistry.register(http); HttpPost post = new HttpPost(server.getAddress()); SingleClientConnManager cm = new SingleClientConnManager(post.getParams(), schemeRegistry); connection = new DefaultHttpClient(cm, params); this.connection.addResponseInterceptor(new Interceptor(this)); notifyOfProggress(); postAndRecieve("OPTIONS", "/", null, null, true); // notifyOfProggress(false); instance = this; } catch (IllegalStateException ex) { } catch (Exception ex) { Log.e("Android mobile voting", "INIT HTTP error " + ex.toString()); showNoConError(); } }
From source file:com.vmware.identity.samlservice.impl.AuthnRequestStateValidator.java
@Override public ValidationResult validate(AuthnRequestState t) { log.debug("Validating request {}", t); ValidationResult vr = null;/*from ww w . j av a 2 s .c o m*/ try { Validate.notNull(t); HttpServletRequest httpRequest = t.getRequest(); Validate.notNull(httpRequest); AuthnRequest request = t.getAuthnRequest(); Validate.notNull(request); Validate.notNull(request.getIssuer()); IdmAccessor accessor = t.getIdmAccessor(); Validate.notNull(accessor); Validate.notNull(accessor.getTenant()); // Validate assertion consumer service first, if that is valid, we can send SAML replies try { boolean validateACSWithMetadata = !this.isRequestSigned(t); String acsUrl = accessor.getAcsForRelyingParty(request.getIssuer().getValue(), request.getAssertionConsumerServiceIndex(), request.getAssertionConsumerServiceURL(), request.getProtocolBinding(), validateACSWithMetadata); t.setAcsUrl(acsUrl); } catch (IllegalStateException e) { // set validation result to 400 log.debug("Caught illegal state exception while Validating {} returning 400", e.toString()); vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), null); } // Validate ID if (vr == null && request.getID() == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Request ID is missing"); } // Validate version if (vr == null) { SAMLVersion version = request.getVersion(); if ((version.getMajorVersion() > Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() > Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too high vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_HIGH); log.debug("Validation FAILED - Version is too high"); } else if ((version.getMajorVersion() < Shared.REQUIRED_SAML_VERSION.getMajorVersion()) || version.getMajorVersion() == Shared.REQUIRED_SAML_VERSION.getMajorVersion() && version.getMinorVersion() < Shared.REQUIRED_SAML_VERSION.getMinorVersion()) { // version too low vr = new ValidationResult(OasisNames.VERSION_MISMATCH, OasisNames.REQUEST_VERSION_TOO_LOW); log.debug("Validation FAILED - Version is too low"); } } // Validate IssueInstant only if this is a new request (i.e. it had not pass been validated) if (vr == null && !t.isExistingRequest()) { DateTime dtPlus = request.getIssueInstant(); DateTime dtMinus = request.getIssueInstant(); DateTime instant = new DateTime(); long clockTolerance = accessor.getClockTolerance(); if (dtPlus == null) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant is missing"); } else { dtPlus = dtPlus.plus(clockTolerance); dtMinus = dtMinus.minus(clockTolerance); // dtPlus must be after now and dtMinus must be before now // in order to satisfy clock tolerance if (dtPlus.isBefore(instant) || dtMinus.isAfter(instant)) { vr = new ValidationResult(OasisNames.REQUESTER); log.debug("Validation FAILED - Issue Instant outside of clock tolerance"); log.debug("clockTolerance {}", clockTolerance); log.debug("now {}", instant); log.debug("dtPlus {}", dtPlus.toString()); log.debug("dtMinus {}", dtMinus.toString()); } } } // Destination URL skipped, this is already done by OpenSAML when parsing // validate scoping if presenet if (vr == null) { vr = validateScoping(t); } // signature must NOT be included if (vr == null) { if (request.getSignature() != null) { log.debug("Validation FAILED - Signature MUST NOT be present"); vr = new ValidationResult(OasisNames.REQUESTER, OasisNames.REQUEST_UNSUPPORTED); } } // ensure that we don't accept unsigned requests if configuration requires signing if (vr == null) { try { boolean mustBeSigned = accessor .getAuthnRequestsSignedForRelyingParty(request.getIssuer().getValue()); this.validateSigning(mustBeSigned, t); } catch (IllegalStateException e) { // set validation result to request denied log.error("Validation FAILED - unsigned request detected, signing required"); vr = new ValidationResult(OasisNames.RESPONDER, OasisNames.REQUEST_DENIED); } } // validate NameIDPolicy if present if (vr == null) { NameIDPolicy policy = request.getNameIDPolicy(); if (policy != null) { String format = policy.getFormat(); if (format != null && !format.equals(OasisNames.PERSISTENT) && !format.equals(OasisNames.EMAIL_ADDRESS) && !format.equals(SAMLNames.IDFORMAT_VAL_UPN.toString())) { log.error("Validation FAILED - unknown NameIDPolicy Format"); vr = new ValidationResult(OasisNames.REQUESTER, OasisNames.INVALID_NAMEID_POLICY); } } } // validate conditions if (vr == null) { Conditions conditions = request.getConditions(); if (conditions != null) { // notBefore processing DateTime notBefore = conditions.getNotBefore(); if (notBefore != null) { // no additional validation, we'll use whatever client wants t.setStartTime(notBefore.toDate()); } // delegable and renewable conditions for (Condition c : conditions.getConditions()) { if (c == null) { continue; } if (c instanceof RenewableType) { t.setRenewable(true); } if (c instanceof DelegableType) { t.setDelegable(true); } } } } if (vr == null) { computeSupportedAuthnTypes(t, request); } // validation done if (vr == null) { log.info("Authentication request validation succeeded"); vr = new ValidationResult(); // success // check if we need to convert a principal into emailAddress if (request.getNameIDPolicy() != null && request.getNameIDPolicy().getFormat() != null && request.getNameIDPolicy().getFormat().equals(OasisNames.EMAIL_ADDRESS)) { t.setIdentityFormat(OasisNames.IDENTITY_FORMAT_EMAIL_ADDRESS); } else { t.setIdentityFormat(OasisNames.IDENTITY_FORMAT_UPN); } } } catch (Exception e) { vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST, "BadRequest", null); log.debug("Caught exception while Validating " + e.toString() + ", returning 400"); } return vr; }
From source file:org.apache.brooklyn.entity.brooklynnode.BrooklynNodeIntegrationTest.java
@Test(groups = "Integration") public void testStopPlainThrowsException() throws Exception { BrooklynNode brooklynNode = setUpBrooklynNodeWithApp(); // Not using annotation with `expectedExceptions = PropagatedRuntimeException.class` because want to // ensure exception comes from stop. On jenkins, was seeing setUpBrooklynNodeWithApp fail in // testStopAndKillAppsEffector; so can't tell if this method was really passing! try {/*from w w w.ja v a2 s . co m*/ brooklynNode.stop(); fail("Expected " + brooklynNode + " stop to fail, because has app"); } catch (Exception e) { IllegalStateException ise = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class); if (ise != null && ise.toString().contains("Can't stop instance with running applications")) { // success } else { throw e; } } finally { try { brooklynNode .invoke(BrooklynNode.STOP_NODE_AND_KILL_APPS, ImmutableMap .of(StopNodeAndKillAppsEffector.TIMEOUT.getName(), Duration.THIRTY_SECONDS)) .getUnchecked(); } catch (Exception e) { log.warn("Error in stopNodeAndKillApps for " + brooklynNode + " (continuing)", e); } } }
From source file:org.chromium.media.MediaDrmBridge.java
/** * Add a key for a session Id./*from w w w .j a v a2s.c om*/ * * @param sessionId Crypto session Id. * @param key Response data from the server. */ @CalledByNative private void addKey(String sessionId, byte[] key) { if (mSessionId == null || !mSessionId.equals(sessionId)) { return; } try { final byte[] session = sessionId.getBytes("UTF-8"); try { mMediaDrm.provideKeyResponse(session, key); } catch (java.lang.IllegalStateException e) { // This is not really an exception. Some error code are incorrectly // reported as an exception. // TODO(qinmin): remove this exception catch when b/10495563 is fixed. Log.e(TAG, "Exception intentionally caught when calling provideKeyResponse() " + e.toString()); } mHandler.post(new Runnable() { public void run() { nativeOnKeyAdded(mNativeMediaDrmBridge, mSessionId); } }); return; } catch (android.media.NotProvisionedException e) { Log.e(TAG, "failed to provide key response: " + e.toString()); } catch (android.media.DeniedByServerException e) { Log.e(TAG, "failed to provide key response: " + e.toString()); } catch (java.io.UnsupportedEncodingException e) { Log.e(TAG, "failed to provide key response: " + e.toString()); } onKeyError(); }
From source file:org.ireland.jnetty.webapp.ErrorPageManager.java
/** * Sends an HTTP error to the browser./*from w w w . jav a 2s . co m*/ * * @param code * the HTTP error code * @param message * a string message */ public void sendErrorImpl(CauchoRequest request, CauchoResponse response, int code, String message) throws IOException { response.resetBuffer(); /* XXX: if we've already got an error, won't this just mask it? if (responseStream.isCommitted()) throw new IllegalStateException("response can't sendError() after commit"); */ response.setStatus(code, message); try { if (handleErrorStatus(request, response, code, message) || code == HttpServletResponse.SC_NOT_MODIFIED) { return; } response.setContentType("text/html; charset=utf-8"); boolean isOutputStreamWrapper = false; PrintWriter out; try { out = response.getWriter(); } catch (IllegalStateException e) { log.debug(e.toString(), e); out = Vfs.openWrite(response.getOutputStream()).getPrintWriter(); isOutputStreamWrapper = true; } out.println("<html>"); if (!response.isCommitted()) { out.print("<head><title>"); out.print(code); out.print(" "); out.print(escapeHtml(message)); out.println("</title></head>"); } out.println("<body>"); out.print("<h1>"); out.print(code); out.print(" "); out.print(escapeHtml(message)); out.println("</h1>"); if (code == HttpServletResponse.SC_NOT_FOUND) { out.println(escapeHtml(request.getPageURI()) + " was not found on this server."); } printVersion(out); out.println("</body></html>"); String userAgent = request.getHeader("User-Agent"); if (userAgent != null && userAgent.indexOf("MSIE") >= 0) { out.write(MSIE_PADDING, 0, MSIE_PADDING.length); } if (isOutputStreamWrapper) { out.flush(); out.close(); } } catch (Exception e) { log.warn(e.toString(), e); } }