Example usage for java.net URISyntaxException printStackTrace

List of usage examples for java.net URISyntaxException printStackTrace

Introduction

In this page you can find the example usage for java.net URISyntaxException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:net.billylieurance.azuresearch.AbstractAzureSearchQuery.java

/**
 * Run the query that has been set up in this instance.
 * Next step would be to get the results with {@link getQueryResult()}
 */// w  w  w . j  a  va 2s .com
public void doQuery() {
    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(
            new AuthScope(_targetHost.getHostName(), _targetHost.getPort()),
            new UsernamePasswordCredentials(this.getAppid(), this.getAppid()));

    URI uri;
    try {
        String full_path = getQueryPath();
        String full_query = getUrlQuery();
        uri = new URI(AZURESEARCH_SCHEME, AZURESEARCH_AUTHORITY, full_path, full_query, null);
        // Bing and java URI disagree about how to represent + in query
        // parameters. This is what we have to do instead...
        uri = new URI(uri.getScheme() + "://" + uri.getAuthority() + uri.getPath() + "?"
                + uri.getRawQuery().replace("+", "%2b").replace("'", "%27"));
        // System.out.println(uri.toString());
        // log.log(Level.WARNING, uri.toString());
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
        return;
    }

    HttpGet get = new HttpGet(uri);

    get.addHeader("Accept", "application/xml");
    get.addHeader("Content-Type", "application/xml");

    try {
        _responsePost = client.execute(get);
        _resEntity = _responsePost.getEntity();

        if (this.getProcessHTTPResults()) {
            _rawResult = loadXMLFromStream(_resEntity.getContent());
            this.loadResultsFromRawResults();
        }
        // Adding an automatic HTTP Result to String really requires
        // Apache Commons IO. That would break
        // Android compatibility. I'm not going to do that unless I
        // re-implement IOUtils.
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    }

}

From source file:org.hfoss.posit.android.web.Communicator.java

/**
 * A wrapper(does some cleanup too) for sending HTTP GET requests to the URI
 * //from w w w  . ja  v  a  2  s.  c  o  m
 * @param Uri
 * @return the request from the remote server
 */
public String doHTTPGET(String Uri) {
    if (Uri == null)
        throw new NullPointerException("The URL has to be passed");
    String responseString = null;
    HttpGet httpGet = new HttpGet();

    try {
        httpGet.setURI(new URI(Uri));
    } catch (URISyntaxException e) {
        Log.e(TAG, "doHTTPGet " + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    }
    if (Utils.debug) {
        Log.i(TAG, "doHTTPGet Uri = " + Uri);
    }
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    mStart = System.currentTimeMillis();

    try {
        responseString = mHttpClient.execute(httpGet, responseHandler);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "ClientProtocolException" + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    } catch (SocketTimeoutException e) {
        Log.e(TAG, "[Error: SocketTimeoutException]" + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    }

    long time = System.currentTimeMillis() - mStart;
    mTotalTime += time;
    Log.i(TAG, "TIME = " + time + " millisecs");

    if (Utils.debug)
        Log.i(TAG, "doHTTPGet Response: " + responseString);
    return responseString;
}

From source file:org.opencb.cellbase.app.cli.VariantAnnotationCommandExecutor.java

private VariantAnnotator createCellBaseAnnotator() {
    // Assume annotation of CellBase variation collection will always be carried out from a local installation
    if (local || cellBaseAnnotation) {
        // dbAdaptorFactory may have been already initialized at execute if annotating CellBase variation collection
        if (dbAdaptorFactory == null) {
            dbAdaptorFactory = new MongoDBAdaptorFactory(configuration);
        }//from  w  w  w . j  av a 2s  .c  o  m
        // Normalization should just be performed in one place: before calling the annotation calculator - within the
        // corresponding *AnnotatorTask since the AnnotatorTasks need that the number of sent variants coincides
        // equals the number of returned annotations
        return new CellBaseLocalVariantAnnotator(
                new VariantAnnotationCalculator(species, assembly, dbAdaptorFactory), queryOptions);
    } else {
        try {
            CellBaseClient cellBaseClient;
            cellBaseClient = new CellBaseClient(url, configuration.getVersion(), species);
            logger.debug("URL set to: {}", url + ":" + port);

            // TODO: normalization must be carried out in the client - phase set must be sent together with the
            // TODO: variant string to the server for proper phase annotation by REST
            return new CellBaseWSVariantAnnotator(cellBaseClient, queryOptions);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

    return null;

}

From source file:com.pearson.dashboard.util.Util.java

public static void retrieveTestCasesUsingSets(DashboardForm dashboardForm, Configuration configuration,
        String cutoffDateStr, List<String> testSets) throws IOException, URISyntaxException, ParseException {
    RallyRestApi restApi = loginRally(configuration);
    QueryRequest testSetRequest = new QueryRequest("TestSet");
    testSetRequest.setProject("/project/" + dashboardForm.getProjectId());
    String wsapiVersion = "1.43";
    restApi.setWsapiVersion(wsapiVersion);

    testSetRequest.setFetch(new Fetch(new String[] { "Name", "Priority", "Description", "TestCases",
            "FormattedID", "LastVerdict", "LastBuild", "LastRun" }));
    QueryFilter queryFilter = new QueryFilter("FormattedID", "=", testSets.get(0));
    int q = 1;//from w w w  .  ja v  a  2s.  c  o  m
    while (testSets.size() > q) {
        queryFilter = queryFilter.or(new QueryFilter("FormattedID", "=", testSets.get(q)));
        q++;
    }
    testSetRequest.setQueryFilter(queryFilter);
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            QueryResponse testSetQueryResponse = restApi.query(testSetRequest);
            dataNotReceived = false;
            List<Priority> priorities = new ArrayList<Priority>();
            Priority priority0 = new Priority();
            priority0.setPriorityName("Pass");
            Priority priority1 = new Priority();
            priority1.setPriorityName("Blocked");
            Priority priority2 = new Priority();
            priority2.setPriorityName("Error");
            Priority priority3 = new Priority();
            priority3.setPriorityName("Fail");
            Priority priority4 = new Priority();
            priority4.setPriorityName("Inconclusive");
            Priority priority5 = new Priority();
            priority5.setPriorityName("NotAttempted");

            int testCasesCount = 0;
            List<TestCase> testCases = new ArrayList<TestCase>();
            for (int i = 0; i < testSetQueryResponse.getResults().size(); i++) {
                JsonObject testSetJsonObject = testSetQueryResponse.getResults().get(i).getAsJsonObject();
                int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonArray().size();
                if (numberOfTestCases > 0) {
                    DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    Date cutoffDate = (Date) formatter1.parse(cutoffDateStr);

                    for (int j = 0; j < numberOfTestCases; j++) {
                        JsonObject jsonObject = testSetJsonObject.get("TestCases").getAsJsonArray().get(j)
                                .getAsJsonObject();
                        TestCase testCase = new TestCase();
                        testCase.setTestCaseId(jsonObject.get("FormattedID").getAsString());
                        Date lastVerdictDate = null;
                        if (null != jsonObject.get("LastRun") && !jsonObject.get("LastRun").isJsonNull()) {
                            lastVerdictDate = (Date) formatter1.parse(jsonObject.get("LastRun").getAsString());
                        }
                        String lastVerdict = "";
                        if (!jsonObject.get("LastVerdict").isJsonNull()) {
                            lastVerdict = jsonObject.get("LastVerdict").getAsString();
                        }
                        if (null != lastVerdictDate && lastVerdictDate.compareTo(cutoffDate) >= 0) {
                            if (lastVerdict.equalsIgnoreCase("Pass")) {
                                priority0.setPriorityCount(priority0.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Blocked")) {
                                priority1.setPriorityCount(priority1.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Error")) {
                                priority2.setPriorityCount(priority2.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Fail")) {
                                priority3.setPriorityCount(priority3.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("Inconclusive")) {
                                priority4.setPriorityCount(priority4.getPriorityCount() + 1);
                            }
                            if (lastVerdict.equalsIgnoreCase("")) {
                                priority5.setPriorityCount(priority5.getPriorityCount() + 1);
                            }

                        } else {
                            priority5.setPriorityCount(priority5.getPriorityCount() + 1);
                        }
                        testCasesCount++;
                        testCase.setLastVerdict(jsonObject.get("LastVerdict") == null
                                || jsonObject.get("LastVerdict").isJsonNull() ? ""
                                        : jsonObject.get("LastVerdict").getAsString());
                        testCase.setName(
                                jsonObject.get("Name") == null || jsonObject.get("Name").isJsonNull() ? ""
                                        : jsonObject.get("Name").getAsString());
                        testCase.setDescription(jsonObject.get("Description") == null
                                || jsonObject.get("Description").isJsonNull() ? ""
                                        : jsonObject.get("Description").getAsString());
                        testCase.setLastRun(
                                jsonObject.get("LastRun") == null || jsonObject.get("LastRun").isJsonNull() ? ""
                                        : jsonObject.get("LastRun").getAsString());
                        testCase.setLastBuild(
                                jsonObject.get("LastBuild") == null || jsonObject.get("LastBuild").isJsonNull()
                                        ? ""
                                        : jsonObject.get("LastBuild").getAsString());
                        testCase.setPriority(
                                jsonObject.get("Priority") == null || jsonObject.get("Priority").isJsonNull()
                                        ? ""
                                        : jsonObject.get("Priority").getAsString());
                        testCases.add(testCase);
                    }
                }
            }
            dashboardForm.setTestCases(testCases);
            List<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(priority0.getPriorityCount());
            arrayList.add(priority1.getPriorityCount());
            arrayList.add(priority2.getPriorityCount());
            arrayList.add(priority3.getPriorityCount());
            arrayList.add(priority4.getPriorityCount());
            arrayList.add(priority5.getPriorityCount());
            Integer maximumCount = Collections.max(arrayList);
            if (maximumCount <= 0) {
                priority0.setPxSize("0");
                priority1.setPxSize("0");
                priority2.setPxSize("0");
                priority3.setPxSize("0");
                priority4.setPxSize("0");
                priority5.setPxSize("0");
            } else {
                priority0.setPxSize(Math.round((100 * priority0.getPriorityCount()) / maximumCount) + "");
                priority1.setPxSize(Math.round((100 * priority1.getPriorityCount()) / maximumCount) + "");
                priority2.setPxSize(Math.round((100 * priority2.getPriorityCount()) / maximumCount) + "");
                priority3.setPxSize(Math.round((100 * priority3.getPriorityCount()) / maximumCount) + "");
                priority4.setPxSize(Math.round((100 * priority4.getPriorityCount()) / maximumCount) + "");
                priority5.setPxSize(Math.round((100 * priority5.getPriorityCount()) / maximumCount) + "");
            }
            priorities.add(priority0);
            priorities.add(priority1);
            priorities.add(priority2);
            priorities.add(priority3);
            priorities.add(priority4);
            priorities.add(priority5);

            dashboardForm.setTestCasesCount(testCasesCount);
            dashboardForm.setTestCasesPriorities(priorities);
        } catch (HttpHostConnectException connectException) {
            if (restApi != null) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.pearson.dashboard.util.Util.java

private static void retrieveDefects(Map<String, List<Defect>> allDefects, RallyRestApi restApi,
        String projectId, String typeCategory, String releaseNum, String cutoffDate, boolean yesterdayDefects,
        Configuration configuration, String operatingSystem, String tag) throws IOException, ParseException {
    List<Defect> defects;//from  w w  w  .j a  va  2s. co m
    QueryFilter queryFilter;
    QueryRequest defectRequest;
    QueryResponse projectDefects;
    JsonArray defectsArray;
    defects = new ArrayList<Defect>();

    QueryFilter releaseQueryFilter = null;
    if (null != releaseNum) {
        String releases[] = releaseNum.split(",");
        releaseQueryFilter = new QueryFilter("Release.Name", "=", releases[0]);
        for (int r = 1; r < releases.length; r++) {
            releaseQueryFilter = releaseQueryFilter.or(new QueryFilter("Release.Name", "=", releases[r]));
        }
    }
    if (yesterdayDefects) {
        String today = getDate("today");
        String yesterday = getDate("yesterday");
        if (typeCategory.equalsIgnoreCase("ClosedY")) {
            if (null != releaseQueryFilter) {
                queryFilter = new QueryFilter("State", "=", "Closed").and(releaseQueryFilter)
                        .and(new QueryFilter("ClosedDate", "<", today))
                        .and(new QueryFilter("ClosedDate", ">=", yesterday));
            } else {
                queryFilter = new QueryFilter("State", "=", "Closed")
                        .and(new QueryFilter("ClosedDate", "<", today))
                        .and(new QueryFilter("ClosedDate", ">=", yesterday));
            }
        } else {
            if (null != releaseQueryFilter) {
                queryFilter = releaseQueryFilter.and(new QueryFilter("CreationDate", "<", today))
                        .and(new QueryFilter("CreationDate", ">=", yesterday));
            } else {
                queryFilter = new QueryFilter("CreationDate", "<", today)
                        .and(new QueryFilter("CreationDate", ">=", yesterday));
            }
        }
    } else {
        if (null != releaseQueryFilter) {
            queryFilter = new QueryFilter("State", "=", typeCategory).and(releaseQueryFilter);
        } else {
            queryFilter = new QueryFilter("State", "=", typeCategory);
        }
        if (null != cutoffDate) {
            queryFilter = queryFilter.and(new QueryFilter("CreationDate", ">=", cutoffDate));
        }
    }

    defectRequest = new QueryRequest("defects");
    defectRequest.setQueryFilter(queryFilter);
    defectRequest.setFetch(new Fetch("State", "Release", "Tags", "Name", "FormattedID", "Platform", "Priority",
            "Components", "LastUpdateDate", "SubmittedBy", "Owner", "Project", "ClosedDate"));
    defectRequest.setProject("/project/" + projectId);
    defectRequest.setScopedDown(true);
    defectRequest.setLimit(4000);
    defectRequest.setOrder("FormattedID desc");
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            projectDefects = restApi.query(defectRequest);
            dataNotReceived = false;
            defectsArray = projectDefects.getResults();
            for (int i = 0; i < defectsArray.size(); i++) {
                JsonElement elements = defectsArray.get(i);
                JsonObject object = elements.getAsJsonObject();
                boolean isTag = true;
                if (null != tag) {
                    isTag = false;
                }

                if (null != tag && null != object.get("Tags") && !object.get("Tags").isJsonNull()) {
                    JsonObject jsonObject = object.get("Tags").getAsJsonObject();
                    int numberOfTestCases = jsonObject.get("_tagsNameArray").getAsJsonArray().size();
                    if (numberOfTestCases > 0) {
                        for (int j = 0; j < numberOfTestCases; j++) {
                            JsonObject jsonObj = jsonObject.get("_tagsNameArray").getAsJsonArray().get(j)
                                    .getAsJsonObject();
                            if (jsonObj.get("Name").getAsString().equals(tag)) {
                                isTag = true;
                            }
                        }
                    }
                }

                if (isTag) {
                    Defect defect = new Defect();
                    defect.setDefectId(object.get("FormattedID").getAsString());

                    if (null != object.get("_ref")) {
                        String defectRef = object.get("_ref").getAsString();
                        if (null != defectRef) {
                            String url = configuration.getRallyURL() + "#/" + projectId + "ud/detail/defect"
                                    + defectRef.substring(defectRef.lastIndexOf("/"));
                            defect.setDefectUrl(url);
                        }
                    }

                    String strFormat1 = object.get("LastUpdateDate").getAsString().substring(0, 10);
                    DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = (Date) formatter1.parse(strFormat1);
                    DateFormat formatter2 = new SimpleDateFormat("MMM dd YY");
                    defect.setLastUpdateDate(formatter2.format(date));

                    defect.setLastUpdateDateOriginal(
                            object.get("LastUpdateDate").getAsString().substring(0, 10));

                    if (null != object.get("Priority") && !object.get("Priority").getAsString().isEmpty()
                            && !object.get("Priority").getAsString().startsWith("No")) {
                        defect.setPriority("P" + object.get("Priority").getAsString().charAt(0));
                    } else {
                        defect.setPriority("TBD");
                    }
                    defect.setState(object.get("State").getAsString());
                    JsonObject project = object.get("Project").getAsJsonObject();
                    defect.setProject(project.get("_refObjectName").getAsString());
                    defect.setDefectDesc(object.get("Name").getAsString());
                    String platform = "iOS";
                    if (null != object.get("c_Platform") && !object.get("c_Platform").isJsonNull()) {
                        if (object.get("c_Platform").getAsString().contains("iOS")
                                && object.get("c_Platform").getAsString().contains("Win")) {
                            platform = "iOS";
                        } else if (object.get("c_Platform").getAsString().contains("iOS")) {
                            platform = "iOS";
                        } else if (object.get("c_Platform").getAsString().contains("Win")) {
                            platform = "Windows";
                        }
                    } else {
                        System.out.println(defect.getDefectId());
                    }
                    defect.setPlatform(platform);
                    defect.setComponents(object.get("c_Components").getAsString());
                    if (platform.equalsIgnoreCase(operatingSystem) || operatingSystem.equalsIgnoreCase("All")) {
                        defects.add(defect);
                    }
                } else {
                    System.out.println("aplha");
                }
            }
            Collections.sort(defects);
            allDefects.put(typeCategory, defects);
        } catch (HttpHostConnectException connectException) {
            if (restApi != null) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.opengeoportal.proxy.controllers.DynamicOgcController.java

@SuppressWarnings("deprecation")
private void doProxy(String remoteUrl, HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws ServletException, IOException {
    // Make the Request
    //note: we won't transfer the protocol version because I'm not sure it would truly be compatible
    try {/*from  w  ww .j a v a 2s .  com*/
        this.targetUri = new URI(remoteUrl);
    } catch (URISyntaxException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //Need to handle https, but think about "restricted" layers for now.  Some institutions don't really have good protection for restricted layers.  Does this open up potential for security
    //problems for those folks?
    if (servletRequest.getScheme().equals("https")) {
        //actually, what matters the most is if the remote url is https
    }

    BasicHttpEntityEnclosingRequest proxyRequest = new BasicHttpEntityEnclosingRequest(
            servletRequest.getMethod(), rewriteUrlFromRequest(servletRequest));

    //HttpGet httpget = new HttpGet(rewriteUrlFromRequest(servletRequest));
    copyRequestHeaders(servletRequest, proxyRequest);

    // Add the input entity (streamed) then execute the request.
    HttpResponse proxyResponse = null;
    InputStream servletRequestInputStream = servletRequest.getInputStream();
    CloseableHttpClient proxyClient = ogpHttpClient.getCloseableHttpClient();

    try {
        try {
            //proxyRequest.setEntity(new InputStreamEntity(servletRequestInputStream));
            proxyRequest.setEntity(
                    new InputStreamEntity(servletRequestInputStream, servletRequest.getContentLength()));

            // Execute the request
            logger.debug("proxy " + servletRequest.getMethod() + " uri: " + servletRequest.getRequestURI()
                    + " -- " + proxyRequest.getRequestLine().getUri());

            proxyResponse = proxyClient.execute(URIUtils.extractHost(targetUri), proxyRequest);
        } finally {
            IOUtils.closeQuietly(servletRequestInputStream);
        }

        // Process the response
        int statusCode = proxyResponse.getStatusLine().getStatusCode();
        logger.info("Status from remote server: " + Integer.toString(statusCode));
        if (doResponseRedirectOrNotModifiedLogic(servletRequest, servletResponse, proxyResponse, statusCode)) {
            EntityUtils.consume(proxyResponse.getEntity());
            return;
        }

        // Pass the response code. This method with the "reason phrase" is deprecated but it's the only way to pass the
        // reason along too.
        //noinspection deprecation
        servletResponse.setStatus(statusCode, proxyResponse.getStatusLine().getReasonPhrase());

        copyResponseHeaders(proxyResponse, servletResponse);

        // Send the content to the client
        copyResponseEntity(proxyResponse, servletResponse);

    } catch (Exception e) {
        //abort request, according to best practice with HttpClient
        if (proxyRequest instanceof AbortableHttpRequest) {
            AbortableHttpRequest abortableHttpRequest = (AbortableHttpRequest) proxyRequest;
            abortableHttpRequest.abort();
        }
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        if (e instanceof ServletException)
            throw (ServletException) e;
        throw new RuntimeException(e);
    }
}

From source file:org.hfoss.posit.android.web.Communicator.java

/**
 * Sends a HttpPost request to the given URL. Any JSON
 * /*from w  w w  .j a v  a 2 s .c o  m*/
 * @param Uri
 *            the URL to send to/receive from
 * @param sendMap
 *            the hashMap of data to send to the server as POST data
 * @return the response from the URL
 */
private String doHTTPPost(String Uri, HashMap<String, String> sendMap) {
    long startTime = System.currentTimeMillis();
    if (Uri == null)
        throw new NullPointerException("The URL has to be passed");
    String responseString = null;
    HttpPost post = new HttpPost();
    if (Utils.debug)
        Log.i(TAG, "doHTTPPost() URI = " + Uri);
    try {
        post.setURI(new URI(Uri));
    } catch (URISyntaxException e) {
        Log.e(TAG, "URISyntaxException " + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();

    }
    List<NameValuePair> nvp = PositHttpUtils.getNameValuePairs(sendMap);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        post.setEntity(new UrlEncodedFormEntity(nvp, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "UnsupportedEncodingException " + e.getMessage());
        return "[Error] " + e.getMessage();
    }
    mStart = System.currentTimeMillis();

    try {
        responseString = mHttpClient.execute(post, responseHandler);
        Log.d(TAG, "doHTTPpost responseString = " + responseString);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "ClientProtocolException" + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    } catch (IOException e) {
        Log.e(TAG, "IOException " + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    } catch (IllegalStateException e) {
        Log.e(TAG, "IllegalStateException: " + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    } catch (Exception e) {
        Log.e(TAG, "Exception on HttpPost " + e.getMessage());
        e.printStackTrace();
        return "[Error] " + e.getMessage();
    }
    long time = System.currentTimeMillis() - startTime;
    mTotalTime += time;
    Log.i(TAG, "doHTTPpost response = " + responseString + " TIME = " + time + " millisecs");

    return responseString;
}

From source file:com.pearson.dashboard.util.Util.java

public static void retrieveTestResults(DashboardForm dashboardForm, Configuration configuration,
        String cutoffDateStr, List<String> testSets) throws IOException, URISyntaxException, ParseException {
    RallyRestApi restApi = loginRally(configuration);
    QueryRequest testCaseResultsRequest = new QueryRequest("TestCaseResult");
    testCaseResultsRequest.setFetch(//from  ww  w .j av a2s . co  m
            new Fetch("Build", "TestCase", "TestSet", "Verdict", "FormattedID", "Date", "TestCaseCount"));
    if (testSets == null || testSets.isEmpty()) {
        testSets = new ArrayList<String>();
        testSets.add("TS0");
    }
    QueryFilter queryFilter = new QueryFilter("TestSet.FormattedID", "=", testSets.get(0));
    int q = 1;
    while (testSets.size() > q) {
        queryFilter = queryFilter.or(new QueryFilter("TestSet.FormattedID", "=", testSets.get(q)));
        q++;
    }
    testCaseResultsRequest.setLimit(4000);
    testCaseResultsRequest.setQueryFilter(queryFilter);
    boolean dataNotReceived = true;
    while (dataNotReceived) {
        try {
            QueryResponse testCaseResultResponse = restApi.query(testCaseResultsRequest);
            JsonArray array = testCaseResultResponse.getResults();
            int numberTestCaseResults = array.size();
            dataNotReceived = false;
            List<Priority> priorities = new ArrayList<Priority>();
            Priority priority0 = new Priority();
            priority0.setPriorityName("Pass");
            Priority priority1 = new Priority();
            priority1.setPriorityName("Blocked");
            Priority priority2 = new Priority();
            priority2.setPriorityName("Error");
            Priority priority3 = new Priority();
            priority3.setPriorityName("Fail");
            Priority priority4 = new Priority();
            priority4.setPriorityName("Inconclusive");
            Priority priority5 = new Priority();
            priority5.setPriorityName("NotAttempted");
            List<TestCase> testCases = new ArrayList<TestCase>();
            List<TestResult> testResults = new ArrayList<TestResult>();
            if (numberTestCaseResults > 0) {
                for (int i = 0; i < numberTestCaseResults; i++) {
                    TestResult testResult = new TestResult();
                    TestCase testCase = new TestCase();
                    String build = array.get(i).getAsJsonObject().get("Build").getAsString();
                    String verdict = array.get(i).getAsJsonObject().get("Verdict").getAsString();
                    DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    String strDate = array.get(i).getAsJsonObject().get("Date").getAsString().substring(0, 10);
                    int hour = Integer.parseInt(
                            array.get(i).getAsJsonObject().get("Date").getAsString().substring(11, 13));
                    int min = Integer.parseInt(
                            array.get(i).getAsJsonObject().get("Date").getAsString().substring(14, 16));
                    Date date = (Date) formatter1.parse(strDate);
                    date.setHours(hour);
                    date.setMinutes(min);
                    JsonObject testSetJsonObj = array.get(i).getAsJsonObject().get("TestSet").getAsJsonObject();
                    JsonObject testCaseJsonObj = array.get(i).getAsJsonObject().get("TestCase")
                            .getAsJsonObject();
                    String testSet = testSetJsonObj.get("FormattedID").getAsString();
                    String testCaseId = testCaseJsonObj.get("FormattedID").getAsString();
                    int resultExists = testResultExists(testSet, testCaseId, date, testResults, testCases);
                    if (resultExists != 0) {
                        testResult.setDate(date);
                        testResult.setStatus(verdict);
                        testResult.setTestCase(testCaseId);
                        testResult.setTestSet(testSet);
                        testResults.add(testResult);
                        testCase.setTestCaseId(testCaseId);
                        testCase.setLastVerdict(verdict);
                        testCase.setName(testSet);
                        testCase.setDescription("");
                        testCase.setLastRun(strDate);
                        testCase.setLastBuild(build);
                        testCase.setPriority("");
                        testCases.add(testCase);
                    }
                }
            }
            for (TestResult result : testResults) {
                String verdict = result.getStatus();
                if (verdict.equalsIgnoreCase("error")) {
                    priority2.setPriorityCount(priority2.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("pass")) {
                    priority0.setPriorityCount(priority0.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("fail")) {
                    priority3.setPriorityCount(priority3.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("inconclusive")) {
                    priority4.setPriorityCount(priority4.getPriorityCount() + 1);
                } else if (verdict.equalsIgnoreCase("blocked")) {
                    priority1.setPriorityCount(priority1.getPriorityCount() + 1);
                }
            }

            dashboardForm.setTestCases(testCases);

            QueryRequest testCaseCountReq = new QueryRequest("TestSet");
            testCaseCountReq.setFetch(new Fetch("FormattedID", "Name", "TestCaseCount"));
            queryFilter = new QueryFilter("FormattedID", "=", testSets.get(0));
            q = 1;
            while (testSets.size() > q) {
                queryFilter = queryFilter.or(new QueryFilter("FormattedID", "=", testSets.get(q)));
                q++;
            }
            testCaseCountReq.setQueryFilter(queryFilter);
            QueryResponse testCaseResponse = restApi.query(testCaseCountReq);
            int testCaseCount = 0;
            for (int i = 0; i < testCaseResponse.getResults().size(); i++) {
                testCaseCount = testCaseCount + testCaseResponse.getResults().get(i).getAsJsonObject()
                        .get("TestCaseCount").getAsInt();
            }

            int unAttempted = testCaseCount - priority0.getPriorityCount() - priority1.getPriorityCount()
                    - priority2.getPriorityCount() - priority3.getPriorityCount()
                    - priority4.getPriorityCount();
            priority5.setPriorityCount(unAttempted);

            List<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(priority0.getPriorityCount());
            arrayList.add(priority1.getPriorityCount());
            arrayList.add(priority2.getPriorityCount());
            arrayList.add(priority3.getPriorityCount());
            arrayList.add(priority4.getPriorityCount());
            arrayList.add(priority5.getPriorityCount());
            Integer maximumCount = Collections.max(arrayList);
            if (maximumCount <= 0) {
                priority0.setPxSize("0");
                priority1.setPxSize("0");
                priority2.setPxSize("0");
                priority3.setPxSize("0");
                priority4.setPxSize("0");
                priority5.setPxSize("0");
            } else {
                priority0.setPxSize(Math.round((100 * priority0.getPriorityCount()) / maximumCount) + "");
                priority1.setPxSize(Math.round((100 * priority1.getPriorityCount()) / maximumCount) + "");
                priority2.setPxSize(Math.round((100 * priority2.getPriorityCount()) / maximumCount) + "");
                priority3.setPxSize(Math.round((100 * priority3.getPriorityCount()) / maximumCount) + "");
                priority4.setPxSize(Math.round((100 * priority4.getPriorityCount()) / maximumCount) + "");
                priority5.setPxSize(Math.round((100 * priority5.getPriorityCount()) / maximumCount) + "");
            }
            priorities.add(priority0);
            priorities.add(priority1);
            priorities.add(priority2);
            priorities.add(priority3);
            priorities.add(priority4);
            priorities.add(priority5);

            dashboardForm.setTestCasesCount(testCaseCount);
            dashboardForm.setTestCasesPriorities(priorities);
        } catch (HttpHostConnectException connectException) {
            if (restApi != null) {
                restApi.close();
            }
            try {
                restApi = loginRally(configuration);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:net.sourceforge.seqware.common.metadata.MetadataWSTest.java

/**
 * Test of addWorkflow method, of class MetadataWS with a novoalign.ini.
 *//*from w  w  w . ja v  a2s. co  m*/
@Test
public void testAddNovoAlignWorkflow() {
    logger.info("addWorkflow");
    String name = "novoalign";
    String version = "0.13.6.2";
    String description = "Novoalign";
    String baseCommand = "java -jar /u/seqware/provisioned-bundles/sqwprod/"
            + "Workflow_Bundle_GATKRecalibrationAndVariantCalling_1.2.29_"
            + "SeqWare_0.10.0/GATKRecalibrationAndVariantCalling/1.x.x/lib/"
            + "seqware-pipeline-0.10.0.jar --plugin net.sourceforge.seqware."
            + "pipeline.plugins.WorkflowLauncher -- --bundle /u/seqware/"
            + "provisioned-bundles/sqwprod/Workflow_Bundle_GATKRecalibration"
            + "AndVariantCalling_1.2.29_SeqWare_0.10.0 --workflow GATK"
            + "RecalibrationAndVariantCalling --version 1.3.16";
    java.io.File configFile = null, templateFile = null;
    try {
        configFile = new java.io.File(MetadataWSTest.class.getResource("novoalign.ini").toURI());
        templateFile = new java.io.File(
                MetadataWSTest.class.getResource("GATKRecalibrationAndVariantCalling_1.3.16.ftl").toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    java.io.File provisionDir = new java.io.File("/u/seqware/provisioned-bundles"
            + "/sqwprod/Workflow_Bundle_GATKRecalibrationAndVariantCalling_" + "1.2.29_SeqWare_0.10.0/");
    int expResult = ReturnValue.SUCCESS;
    ReturnValue result = instance.addWorkflow(name, version, description, baseCommand,
            configFile.getAbsolutePath(), templateFile.getAbsolutePath(), provisionDir.getAbsolutePath(), true,
            "", false, null, null, null);
    Assert.assertEquals(expResult, result.getExitStatus());

    // test certain properties of the workflow parameters in relation to SEQWARE-1444
    String workflow_id = result.getAttribute("sw_accession");
    Workflow workflow = instance.getWorkflow(Integer.valueOf(workflow_id));
    Assert.assertTrue("workflow retrieved is invalid", workflow.getWorkflowId() == result.getReturnValue());
    SortedSet<WorkflowParam> workflowParams = instance.getWorkflowParams(workflow_id);
    Assert.assertTrue("invalid number of workflow params retrieved", workflowParams.size() == 34);
    // check out the values of some suspicious values
    for (WorkflowParam param : workflowParams) {
        if (param.getKey().equals("colorspace")) {
            Assert.assertTrue("colorspace invalid", param.getDefaultValue().equals("0"));
        } else if (param.getKey().equals("novoalign_r1_adapter_trim")) {
            Assert.assertTrue("novoalign_r1_adapter_trim invalid",
                    param.getDefaultValue().equals("-a AGATCGGAAGAGCGGTTCAGCAGGAATGCCGAGACCG"));
        }
    }

}

From source file:de.uni_potsdam.hpi.bpt.bp2014.jcore.rest.RestInterface.java

/**
 * This method provides detailed information about a scenario instance.
 * The information will contain the id, name, parent scenario and the
 * number of activities in the different states.
 * The Response is JSON-Object.//from w  w  w  . j  a va 2s  . co  m
 *
 * @param scenarioID The ID of the scenario.
 * @param instanceID The ID of the instance.
 * @return Will return a Response with a JSON-Object body, containing
 * the information about the instance.
 * If the instance ID or both are incorrect 404 (NOT_FOUND) will be
 * returned.
 * If the scenario ID is wrong but the instance ID is correct a 301
 * (REDIRECT) will be returned.
 * If both IDs are correct a 200 (OK) with the expected JSON-Content
 * will be returned.
 */
@GET
@Path("scenario/{scenarioID}/instance/{instanceID}")
@Produces(MediaType.APPLICATION_JSON)
public Response getScenarioInstance(@PathParam("scenarioID") int scenarioID,
        @PathParam("instanceID") int instanceID) {
    ExecutionService executionService = new ExecutionService();
    DbScenarioInstance instance = new DbScenarioInstance();
    //TODO: add links to detail REST calls for more information about each activity instance
    if (!executionService.existScenarioInstance(instanceID)) {
        return Response.status(Response.Status.NOT_FOUND)
                .entity("{\"message\":\"There is no instance with the id " + instanceID + "\"}")
                .type(MediaType.APPLICATION_JSON).build();
    } else if (!executionService.existScenario(scenarioID)) {
        scenarioID = instance.getScenarioID(instanceID);
        try {
            return Response.seeOther(new URI("interface/v2/scenario/" + scenarioID + "/instance/" + instanceID))
                    .build();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    return Response
            .ok((new JSONObject(instance.getInstanceMap(instanceID))).toString(), MediaType.APPLICATION_JSON)
            .build();
}