List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:com.marklogic.contentpump.ImportRecordReader.java
/** * Apply URI replace option, encode URI if specified, apply URI prefix and * suffix configuration options and set the result as DocumentURI key. * /*from w ww .j a v a 2 s . co m*/ * @param uri Source string of document URI. * @param line Line number in the source if applicable; 0 otherwise. * @param col Column number in the source if applicable; 0 otherwise. * @param encode Encode uri if set to true. * * @return true if key indicates the record is to be skipped; false * otherwise. */ protected boolean setKey(String uri, int line, int col, boolean encode) { if (key == null) { key = new DocumentURIWithSourceInfo(uri, srcId); } // apply prefix, suffix and replace for URI if (uri != null && !uri.isEmpty()) { uri = URIUtil.applyUriReplace(uri, conf); key.setSkipReason(""); if (encode) { try { URI uriObj = new URI(null, null, null, 0, uri, null, null); uri = uriObj.toString(); } catch (URISyntaxException e) { uri = null; key.setSkipReason(e.getMessage()); } } uri = URIUtil.applyPrefixSuffix(uri, conf); } else { key.setSkipReason("empty uri value"); } key.setUri(uri); key.setSrcId(srcId); key.setSubId(subId); key.setColNumber(col); key.setLineNumber(line); if (LOG.isTraceEnabled()) { LOG.trace("Set key: " + key); } return key.isSkip(); }
From source file:ph.com.globe.connect.Subscriber.java
/** * Get subscriber balance request./*www. j av a 2 s . c o m*/ * * @param address subscriber address * @return HttpResponse * @throws ApiException api exception * @throws HttpRequestException http request exception * @throws HttpResponseException http response exception */ public HttpResponse getSubscriberBalance(String address) throws ApiException, HttpRequestException, HttpResponseException { // set request url String url = this.SUBSCRIBER_URL; // build url try { // initialize url builder URIBuilder builder = new URIBuilder(url); // set access token parameter builder.setParameter("access_token", this.accessToken); // set the address builder.setParameter("address", address); // build the url url = builder.build().toString(); } catch (URISyntaxException e) { // throw exception throw new ApiException(e.getMessage()); } // send request CloseableHttpResponse results = this.request // set url .setUrl(url) // send get request .sendGet(); return new HttpResponse(results); }
From source file:ph.com.globe.connect.Subscriber.java
/** * Get subscriber reload amount./*from www .j a va 2 s .c o m*/ * * @param address subscriber address * @return HttpResponse * @throws ApiException api exception * @throws HttpRequestException http request exception * @throws HttpResponseException http response exception */ public HttpResponse getSubscriberReloadAmount(String address) throws ApiException, HttpRequestException, HttpResponseException { // set request url String url = this.SUBSCRIBER_RA_URL; // build url try { // initialize url builder URIBuilder builder = new URIBuilder(url); // set access token parameter builder.setParameter("access_token", this.accessToken); // set the address builder.setParameter("address", address); // build the url url = builder.build().toString(); } catch (URISyntaxException e) { // throw exception throw new ApiException(e.getMessage()); } // send request CloseableHttpResponse results = this.request // set url .setUrl(url) // send get request .sendGet(); return new HttpResponse(results); }
From source file:clj_httpc.CustomRedirectStrategy.java
public URI getLocationURI(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); }//from www . jav a 2s.c om //get the location header to find out where to redirect to Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); } String location = locationHeader.getValue(); if (this.log.isDebugEnabled()) { this.log.debug("Redirect requested to location '" + location + "'"); } URI uri = createLocationURI(location); HttpParams params = response.getParams(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target == null) { throw new IllegalStateException("Target host not available " + "in the HTTP context"); } try { URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { CustomRedirectLocations redirectLocations = (CustomRedirectLocations) context .getAttribute(REDIRECT_LOCATIONS); if (redirectLocations == null) { redirectLocations = new CustomRedirectLocations(); context.setAttribute(REDIRECT_LOCATIONS, redirectLocations); } URI redirectURI; if (uri.getFragment() != null) { try { HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'"); } else { int statusCode = response.getStatusLine().getStatusCode(); redirectLocations.add(redirectURI, statusCode); } } return uri; }
From source file:org.wso2.carbon.appmgt.usage.publisher.APPMgtGoogleAnalayticsHandler.java
public boolean handleResponse(MessageContext messageContext) { /** TODO refactor so common parts with handleRequest are pulled out **/ Map headers = (Map) ((Axis2MessageContext) messageContext).getAxis2MessageContext() .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); /** Get document referer **/ String documentReferer = (String) headers.get(HttpHeaders.REFERER); if (isEmpty(documentReferer)) { documentReferer = ""; } else {/*w w w .ja va2 s. co m*/ try { documentReferer = new URI(documentReferer).getPath(); } catch (URISyntaxException e) { log.error(e.getMessage(), e); return true; } } /** Get invoked Application Name **/ String appName = APPMgtUsageUtils.getAppNameFromSynapseEnvironment(messageContext, documentReferer); String appBasedCookieName = COOKIE_NAME + "_" + appName; String cookieValue = (String) messageContext.getProperty(appBasedCookieName); if (cookieValue != null) { String cookieString = appBasedCookieName + "=" + cookieValue + "; " + "path=" + "/"; headers.put(HTTPConstants.HEADER_SET_COOKIE, cookieString); } return true; }
From source file:com.couchbase.sqoop.mapreduce.db.CouchbaseRecordReader.java
public CouchbaseRecordReader(final Class<T> inputClass, final CouchbaseInputSplit split, final Configuration conf, final CouchbaseConfiguration dbConfig, final String table) { this.inputClass = inputClass; this.conf = conf; this.dbConf = dbConfig; this.tableName = table; this.split = split; try {/*from w ww . jav a 2 s. c o m*/ final String user = dbConf.getUsername(); final String pass = dbConf.getPassword(); final String url = dbConf.getUrlProperty(); // final String passwordSecurely = new String(dbConfig.getConf().get(DBConfiguration.PASSWORD_PROPERTY)); // System.out.printf("CouchbaseRecorder: Found password %s", passwordSecurely); // final String passwordSecurely = new String(split.getJob().getCredentials() // .getSecretKey(CouchbaseRecordReader.PASSWORD_SECRET_KEY)); // pass = passwordSecurely; this.client = new TapClient(Arrays.asList(new URI(url)), user, pass); } catch (final URISyntaxException e) { CouchbaseRecordReader.LOG.error("Bad URI Syntax: " + e.getMessage()); client.shutdown(); } }
From source file:org.basinmc.maven.plugins.minecraft.AbstractArtifactMojo.java
/** * Fetches any resource from a remote HTTP server and stores it in a specified file. *///w ww . j a v a2s . com protected void fetch(@Nonnull URL url, @Nonnull Path target) throws IOException { try { this.fetch(url.toURI(), target); } catch (URISyntaxException ex) { throw new IOException("Invalid resource URI: " + ex.getMessage(), ex); } }
From source file:net.nologin.meep.pingly.service.runner.HTTPResponseProbeRunner.java
public void doRun(Context ctx) throws ProbeRunCancelledException { HTTPResponseProbe httpProbe = (HTTPResponseProbe) getProbe(); // if everything is configured properly if (StringUtils.isBlank(httpProbe.url)) { notifyFinishedWithFailure(ctx.getString(R.string.probe_run_HTTP_RESP_err_no_url)); return;/*from ww w . j a v a 2 s. c o m*/ } checkCancelled(); try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); // 'Starting request to: url' notifyUpdate(ctx.getString(R.string.probe_run_HTTP_RESP_reqstart, httpProbe.url)); request.setURI(new URI(httpProbe.url)); HttpResponse response = client.execute(request); // execute can take some time, check that the asynctask hasn't been checkCancelled in the meantime checkCancelled(); StatusLine sl = response.getStatusLine(); String statusCode = sl != null ? Integer.toString(sl.getStatusCode()) : ""; // 'Response Received (Status: 200)' notifyFinishedWithSuccess(ctx.getString(R.string.probe_run_HTTP_RESP_successmsg, statusCode)); } catch (URISyntaxException e) { // "Error parsing URL '${url}': ${exceptionmsg}" String msg = ctx.getString(R.string.probe_run_HTTP_RESP_err_invalid_url, httpProbe.url, e.getMessage()); notifyFinishedWithFailure(msg); } catch (UnknownHostException e) { // "Unknown Host: '${exceptionmsg}'" String msg = ctx.getString(R.string.probe_run_HTTP_RESP_err_unknownhost, httpProbe.url); notifyFinishedWithFailure(msg); } catch (HttpHostConnectException e) { // "Couldn't Connect: ${exceptionmsg}" (exception message is descriptive) String msg = ctx.getString(R.string.probe_run_HTTP_RESP_err_hostconnect, e.getMessage()); notifyFinishedWithFailure(msg); } catch (IOException e) { Log.w(PinglyConstants.LOG_TAG, e); String msg = ctx.getString(R.string.probe_run_general_err_io, e.getMessage()); notifyFinishedWithFailure(msg); } }
From source file:com.amos.tool.SelfRedirectStrategy.java
public URI getLocationURI(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { Args.notNull(request, "HTTP request"); Args.notNull(response, "HTTP response"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); //get the location header to find out where to redirect to final Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); }//from www . j a v a 2 s. c o m final String location = locationHeader.getValue(); if (this.log.isDebugEnabled()) { this.log.debug("Redirect requested to location '" + location + "'"); } final RequestConfig config = clientContext.getRequestConfig(); URI uri = createLocationURI(location.replaceAll(" ", "%20")); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI try { if (!uri.isAbsolute()) { if (!config.isRelativeRedirectsAllowed()) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI final HttpHost target = clientContext.getTargetHost(); Asserts.notNull(target, "Target host"); final URI requestURI = new URI(request.getRequestLine().getUri()); final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false); uri = URIUtils.resolve(absoluteRequestURI, uri); } } catch (final URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } RedirectLocations redirectLocations = (RedirectLocations) clientContext .getAttribute(HttpClientContext.REDIRECT_LOCATIONS); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations); } if (!config.isCircularRedirectsAllowed()) { if (redirectLocations.contains(uri)) { throw new CircularRedirectException("Circular redirect to '" + uri + "'"); } } redirectLocations.add(uri); return uri; }