List of usage examples for java.lang InstantiationException getCause
public synchronized Throwable getCause()
From source file:com.networking.nemo.network.NetworkRequestManager.java
private <T, K> void runRequestsFromQueue() throws InterruptedException { Iterator<JsonNetworkRequest<?, JsonNetworkRequestError>> iter = mRequestQueue.iterator(); while (iter.hasNext() && mRunningRequests.size() < mMaxRunningRequestCount) { // Get the base request @SuppressWarnings("unchecked") final JsonNetworkRequest<T, JsonNetworkRequestError> baseRequest = (JsonNetworkRequest<T, JsonNetworkRequestError>) iter .next();/* w w w. ja v a2 s .c om*/ // Check if we can run it if (isAllowedToRun(baseRequest)) { // Now it's safe to remove from queue iter.remove(); // If there is no network available notify listener if (!mNetworkStateChecker.isNetworkConnected()) { try { JsonNetworkRequestError error = baseRequest.getClassOfFailedObject().newInstance(); error.setReason(NetworkErrorReason.NO_NETWORK); baseRequest.getListener().onNetworkRequestError(error); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } continue; } // Create response listener Listener<Object> responseListener = new Listener<Object>() { @SuppressWarnings("unchecked") @Override public void onResponse(Object response) { // Remove from running requests mRunningRequests.remove(baseRequest.getId()); NetworkRequestListener<T, K> listener = (NetworkRequestListener<T, K>) baseRequest .getListener(); // Notify listener if (listener != null) { listener.onNetworkRequestSuccess((T) response); } // Start more requests if in queue runDelayed(); } }; ErrorListener errorResponseListener = new ErrorListener() { @SuppressWarnings("unchecked") @Override public void onErrorResponse(VolleyError error) { NemoVolleyError e = (NemoVolleyError) error; JsonNetworkRequestError err = (JsonNetworkRequestError) e.getErrorObject(); // Check for JsonKeyNotFoundExpection if (e.getCause() != null && e.getCause() instanceof JsonKeyNotFoundExpection) { // Log JsonKeyNotFoundExpection ex = (JsonKeyNotFoundExpection) e.getCause(); NemoLog.error(NetworkRequestManager.class, "request url: " + baseRequest.getUrl()); NemoLog.error(NetworkRequestManager.class, "response missing field in JSON: " + ex.getMessage()); err.setReason(NetworkErrorReason.KEY_NOT_FOUND); } else if (err.getHttpStatusCode() != HttpStatus.SC_OK) { err.setReason(NetworkErrorReason.HTTP_ERROR); } // Remove from running requests mRunningRequests.remove(baseRequest.getId()); NetworkRequestListener<T, K> listener = (NetworkRequestListener<T, K>) baseRequest .getListener(); if (listener != null) { listener.onNetworkRequestError((K) err); } // Start more requests if in queue runDelayed(); } }; // Create JsonNetworkRequest Gson gson = new Gson(); String body = gson.toJson(baseRequest.getJsonBody()); VolleyRequest<T, JsonNetworkRequestError> request = new VolleyRequest<T, JsonNetworkRequestError>( (JsonNetworkRequest<T, JsonNetworkRequestError>) baseRequest, body, responseListener, errorResponseListener); request.setId(baseRequest.getId()); // Change request running mRunningRequests.put(baseRequest.getId(), baseRequest); request.run(mVolleyQueue); // Log String logMethod = ""; switch (baseRequest.getMethod()) { case Method.GET: logMethod = "GET"; break; case Method.POST: logMethod = "POST"; break; case Method.PUT: logMethod = "PUT"; break; case Method.DELETE: logMethod = "DELETE"; break; } NemoLog.debug(NetworkRequestManager.class, "run " + logMethod + ": " + baseRequest.getUrl()); if (baseRequest.getMethod() == Method.POST) { NemoLog.debug(NetworkRequestManager.class, "parameters: " + body); } } } }
From source file:hu.sztaki.lpds.pgportal.services.asm.ASMService.java
/** * Imports a workflow/application/project/graph stored in the local Repository component of gUSE * /*from ww w . ja v a 2 s .c om*/ * @param userId * - Id of the user * @param userworkflowname * - name of the workflow given by the user * @param ownerId * - Id of the owner of the workflow that should be imported * @param impWfType * - Type of the workflow (see ASMRepositoryItemType object) * @param importworkflowName * - Name of the workflow to be imported * @return String - name of the generated workflow */ public String ImportWorkflow(String userId, String userworkflowname, String ownerId, String impWfType, String importworkflowName) { try { ArrayList<RepositoryWorkflowBean> wfList = getWorkflowsFromRepository2Array(ownerId, impWfType, new Long(importworkflowName)); RepositoryWorkflowBean selectedBean = (RepositoryWorkflowBean) wfList.get(0); if (selectedBean == null) { throw new Import_NotValidWorkflowNameException(userId, importworkflowName); } String storageID = WorkflowUpDownloadUtils.getInstance().getStorageID(); String wfsID = WorkflowUpDownloadUtils.getInstance().getWfsID(); PORTAL = this.getPortalID(); selectedBean.setPortalID(PORTAL); selectedBean.setStorageID(storageID); selectedBean.setWfsID(wfsID); selectedBean.setUserID(userId); // String generated_id = Long.toString(System.currentTimeMillis()); String concrete_wf_name = userworkflowname; selectedBean.setNewGrafName("g_" + userworkflowname); selectedBean.setNewRealName(concrete_wf_name); selectedBean.setNewAbstName("t_" + userworkflowname); // //System.out.println("selBean zip path : " + selectedBean.getZipRepositoryPath()); // // import item from repository... Hashtable hsh = new Hashtable(); // hsh.put("url", bean.getWfsID()); ServiceType st = InformationBase.getI().getService("repository", "portal", hsh, new Vector()); PortalRepositoryClient repoClient = (PortalRepositoryClient) Class.forName(st.getClientObject()) .newInstance(); repoClient.setServiceURL(st.getServiceUrl()); repoClient.setServiceID(st.getServiceID()); String retStr = repoClient.importWorkflow(selectedBean); // updating ASMs in memory String importWkfID = null; Date newestDate = null; Enumeration workflow_enum = PortalCacheService.getInstance().getUser(userId).getWorkflows().keys(); while (workflow_enum.hasMoreElements()) { WorkflowData act_data = ((WorkflowData) PortalCacheService.getInstance().getUser(userId) .getWorkflows().get(workflow_enum.nextElement())); // check if id starts with correct prefix // System.out.println("ID: " + act_data.getWorkflowID()); if (act_data.getWorkflowID().startsWith(userworkflowname)) { // parse timestamp of import Date importDate = parseDate(act_data.getWorkflowID()); if (importDate != null) { // System.out.println("DATE: " + gUSE_DateFormat.format(importDate)); if (newestDate == null || importDate.after(newestDate)) { importWkfID = act_data.getWorkflowID(); // System.out.println("SETTING: " + importWkfID); newestDate = importDate; } } } } ASMWorkflow newImportedWorkflow = this.getRealASMWorkflow(userId, importWkfID); if (newImportedWorkflow == null) { throw new Import_FailedException(userId, userworkflowname); } else { putWorkflow(userId, newImportedWorkflow); updateASMWorkflowStatus(userId, importWkfID); } return importWkfID; } catch (InstantiationException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), userId, userworkflowname); } catch (IllegalAccessException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), userId, userworkflowname); } catch (Exception ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), userId, userworkflowname); } }