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:info.rmapproject.core.model.impl.openrdf.ORMapDiscoTest.java

/**
 * Test method for {@link info.rmapproject.core.model.impl.openrdf.ORMapDiSCO#ORMapDiSCO(RMapIri, java.util.List)}.
 * @throws RMapDefectiveArgumentException 
 * @throws RMapException //from   ww  w  .ja v  a2 s .  com
 */
@Test
public void testORMapDiSCORMapResourceListOfURI() throws RMapException, RMapDefectiveArgumentException {
    List<java.net.URI> resourceList = new ArrayList<java.net.URI>();
    try {
        resourceList.add(new java.net.URI("http://rmap-info.org"));
        resourceList.add(new java.net.URI("https://rmap-project.atlassian.net/wiki/display/RMAPPS/RMap+Wiki"));
        RMapIri author = ORAdapter.openRdfIri2RMapIri(creatorIRI);
        ORMapDiSCO disco = new ORMapDiSCO(author, resourceList);
        assertEquals(author.toString(), disco.getCreator().getStringValue());
        List<Statement> resources = disco.getAggregatedResourceStatements();
        assertEquals(2, resources.size());
        Model model = new LinkedHashModel();
        model.addAll(resources);
        Set<IRI> predicates = model.predicates();
        assertEquals(1, predicates.size());
        assertTrue(predicates.contains(ORE.AGGREGATES));
        Set<Value> objects = model.objects();
        assertTrue(objects.contains(r));
        assertTrue(objects.contains(r2));
        Statement cstmt = disco.getCreatorStmt();
        assertEquals(DCTERMS.CREATOR, cstmt.getPredicate());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }

}

From source file:com.Upwork.api.OAuthClient.java

/**
 * Send signed GET OAuth request/*from www  .  jav  a  2  s . co  m*/
 * 
 * @param   url Relative URL
 * @param   type Type of HTTP request (HTTP method)
 * @param   params Hash of parameters
 * @throws   JSONException If JSON object is invalid or request was abnormal
 * @return   {@link JSONObject} JSON Object that contains data from response
 * */
private JSONObject sendGetRequest(String url, Integer type, HashMap<String, String> params)
        throws JSONException {
    String fullUrl = getFullUrl(url);
    HttpGet request = new HttpGet(fullUrl);

    if (params != null) {
        URI uri;
        String query = "";
        try {
            URIBuilder uriBuilder = new URIBuilder(request.getURI());

            // encode values and add them to the request
            for (Map.Entry<String, String> entry : params.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                // to prevent double encoding, we need to create query string ourself
                // uriBuilder.addParameter(key, URLEncoder.encode(value).replace("%3B", ";"));
                query = query + key + "=" + value.replace("&", "&amp;") + "&";
                // what the hell is going on in java - no adequate way to encode query string
                // lets temporary replace "&" in the value, to encode it manually later
            }
            // this routine will encode query string
            uriBuilder.setCustomQuery(query);
            uri = uriBuilder.build();

            // re-create request to have validly encoded ampersand
            request = new HttpGet(fullUrl + "?" + uri.getRawQuery().replace("&amp;", "%26"));
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        mOAuthConsumer.sign(request);
    } catch (OAuthException e) {
        e.printStackTrace();
    }

    return UpworkRestClient.getJSONObject(request, type);
}

From source file:io.wcm.caravan.io.http.impl.servletclient.HttpServletRequestMapper.java

@Override
public Map<String, String[]> getParameterMap() {
    try {//from w w w .j  a  va 2 s .  c om
        List<NameValuePair> pairs = URLEncodedUtils.parse(new URI(request.getUrl()), Charsets.UTF_8.toString());
        Map<String, Collection<String>> multiMap = Observable.from(pairs)
                .toMultimap(NameValuePair::getName, NameValuePair::getValue).toBlocking().single();
        Builder<String, String[]> builder = ImmutableMap.builder();
        multiMap.entrySet().stream().forEach(entry -> {
            String[] arrayValue = entry.getValue().toArray(new String[entry.getValue().size()]);
            builder.put(entry.getKey(), arrayValue);
        });
        return builder.build();
    } catch (URISyntaxException ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:org.fusesource.cloudmix.agent.karaf.KarafAgent.java

@Override
public AgentDetails updateAgentDetails() {
    AgentDetails rc = super.updateAgentDetails();

    try {/*from ww  w .jav  a  2s .c  o m*/
        getClient().updateAgentDetails(getAgentId(), getAgentDetails());
    } catch (URISyntaxException e) {
        LOGGER.info("Problem updating agent information ", e);
        e.printStackTrace();
    }
    return rc;
}

From source file:cc.arduino.mvd.services.XivelyService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {

        apiKey = intent.getStringExtra(MvdServiceReceiver.EXTRA_SERVICE_API_KEY);

        feedId = intent.getStringExtra(MvdServiceReceiver.EXTRA_SERVICE_FEED_ID);

        mqtt = new MQTT();

        try {//ww  w  .  j  a  va2  s  . c  o m
            mqtt.setHost(host, port);

            mqtt.setUserName(apiKey);

            connection = mqtt.callbackConnection();

            connection.listener(mqttListener);

            connection.connect(mqttCallback);

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

        if (DEBUG) {
            Log.d(TAG, TAG + " started.");
        }
    }

    return START_STICKY;
}

From source file:com.xebialabs.xlt.ci.server.XLTestServerImpl.java

@Override
public void uploadTestRun(String testSpecificationId, FilePath workspace, String includes, String excludes,
        Map<String, Object> metadata, PrintStream logger) throws IOException, InterruptedException {
    if (testSpecificationId == null || testSpecificationId.isEmpty()) {
        throw new IllegalArgumentException(
                "No test specification id specified. Does the test specification still exist in XL TestView?");
    }//from   w  ww. j  ava2s . co  m
    try {
        logInfo(logger,
                format("Collecting files from '%s' using include pattern: '%s' and exclude pattern '%s'",
                        workspace.getRemote(), includes, excludes));

        DirScanner scanner = new DirScanner.Glob(includes, excludes);

        ObjectMapper objectMapper = new ObjectMapper();

        RequestBody body = new MultipartBuilder().type(MultipartBuilder.MIXED)
                .addPart(RequestBody.create(MediaType.parse(APPLICATION_JSON_UTF_8),
                        objectMapper.writeValueAsString(metadata)))
                .addPart(new ZipRequestBody(workspace, scanner, logger)).build();

        Request request = new Request.Builder()
                .url(createSensibleURL(API_IMPORT + "/" + testSpecificationId, serverUrl))
                .header("User-Agent", getUserAgent()).header("Accept", APPLICATION_JSON_UTF_8)
                .header("Authorization", createCredentials()).header("Transfer-Encoding", "chunked").post(body)
                .build();

        Response response = client.newCall(request).execute();
        ObjectMapper mapper = createMapper();
        ImportError importError;
        switch (response.code()) {
        case 200:
            logInfo(logger, "Sent data successfully");
            return;
        case 304:
            logWarn(logger, "No new results were detected. Nothing was imported.");
            throw new IllegalStateException("No new results were detected. Nothing was imported.");
        case 400:
            importError = mapper.readValue(response.body().byteStream(), ImportError.class);
            throw new IllegalStateException(importError.getMessage());
        case 401:
            throw new AuthenticationException(String.format(
                    "User '%s' and the supplied password are unable to log in", credentials.getUsername()));
        case 402:
            throw new PaymentRequiredException("The XL TestView server does not have a valid license");
        case 404:
            throw new ConnectionException("Cannot find test specification '" + testSpecificationId
                    + ". Please check if the XL TestView server is "
                    + "running and the test specification exists.");
        case 422:
            logWarn(logger, "Unable to process results.");
            logWarn(logger,
                    "Are you sure your include/exclude pattern provides all needed files for the test tool?");
            importError = mapper.readValue(response.body().byteStream(), ImportError.class);
            throw new IllegalStateException(importError.getMessage());
        default:
            throw new IllegalStateException("Unknown error. Status code: " + response.code()
                    + ". Response message: " + response.toString());
        }
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    } catch (IOException e) {
        e.printStackTrace();
        LOG.warn("I/O error uploading test run data to {} {}\n{}", serverUrl.toString(), e.toString(), e);
        throw new IOException(
                "I/O error uploading test run data to " + serverUrl.toString() + " " + e.toString(), e);
    }
}

From source file:org.rifidi.designer.library.basemodels.antennafield.AntennaFieldEntity.java

private void prepare() {
    if (fieldModel == null) {
        URI modelpath = null;/*from   ww w .  j  a v  a 2  s . co m*/
        try {
            modelpath = getClass().getClassLoader()
                    .getResource("org/rifidi/designer/library/basemodels/antennafield/field.jme").toURI();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        try {
            fieldModel = (Node) BinaryImporter.getInstance().load(modelpath.toURL());
        } catch (MalformedURLException e) {
            logger.fatal(e);
        } catch (IOException e) {
            logger.fatal(e);
        }
    }
    as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
    as.setBlendEnabled(true);
    as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
    as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_COLOR);
    as.setEnabled(true);
    // create material and alpha states for the field
    ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
    ms.setDiffuse(new ColorRGBA(.1f, .1f, .1f, .1f));
}

From source file:com.facebook.android.MainPage.java

/** Called when the activity is first created. */
@Override/*  w  w w  .  j a v a2s .  c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see Example.java");
    }

    setContentView(R.layout.main);
    mMovieNameInput = (EditText) findViewById(R.id.title);
    mMediaSpinner = (Spinner) findViewById(R.id.media);
    mSearchButton = (Button) findViewById(R.id.search);
    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    // set up the Spinner for the media list selection
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.media_list,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mMediaSpinner.setAdapter(adapter);

    //for search button         
    final Context context = this;
    mSearchButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            String servletURL;
            String movieName = mMovieNameInput.getText().toString();
            // check the input text of movie, if the text is empty give user alert
            movieName = movieName.trim();
            if (movieName.length() == 0) {
                Toast toast = Toast.makeText(context, "Please enter a movie name", Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 70);
                toast.show();
            }
            // if movie name is not empty
            else {
                // remove any extra whitespace
                movieName = movieName.replaceAll("\\s+", "+");
                String mediaList = mMediaSpinner.getSelectedItem().toString();
                if (mediaList.equals("Feature Film")) {
                    mediaList = "feature";
                }
                mediaList = mediaList.replaceAll("\\s+", "+");
                // construct the query string
                // construct the final URL to Servlet
                //String servletString = "?" + "title=" + movieName + "&" + "title_type=" + mediaList;
                //servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie"
                //+ servletString;
                //String servletString = "?" + "title=" + movieName + "&" + "media=" + mediaList;
                //servletURL = "http://cs-server.usc.edu:34404/examples/servlet/HelloWorldExample?title=" + movieName + "&" + "media=" + mediaList;
                //+ servletString;
                servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie?title=" + movieName + "&"
                        + "title_type=" + mediaList;
                BufferedReader in = null;
                try {
                    // REFERENCE: this part of code is modified from:
                    // "Example of HTTP GET Request using HttpClient in Android"
                    // http://w3mentor.com/learn/java/android-development/android-http-services/example-of-http-get-request-using-httpclient-in-android/
                    // get response (JSON string) from Servlet 
                    HttpClient client = new DefaultHttpClient();
                    HttpGet request = new HttpGet();
                    request.setURI(new URI(servletURL));
                    HttpResponse response = client.execute(request);
                    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                    StringBuffer sb = new StringBuffer("");
                    String line = "";
                    String NL = System.getProperty("line.separator");
                    while ((line = in.readLine()) != null) {
                        sb.append(line + NL);
                    }
                    in.close();
                    String page = sb.toString();
                    //test for JSON string
                    /*LinearLayout lView = new LinearLayout(context);
                    TextView myText = new TextView(context);
                    myText.setText(page);
                    lView.addView(myText);
                    setContentView(lView);*/

                    // convert the JSON string to real JSON and get out the movie JSON array
                    // to check if there is any movie data
                    JSONObject finalJson;
                    JSONObject movieJson;
                    JSONArray movieJsonArray;
                    finalJson = new JSONObject(page);
                    movieJson = finalJson.getJSONObject("results");
                    //System.out.println(movieJson);
                    movieJsonArray = movieJson.getJSONArray("result");

                    // if the response contains some movie data
                    if (movieJsonArray.length() != 0) {

                        // start the ListView activity, and pass the JSON string to it
                        Intent intent = new Intent(context, MovieListActivity.class);
                        intent.putExtra("finalJson", page);
                        startActivity(intent);
                    }
                    // if the response does not contain any movie data,
                    // show user that there is no result for this search
                    else {
                        Toast toast = Toast.makeText(getBaseContext(), "No movie found for this search",
                                Toast.LENGTH_LONG);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                    }
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    });
}

From source file:iristk.speech.nuancecloud.NuanceCloudRecognizerListener.java

private void initRequest() {
    try {//from   w  w w. j  a v a  2 s .c o  m
        speechQueue.reset();

        InputStream inputStream;
        String codec;

        if (!(audioFormat.getSampleRate() == 8000 || audioFormat.getSampleRate() == 16000)) {
            System.err.println("Error: NuanceCloudRecognizer must get 8 or 16 Khz audio, not "
                    + audioFormat.getSampleRate());
        }

        if (useSpeex) {
            encodedQueue.reset();
            JSpeexEnc encoder = new JSpeexEnc((int) audioFormat.getSampleRate());
            encoder.startEncoding(speechQueue, encodedQueue);
            inputStream = encodedQueue.getInputStream();
            codec = "audio/x-speex;rate=" + (int) audioFormat.getSampleRate();
        } else {
            inputStream = speechQueue.getInputStream();
            codec = "audio/x-wav;codec=pcm;bit=16;rate=" + (int) audioFormat.getSampleRate();
        }

        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("appId", license.getAppId()));
        qparams.add(new BasicNameValuePair("appKey", license.getAppKey()));
        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(inputStream, -1);
        reqEntity.setContentType(codec);

        httppost.setEntity(reqEntity);

        postThread = new PostThread(httppost);

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

From source file:org.xwiki.android.rest.HttpConnector.java

/**
 * Perform HTTP Delete method execution and return its status
 * /*www . j a v a  2  s. c  o m*/
 * @param Uri URL of XWiki RESTful API
 * @return status of the HTTP method execution
 */
public String deleteRequest(String Uri) {
    initialize();

    HttpDelete request = new HttpDelete();

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

    setCredentials();

    request.setURI(requestUri);
    Log.d("Request URL", Uri);

    try {

        response = client.execute(request);
        Log.d("Response status", response.getStatusLine().toString());
        return response.getStatusLine().toString();

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

    return "error";
}