List of usage examples for java.lang ArrayIndexOutOfBoundsException printStackTrace
public void printStackTrace()
From source file:es.itecban.deployment.executionmanager.gui.swf.service.UpdatePlanCreationManager.java
public boolean map(RequestContext context, DeploymentGroup[] groups, String[] containers, String planNameUniq) throws Exception { Calendar map1 = Calendar.getInstance(); String lock = "map_lock"; boolean ok = false; synchronized (lock) { String environmentName = (String) context.getFlowScope().get(Constants.FLOW_SELECTED_ENV); DeploymentTargetType environment = this.envManager.getEnvironment(environmentName); DependencyGraph graph = this.common.getDependencyGraph(context, environment.getName()); PlanContextBrowser browser = new PlanContextBrowser(environment, graph); logger.fine("Starting Mapping"); String stActionsToDo = context.getRequestParameters().get("actionsToDo"); if (stActionsToDo == null || stActionsToDo.equals("")) { ErrorUtils.createMessageError(context, "running.error.noSelectedContainer", null); throw new Exception(); }//from w ww. j ava2s.co m // Check if the selected unit to operate with has been assigned to a container DeploymentGroup dgOfTargetUnitSelected = groups[groups.length - 1]; String selectedUnitName = (String) context.getFlowScope().get(Constants.FLOW_SELECTED_UNIT_NAME); String selectedUnitVersion = (String) context.getFlowScope().get(Constants.FLOW_SELECTED_UNIT_VERSION); if (dgOfTargetUnitSelected.getUnits().size() > 1) throw new Exception( "The updating of a unit in a group with more than one unit is not implemented yet"); if (!(dgOfTargetUnitSelected.getUnits().get(0).getName().equals(selectedUnitName) && dgOfTargetUnitSelected.getUnits().get(0).getVersion().equals(selectedUnitVersion))) { ErrorUtils.createMessageError(context, "running.error.principalUnitNoAssigned", null); throw new Exception(); } if (stActionsToDo == null || stActionsToDo.equals("")) { ErrorUtils.createMessageError(context, "running.error.noSelectedContainer", null); throw new Exception(); } // check if they are less because come of the units are already // installed String[] actionsToDoArray = stActionsToDo.split(","); List<InstalledUnit> installedUnitList = (List<InstalledUnit>) context.getFlowScope() .get(Constants.FLOW_INSTALLED_UNITS); int numberOfAssignedUnits = 0; // look for the non assigned groups // get the unique groups of assignment Set<String> uniqueGroups = new HashSet<String>(); for (String action : actionsToDoArray) { String assignedGroup = action.substring(0, action.indexOf('|')); uniqueGroups.add(assignedGroup); } // if any of the group has not been assigned check if it is already // installed in the environment String[] uniqueGroupsArray = uniqueGroups.toArray(new String[uniqueGroups.size()]); Arrays.sort(uniqueGroupsArray); if (uniqueGroups.size() < groups.length) { for (int i = 0, k = 0; i < groups.length; i++) { boolean notAssigned = false; int groupNumber = -1; try { groupNumber = Integer.parseInt(uniqueGroupsArray[k]); } catch (ArrayIndexOutOfBoundsException e) { notAssigned = true; } if (notAssigned || groupNumber != i) { // group number not assigned, necessary to check if this // group is already installed DeploymentGroup groupNotAssigned = groups[i]; List<DeploymentUnit> unitList = groupNotAssigned.getUnits(); for (DeploymentUnit unit : unitList) { String unitName = unit.getName(); String unitVersion = unit.getVersion(); // check against the installed units for (InstalledUnit installedUnit : installedUnitList) { if (installedUnit.getUnitName().equals(unitName) && installedUnit.getUnitVersion().equals(unitVersion)) { // the unit is installed, it is not necessary to // install it again numberOfAssignedUnits++; break; } } } } if (groupNumber == i) k = k + 1; } } if (uniqueGroupsArray.length + numberOfAssignedUnits < groups.length) { ErrorUtils.createMessageError(context, "running.error.noSelectedAllContainer", null); throw new Exception(); } // TODO TODO TODO TODO TODO necessary to check if there is going to be // updated more than one // version of a unit String[] aActionsToDo = stActionsToDo.split(","); // FIXME para que es esto del if? if (context.getFlowScope().get(Constants.FLOW_CONTAINER_GRAPH) != null) context.getFlowScope().put(Constants.FLOW_CONTAINER_GRAPH, null); for (int i = 0; i < aActionsToDo.length; i++) { String[] actioni = aActionsToDo[i].split("\\|"); int g = Integer.parseInt(actioni[0]); DeploymentGroup group = groups[g]; String containeri = actioni[1]; if (group.equals(dgOfTargetUnitSelected)) { try { // TODO We suppose that there is only a unit version // at a time but we are not restricting it programmatically HttpServletRequest request = (HttpServletRequest) context.getExternalContext() .getNativeRequest(); // FIXME considera unicamente una version, como si no // pudiera haber mas String containerList = (String) context.getFlowScope().get(Constants.FLOW_CONTAINER_GRAPH); String containerGraphList = ""; if (containerList == null || containerList.equals("")) containerGraphList = containeri; else containerGraphList = containerList + "|" + containeri; String previousVersion = this.common.getPreviousUnitVersion(containeri, installedUnitList); String xmlDependencyGraph = this.common.getXMLDependencyGraphURL(request, selectedUnitName, previousVersion, environmentName, containerGraphList); context.getFlowScope().put("name", selectedUnitName); context.getFlowScope().put("version", previousVersion); context.getFlowScope().put("environment", environmentName); context.getFlowScope().put("xmlDependencyGraph", xmlDependencyGraph); // add the nodes to be updated so the graph of all of them // will be shown context.getFlowScope().put(Constants.FLOW_CONTAINER_GRAPH, containerGraphList); Map<DeploymentGroup, String> groupsToContainer = this.common.assignGroupToContainer(group, containeri, false, context, browser); context.getFlowScope().put(Constants.FLOW_GROUPS_TO_CONTAINER, groupsToContainer); } catch (Exception e) { e.printStackTrace(); return false; } } else { // These operations are of installation Map<DeploymentGroup, String> groupsToContainer = this.common .assignGroupToContainerForInstall(group, containeri, false, context, browser); context.getFlowScope().put(Constants.FLOW_GROUPS_TO_CONTAINER_FOR_INSTALL, groupsToContainer); } } logger.fine("Mapped everything OK"); Calendar map2 = Calendar.getInstance(); Utils.getTimeOfExecution(map1, map2, "Time of executing map: "); ok = this.common.validatePlan(context, environment, graph); } lock = null; return ok; }
From source file:com.lgallardo.qbittorrentclient.JSONParser.java
public String postCommand(String command, String hash) throws JSONParserStatusCodeException { String key = "hash"; String urlContentType = "application/x-www-form-urlencoded"; String limit = ""; String tracker = ""; String boundary = null;// www. j a va2 s . c o m String fileId = ""; String filePriority = ""; String result = ""; StringBuilder fileContent = null; HttpResponse httpResponse; DefaultHttpClient httpclient; String url = ""; String label = ""; if ("start".equals(command) || "startSelected".equals(command)) { url = "command/resume"; } if ("pause".equals(command) || "pauseSelected".equals(command)) { url = "command/pause"; } if ("delete".equals(command) || "deleteSelected".equals(command)) { url = "command/delete"; key = "hashes"; } if ("deleteDrive".equals(command) || "deleteDriveSelected".equals(command)) { url = "command/deletePerm"; key = "hashes"; } if ("addTorrent".equals(command)) { url = "command/download"; key = "urls"; } if ("addTracker".equals(command)) { url = "command/addTrackers"; key = "hash"; } if ("addTorrentFile".equals(command)) { url = "command/upload"; key = "urls"; boundary = "-----------------------" + (new Date()).getTime(); urlContentType = "multipart/form-data; boundary=" + boundary; } if ("pauseall".equals(command)) { url = "command/pauseall"; } if ("pauseAll".equals(command)) { url = "command/pauseAll"; } if ("resumeall".equals(command)) { url = "command/resumeall"; } if ("resumeAll".equals(command)) { url = "command/resumeAll"; } if ("increasePrio".equals(command)) { url = "command/increasePrio"; key = "hashes"; } if ("decreasePrio".equals(command)) { url = "command/decreasePrio"; key = "hashes"; } if ("maxPrio".equals(command)) { url = "command/topPrio"; key = "hashes"; } if ("minPrio".equals(command)) { url = "command/bottomPrio"; key = "hashes"; } if ("setFilePrio".equals(command)) { url = "command/setFilePrio"; String[] tmpString = hash.split("&"); hash = tmpString[0]; fileId = tmpString[1]; filePriority = tmpString[2]; // Log.d("Debug", "hash: " + hash); // Log.d("Debug", "fileId: " + fileId); // Log.d("Debug", "filePriority: " + filePriority); } if ("setQBittorrentPrefefrences".equals(command)) { url = "command/setPreferences"; key = "json"; } if ("setUploadRateLimit".equals(command)) { url = "command/setTorrentsUpLimit"; key = "hashes"; String[] tmpString = hash.split("&"); hash = tmpString[0]; try { limit = tmpString[1]; } catch (ArrayIndexOutOfBoundsException e) { limit = "-1"; } } if ("setDownloadRateLimit".equals(command)) { url = "command/setTorrentsDlLimit"; key = "hashes"; Log.d("Debug", "Hash before: " + hash); String[] tmpString = hash.split("&"); hash = tmpString[0]; try { limit = tmpString[1]; } catch (ArrayIndexOutOfBoundsException e) { limit = "-1"; } // Log.d("Debug", "url: " + url); // Log.d("Debug", "Hashes: " + hash + " | limit: " + limit); } if ("recheckSelected".equals(command)) { url = "command/recheck"; } if ("toggleFirstLastPiecePrio".equals(command)) { url = "command/toggleFirstLastPiecePrio"; key = "hashes"; } if ("toggleSequentialDownload".equals(command)) { url = "command/toggleSequentialDownload"; key = "hashes"; } if ("toggleAlternativeSpeedLimits".equals(command)) { // Log.d("Debug", "Toggling alternative rates"); url = "command/toggleAlternativeSpeedLimits"; key = "hashes"; } if ("setLabel".equals(command)) { url = "command/setLabel"; key = "hashes"; String[] tmpString = hash.split("&"); hash = tmpString[0]; try { label = tmpString[1]; } catch (ArrayIndexOutOfBoundsException e) { label = ""; } // Log.d("Debug", "Hash2: " + hash + "| label2: " + label); } if ("setCategory".equals(command)) { url = "command/setCategory"; key = "hashes"; String[] tmpString = hash.split("&"); hash = tmpString[0]; try { label = tmpString[1]; } catch (ArrayIndexOutOfBoundsException e) { label = ""; } // Log.d("Debug", "Hash2: " + hash + "| label2: " + label); } if ("alternativeSpeedLimitsEnabled".equals(command)) { // Log.d("Debug", "Getting alternativeSpeedLimitsEnabled"); url = "command/alternativeSpeedLimitsEnabled"; key = "hashes"; } // if server is publish in a subfolder, fix url if (subfolder != null && !subfolder.equals("")) { url = subfolder + "/" + url; } HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. // The default value is zero, that means the timeout is not used. int timeoutConnection = connection_timeout * 1000; // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = data_timeout * 1000; // Set http parameters HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpProtocolParams.setUserAgent(httpParameters, "qBittorrent for Android"); HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8); // Making HTTP request HttpHost targetHost = new HttpHost(this.hostname, this.port, this.protocol); // httpclient = new DefaultHttpClient(); httpclient = getNewHttpClient(); httpclient.setParams(httpParameters); try { AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password); httpclient.getCredentialsProvider().setCredentials(authScope, credentials); url = protocol + "://" + hostname + ":" + port + "/" + url; HttpPost httpget = new HttpPost(url); if ("addTorrent".equals(command)) { URI hash_uri = new URI(hash); hash = hash_uri.toString(); } if ("addTracker".equals(command)) { String[] tmpString = hash.split("&"); hash = tmpString[0]; URI hash_uri = new URI(hash); hash = hash_uri.toString(); try { tracker = tmpString[1]; } catch (ArrayIndexOutOfBoundsException e) { tracker = ""; } // Log.d("Debug", "addTracker - hash: " + hash); // Log.d("Debug", "addTracker - tracker: " + tracker); } // In order to pass the hash we must set the pair name value BasicNameValuePair bnvp = new BasicNameValuePair(key, hash); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(bnvp); // Add limit if (!limit.equals("")) { Log.d("Debug", "JSONParser - Limit: " + limit); nvps.add(new BasicNameValuePair("limit", limit)); } // Set values for setting file priority if ("setFilePrio".equals(command)) { nvps.add(new BasicNameValuePair("id", fileId)); nvps.add(new BasicNameValuePair("priority", filePriority)); } // Add label if (label != null && !label.equals("")) { label = Uri.decode(label); if ("setLabel".equals(command)) { nvps.add(new BasicNameValuePair("label", label)); } else { nvps.add(new BasicNameValuePair("category", label)); } // Log.d("Debug", "Hash3: " + hash + "| label3: >" + label + "<"); } // Add tracker if (tracker != null && !tracker.equals("")) { nvps.add(new BasicNameValuePair("urls", tracker)); // Log.d("Debug", ">Tracker: " + key + " | " + hash + " | " + tracker + "<"); } String entityValue = URLEncodedUtils.format(nvps, HTTP.UTF_8); // This replaces encoded char "+" for "%20" so spaces can be passed as parameter entityValue = entityValue.replaceAll("\\+", "%20"); StringEntity stringEntity = new StringEntity(entityValue, HTTP.UTF_8); stringEntity.setContentType(URLEncodedUtils.CONTENT_TYPE); httpget.setEntity(stringEntity); // Set content type and urls if ("addTorrent".equals(command) || "increasePrio".equals(command) || "decreasePrio".equals(command) || "maxPrio".equals(command) || "setFilePrio".equals(command) || "toggleAlternativeSpeedLimits".equals(command) || "alternativeSpeedLimitsEnabled".equals(command) || "setLabel".equals(command) || "setCategory".equals(command) || "addTracker".equals(command)) { httpget.setHeader("Content-Type", urlContentType); } // Set cookie if (this.cookie != null) { httpget.setHeader("Cookie", this.cookie); } // Set content type and urls if ("addTorrentFile".equals(command)) { httpget.setHeader("Content-Type", urlContentType); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); // Add boundary builder.setBoundary(boundary); // Add torrent file as binary File file = new File(hash); // FileBody fileBody = new FileBody(file); // builder.addPart("file", fileBody); builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, hash); // Build entity HttpEntity entity = builder.build(); // Set entity to http post httpget.setEntity(entity); } httpResponse = httpclient.execute(targetHost, httpget); StatusLine statusLine = httpResponse.getStatusLine(); int mStatusCode = statusLine.getStatusCode(); // Log.d("Debug", "JSONPArser - mStatusCode: " + mStatusCode); if (mStatusCode != 200) { httpclient.getConnectionManager().shutdown(); throw new JSONParserStatusCodeException(mStatusCode); } HttpEntity httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity); // Log.d("Debug", "JSONPArser - command result: " + result); return result; } catch (UnsupportedEncodingException e) { } catch (ClientProtocolException e) { Log.e("Debug", "Client: " + e.toString()); e.printStackTrace(); } catch (SSLPeerUnverifiedException e) { Log.e("JSON", "SSLPeerUnverifiedException: " + e.toString()); throw new JSONParserStatusCodeException(NO_PEER_CERTIFICATE); } catch (IOException e) { Log.e("Debug", "IO: " + e.toString()); httpclient.getConnectionManager().shutdown(); throw new JSONParserStatusCodeException(TIMEOUT_ERROR); } catch (JSONParserStatusCodeException e) { httpclient.getConnectionManager().shutdown(); throw new JSONParserStatusCodeException(e.getCode()); } catch (Exception e) { Log.e("Debug", "Generic: " + e.toString()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } return null; }