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:iristk.speech.nuancecloud.JSpeexNuanceCloudRecognizerListener.java

private void initRequest() {
    try {// www .  ja  v a  2  s  .  c om
        byteQueue.reset();
        encodedQueue.reset();
        JSpeexEnc encoder = new JSpeexEnc(16000);
        encoder.startEncoding(byteQueue, encodedQueue);

        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("appId", APP_ID));
        qparams.add(new BasicNameValuePair("appKey", APP_KEY));
        qparams.add(new BasicNameValuePair("id", DEVICE_ID));
        URI uri = URIUtils.createURI("https", HOSTNAME, 443, SERVLET, URLEncodedUtils.format(qparams, "UTF-8"),
                null);
        final HttpPost httppost = new HttpPost(uri);
        httppost.addHeader("Content-Type", CODEC);
        httppost.addHeader("Content-Language", LANGUAGE);
        httppost.addHeader("Accept-Language", LANGUAGE);
        httppost.addHeader("Accept", RESULTS_FORMAT);
        httppost.addHeader("Accept-Topic", LM);
        if (nuanceAudioSource != null) {
            httppost.addHeader("X-Dictation-AudioSource", nuanceAudioSource.name());
        }
        if (cookie != null)
            httppost.addHeader("Cookie", cookie);

        InputStreamEntity reqEntity = new InputStreamEntity(encodedQueue.getInputStream(), -1);
        reqEntity.setContentType(CODEC);

        httppost.setEntity(reqEntity);

        postThread = new PostThread(httppost);

    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:org.deviceconnect.android.uiapp.fragment.profile.ExtraProfileFragment.java

/**
 * ??.//from   w w w  .j a v  a 2s .  c  om
 * @param view ?
 */
protected void onClickSend(final View view) {
    // 
    final CharSequence inter = ((TextView) getView().findViewById(R.id.fragment_extra_interface)).getText();
    // 
    final CharSequence attr = ((TextView) getView().findViewById(R.id.fragment_extra_attribute)).getText();
    // 
    final String accessToken = getAccessToken();
    // 
    final CharSequence query = ((TextView) getView().findViewById(R.id.fragment_extra_query)).getText();

    final URIBuilder builder = new URIBuilder();
    builder.setProfile(mProfile);
    if (inter != null && inter.length() > 0) {
        builder.setInterface(inter.toString());
    }
    if (attr != null && attr.length() > 0) {
        builder.setAttribute(attr.toString());
    }
    builder.addParameter(DConnectMessage.EXTRA_DEVICE_ID, getSmartDevice().getId());
    if (accessToken != null) {
        builder.addParameter(DConnectMessage.EXTRA_ACCESS_TOKEN, accessToken);
    }
    if (query != null) {
        String path = query.toString();
        if (path.length() > 0) {
            String[] keyvalues = path.split("&");
            for (int i = 0; i < keyvalues.length; i++) {
                String[] kv = keyvalues[i].split("=");
                if (kv.length == 1) {
                    builder.addParameter(kv[0], "");
                } else if (kv.length == 2) {
                    builder.addParameter(kv[0], kv[1]);
                }
            }
        }
    }

    HttpRequest request = null;
    try {
        Spinner spinner = (Spinner) getView().findViewById(R.id.spinner);
        String method = (String) spinner.getSelectedItem();
        if (method.equals("GET")) {
            request = new HttpGet(builder.build());
        } else if (method.equals("POST")) {
            request = new HttpPost(builder.build());
        } else if (method.equals("PUT")) {
            request = new HttpPut(builder.build());
        } else if (method.equals("DELETE")) {
            request = new HttpDelete(builder.build());
        }
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                TextView tv = (TextView) getView().findViewById(R.id.fragment_extra_request);
                try {
                    String uri = builder.build().toASCIIString();
                    tv.setText(uri);
                } catch (URISyntaxException e) {
                    tv.setText("");
                }
            }
        });
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    (new AsyncTask<HttpRequest, Void, DConnectMessage>() {
        public DConnectMessage doInBackground(final HttpRequest... args) {
            if (args == null || args.length <= 0) {
                return new DConnectResponseMessage(DConnectMessage.RESULT_ERROR);
            }

            DConnectMessage message = new DConnectResponseMessage(DConnectMessage.RESULT_ERROR);
            try {
                HttpRequest request = args[0];
                HttpResponse response = getDConnectClient().execute(getDefaultHost(), request);
                message = (new HttpMessageFactory()).newDConnectMessage(response);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return message;
        }

        @Override
        protected void onPostExecute(final DConnectMessage result) {

            if (getActivity().isFinishing()) {
                return;
            }

            if (result == null) {
                return;
            }
            View view = getView();
            if (view != null) {
                TextView tv = (TextView) view.findViewById(R.id.fragment_extra_response);
                tv.setText(result.toString());
            }
        }
    }).execute(request);
}

From source file:org.seadpdt.impl.PeopleServicesImpl.java

@POST
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)//  w ww .jav a 2  s . co  m
@Produces(MediaType.APPLICATION_JSON)
public Response registerPerson(String personString) {

    JSONObject person = new JSONObject(personString);
    Provider p = null;

    if (person.has(provider)) {
        p = Provider.getProvider((String) person.get(provider));

    }

    if (!person.has(identifier)) {
        return Response.status(Status.BAD_REQUEST)
                .entity(new BasicDBObject("Failure", "Invalid request format: missing identifier")).build();
    }
    String rawID = (String) person.get(identifier);

    String newID;
    if (p != null) {
        //Know which provider the ID is from (as claimed by the client) so go direct to get its canonical form
        newID = p.getCanonicalId(rawID);
    } else {
        //Don't know the provider, so find it and the canonical ID together
        Profile profile = Provider.findCanonicalId(rawID);
        if (profile != null) {

            p = Provider.getProvider(profile.getProvider());
        } //else no provider recognized the id (e.g. it's a string), so we'll just fail with a null Provier
        if (p == null) {
            return Response.status(Status.BAD_REQUEST)
                    .entity(new BasicDBObject("Failure", "Invalid request format:identifier not recognized"))
                    .build();
        }
        newID = profile.getIdentifier();
    }

    person.put(identifier, newID);

    FindIterable<Document> iter = peopleCollection.find(new Document("@id", newID));
    if (iter.iterator().hasNext()) {
        return Response.status(Status.CONFLICT)
                .entity(new BasicDBObject("Failure", "Person with Identifier " + newID + " already exists"))
                .build();
    } else {
        URI resource = null;
        try {

            Document profileDocument = p.getExternalProfile(person);
            peopleCollection.insertOne(profileDocument);
            resource = new URI("./" + profileDocument.getString("@id"));
        } catch (Exception r) {
            return Response.serverError()
                    .entity(new BasicDBObject("failure", "Provider call failed with status: " + r.getMessage()))
                    .build();
        }

        try {
            resource = new URI("./" + newID);
        } catch (URISyntaxException e) {
            // Should not happen given simple ids
            e.printStackTrace();
        }
        return Response.created(resource).entity(new Document("identifier", newID)).build();
    }
}

From source file:org.xwiki.android.test.utils.xmlrpc.RestClient.java

public int headRequest(String Uri) throws IOException {

    HttpHead request = new HttpHead();
    URI requestUri;/*from  ww  w .j a v a2s  .com*/
    try {
        requestUri = new URI(Uri);
        request.setURI(requestUri);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    log.debug("Request URL :" + Uri);

    try {
        HttpResponse response = client.execute(request);
        log.debug("Response status", response.getStatusLine().toString());
        return response.getStatusLine().getStatusCode();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:org.xwiki.android.test.utils.xmlrpc.RestClient.java

/**
 * Perform HTTP Put method with the raw data file
 *
 * @param Uri  URL of XWiki RESTful API/*from  ww  w .j  a  v a 2 s. c  o m*/
 * @param file file to upload
 * @return status of the HTTP Put method execution
 * @throws IOException
 * @throws RestException
 */
public HttpResponse putRequest(String Uri, File file) throws IOException, RestException {

    HttpPut request = new HttpPut();
    try {
        URI requestUri = new URI(Uri);
        request.setURI(requestUri);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    log.debug("Request URL :" + Uri);
    try {
        FileEntity fe = new FileEntity(file, "/");
        request.setEntity(fe);
        // request.setHeader("Content-Type","application/xml;charset=UTF-8");
        HttpResponse response = client.execute(request);
        log.debug("Response status", response.getStatusLine().toString());
        EntityUtils.consume(response.getEntity());
        validate(response.getStatusLine().getStatusCode());
        return response;
    } catch (ClientProtocolException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.xwiki.android.test.utils.xmlrpc.RestClient.java

/**
 * Perform HTTP Delete method execution and return its status
 *
 * @param Uri URL of XWiki RESTful API//  w  ww  .  j  a  v a2  s  .com
 * @return status of the HTTP method execution
 * @throws IOException
 * @throws RestException
 */
public HttpResponse deleteRequest(String Uri) throws IOException, RestException {

    HttpDelete request = null;

    try {
        URI requestUri = new URI(Uri);
        request = new HttpDelete();
        request.setURI(requestUri);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    log.debug("Request URL :" + Uri);
    try {
        HttpResponse response = client.execute(request);

        log.debug("Response status", response.getStatusLine().toString());
        EntityUtils.consume(response.getEntity());
        validate(response.getStatusLine().getStatusCode());
        return response;
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:org.epop.dataprovider.msacademic.MicrosoftAcademicSearch.java

@Override
protected Reader getHTMLDoc(String htmlParams, int pageTurnLimit, boolean initialWait) {

    // http://academic.research.microsoft.com/Search/?query=author:(%22Angelo%20gargantini%22)&start=1&end=10000
    // List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    // qparams.add(new BasicNameValuePair("query","author:(\""+
    // q.getCompleteAuthorName()+"\")"));//with quotation marks
    // qparams.add(new BasicNameValuePair("query", "author:("
    // + q.getCompleteAuthorName() + ")"));// without quotation marks
    // qparams.add(new BasicNameValuePair("start", "1"));
    // qparams.add(new BasicNameValuePair("end",
    // String.valueOf(searchStep)));

    URI uri;/* w ww  .j  a  va  2  s .c  o  m*/
    String responseBody = "";

    try {

        if (initialWait)
            Thread.sleep(DELAY);

        uri = URIUtils.createURI("http", MS_ACADEMIC_SEARCH, -1, "", htmlParams, null);
        HttpGet httpget = new HttpGet(uri);
        System.out.println(httpget.getURI());
        HttpClient httpclient = new DefaultHttpClient();
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httpget, responseHandler);

        if (pageTurnLimit == 0)
            return new StringReader(responseBody);

        int counter = 1;
        String newResponseBody = responseBody;
        while (newResponseBody.contains(
                "<a id=\"ctl00_MainContent_PaperList_Next\" title=\"Go to Next Page\" class=\"nextprev\"")) {

            Thread.sleep(DELAY);

            URI newUri = URIUtils.createURI("http", MS_ACADEMIC_SEARCH, -1, "",
                    htmlParams + "&start=" + String.valueOf((counter * searchStep) + 1) + "&end="
                            + String.valueOf((counter + 1) * searchStep),
                    null);

            httpget = new HttpGet(newUri);
            System.out.println(httpget.getURI());
            httpclient = new DefaultHttpClient();
            newResponseBody = httpclient.execute(httpget, responseHandler);
            // System.out.println(newResponseBody);
            responseBody = responseBody + newResponseBody;

            if (pageTurnLimit == counter)
                return new StringReader(responseBody);

            counter++;

        }

    } catch (URISyntaxException 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 (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // return the result as string
    return new StringReader(responseBody);
}

From source file:org.xwiki.android.test.utils.xmlrpc.RestClient.java

/**
 * Perform HTTP Post method execution and return its response status
 *
 * @param Uri     URL of XWiki RESTful API
 * @param content content to be posted to the server
 * @return status code of the Post method execution
 * @throws IOException//from   www . j  a v a  2  s . c  om
 * @throws RestException
 */
public HttpResponse postRequest(String Uri, String content) throws IOException, RestException {

    HttpPost request = new HttpPost();

    try {
        URI requestUri = new URI(Uri);
        request.setURI(requestUri);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    log.debug("Request URL :" + Uri);

    try {
        log.debug("Post content", "content=" + content);
        StringEntity se = new StringEntity(content, "UTF-8");

        se.setContentType("application/xml");
        // se.setContentType("text/plain");
        request.setEntity(se);
        request.setHeader("Content-Type", "application/xml;charset=UTF-8");

        HttpResponse response = client.execute(request);
        log.debug("Response status", response.getStatusLine().toString());
        EntityUtils.consume(response.getEntity());
        validate(response.getStatusLine().getStatusCode());
        return response;

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:at.bitfire.ical4android.AndroidTask.java

protected void buildTask(Builder builder, boolean update) {
    if (!update)/*from  w ww  .  j a  v a  2  s .  com*/
        builder.withValue(Tasks.LIST_ID, taskList.getId()).withValue(Tasks._DIRTY, 0);

    builder
            //.withValue(Tasks._UID, task.uid)          // not available in F-Droid OpenTasks version yet (15 Oct 2015)
            .withValue(Tasks.TITLE, task.summary).withValue(Tasks.LOCATION, task.location);

    if (task.geoPosition != null)
        builder.withValue(Tasks.GEO, task.geoPosition.getValue());

    builder.withValue(Tasks.DESCRIPTION, task.description).withValue(Tasks.URL, task.url);

    if (task.organizer != null)
        try {
            URI organizer = new URI(task.organizer.getValue());
            if ("mailto".equals(organizer.getScheme()))
                builder.withValue(Tasks.ORGANIZER, organizer.getSchemeSpecificPart());
            else
                Log.w(TAG, "Found non-mailto ORGANIZER URI, ignoring");
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

    builder.withValue(Tasks.PRIORITY, task.priority);

    if (task.classification != null) {
        int classCode = Tasks.CLASSIFICATION_PRIVATE;
        if (task.classification == Clazz.PUBLIC)
            classCode = Tasks.CLASSIFICATION_PUBLIC;
        else if (task.classification == Clazz.CONFIDENTIAL)
            classCode = Tasks.CLASSIFICATION_CONFIDENTIAL;
        builder.withValue(Tasks.CLASSIFICATION, classCode);
    }

    if (task.completedAt != null) {
        // COMPLETED must always be a DATE-TIME
        builder.withValue(Tasks.COMPLETED, task.completedAt.getDateTime().getTime())
                .withValue(Tasks.COMPLETED_IS_ALLDAY, 0);
    }
    builder.withValue(Tasks.PERCENT_COMPLETE, task.percentComplete);

    int statusCode = Tasks.STATUS_DEFAULT;
    if (task.status != null) {
        if (task.status == Status.VTODO_NEEDS_ACTION)
            statusCode = Tasks.STATUS_NEEDS_ACTION;
        else if (task.status == Status.VTODO_IN_PROCESS)
            statusCode = Tasks.STATUS_IN_PROCESS;
        else if (task.status == Status.VTODO_COMPLETED)
            statusCode = Tasks.STATUS_COMPLETED;
        else if (task.status == Status.VTODO_CANCELLED)
            statusCode = Tasks.STATUS_CANCELLED;
    }
    builder.withValue(Tasks.STATUS, statusCode);

    final boolean allDay = task.isAllDay();
    if (allDay)
        builder.withValue(Tasks.IS_ALLDAY, 1);
    else {
        builder.withValue(Tasks.IS_ALLDAY, 0);

        java.util.TimeZone tz = task.getTimeZone();
        builder.withValue(Tasks.TZ, tz.getID());
    }

    if (task.createdAt != null)
        builder.withValue(Tasks.CREATED, task.createdAt);
    if (task.lastModified != null)
        builder.withValue(Tasks.LAST_MODIFIED, task.lastModified);

    if (task.dtStart != null)
        builder.withValue(Tasks.DTSTART, task.dtStart.getDate().getTime());
    if (task.due != null)
        builder.withValue(Tasks.DUE, task.due.getDate().getTime());
    if (task.duration != null)
        builder.withValue(Tasks.DURATION, task.duration.getValue());

    if (!task.getRDates().isEmpty())
        try {
            builder.withValue(Tasks.RDATE, DateUtils.recurrenceSetsToAndroidString(task.getRDates(), allDay));
        } catch (ParseException e) {
            Log.e(TAG, "Couldn't parse RDate(s)", e);
        }
    if (!task.getExDates().isEmpty())
        try {
            builder.withValue(Tasks.EXDATE, DateUtils.recurrenceSetsToAndroidString(task.getExDates(), allDay));
        } catch (ParseException e) {
            Log.e(TAG, "Couldn't parse ExDate(s)", e);
        }
    if (task.rRule != null)
        builder.withValue(Tasks.EXDATE, task.rRule.getValue());
}