List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:io.datenwelt.cargo.rest.Request.java
public Request(HttpServletRequest servletRequest, List<ContentType> supportedContentTypes, List<ContentEncoding> supportedContentEncodings) throws APIException { this.servletRequest = servletRequest; this.supportedContentTypes = supportedContentTypes; this.supportedContentEncodings = supportedContentEncodings; this.method = servletRequest.getMethod(); this.path = Segment.normalize(servletRequest.getPathInfo()); StringBuffer url = servletRequest.getRequestURL(); String query = servletRequest.getQueryString(); if (query != null && !query.isEmpty()) { url.append("?").append(query); }/*from w w w . ja va 2 s . com*/ // Parse request URI and construct the base URI. try { requestURI = new URI(url.toString()); String basePath = (servletRequest.getContextPath() == null ? "" : servletRequest.getContextPath()) + (servletRequest.getServletPath() == null ? "" : servletRequest.getServletPath()); baseURI = URI.create(new StringBuffer().append(requestURI.getScheme()).append("://") .append(requestURI.getRawAuthority()).append("/").append(basePath).toString()); path = Segment.normalize(requestURI.getPath()); if (path.startsWith(basePath)) { path = path.substring(basePath.length()); } } catch (URISyntaxException ex) { throw new APIException(new InternalServerError(), "Unable to parse request URI from string '" + requestURI + "'. Using defaut value for base URI. Error: " + ex.getMessage(), ex); } // Parse query string. String queryString = servletRequest.getQueryString(); this.queries.addAll(Query.parseQueryString(queryString)); // Parse header values Enumeration headerNames = servletRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement().toString(); Enumeration values = servletRequest.getHeaders(name); while (values.hasMoreElements()) { Header header = headers.get(name); if (header == null) { header = new Header(name); headers.put(header.getName(), header); } String value = values.nextElement().toString(); header.add(Header.decode(name, value)); } } // Collect infos about the remote end. remoteAddress = servletRequest.getRemoteAddr(); remoteHost = servletRequest.getRemoteHost(); remotePort = servletRequest.getRemotePort(); }
From source file:com.trellmor.berrymotes.sync.SubredditEmoteDownloader.java
@Override public void run() { try {/*from w w w . jav a 2 s . c om*/ List<EmoteImage> emotes = this.getEmoteList(); if (emotes != null) { this.downloadEmotes(emotes); this.updateEmotes(emotes); // If everything is ok, update the last modified date if (!mSyncResult.hasError()) { Log.info("Updating LAST_MODIFIED time to " + mLastModified.toString()); PreferenceManager.getDefaultSharedPreferences(mContext).edit() .putLong(SettingsActivity.KEY_SYNC_LAST_MODIFIED + mSubreddit, mLastModified.getTime()) .commit(); } } } catch (URISyntaxException e) { Log.error("Emotes URL is malformed", e); mSyncResult.stats.numParseExceptions++; mSyncResult.delayUntil = 60 * 60; return; } catch (IOException e) { Log.error("Error reading from network: " + e.getMessage(), e); mSyncResult.stats.numIoExceptions++; mSyncResult.delayUntil = 30 * 60; return; } catch (RemoteException e) { Log.error("Error updating database: " + e.getMessage(), e); mSyncResult.databaseError = true; } catch (OperationApplicationException e) { Log.error("Error updating database: " + e.getMessage(), e); mSyncResult.databaseError = true; } catch (InterruptedException e) { Log.info("Sync interrupted"); mSyncResult.moreRecordsToGet = true; Thread.currentThread().interrupt(); } finally { mEmoteDownloader.updateSyncResult(mSyncResult); } }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private ResolvedRepositoryData resolveTargetRepository(RequestMethod method, HttpServletRequest req) throws IOException { ResolvedRepositoryData repoData = new ResolvedRepositoryData(); String op = StringUtils.trimToEmpty(req.getParameter("service")), uriPath = req.getPathInfo(); if (StringUtils.isEmpty(op)) { int pos = uriPath.lastIndexOf('/'); if ((pos > 0) && (pos < (uriPath.length() - 1))) { op = uriPath.substring(pos + 1); }/*from w w w . j a va2 s. c o m*/ } if (!ALLOWED_SERVICES.contains(op)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new UnsupportedOperationException("Unsupported operation: " + op)); } repoData.setOperation(op); String repoName = extractRepositoryName(uriPath); if (StringUtils.isEmpty(repoName)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new IllegalArgumentException("Failed to extract repo name from " + uriPath)); } repoData.setRepoName(repoName); // TODO access an injected resolver that returns the back-end location URL String query = req.getQueryString(); try { if (StringUtils.isEmpty(query)) { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath)); } else { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath + "?" + query)); } } catch (URISyntaxException e) { throw new MalformedURLException(e.getClass().getSimpleName() + ": " + e.getMessage()); } return repoData; }
From source file:org.hfoss.posit.android.sync.Communicator.java
/** * Sends a HttpPost request to the given URL. Any JSON * //from w w w . j av a2 s. c o m * @param Uri, the URL to send to/receive from * @param pairs, a list of attribute/value pairs * @return the response from the URL */ public static String doHTTPPost(String Uri, List<NameValuePair> pairs) { BasicHttpParams mHttpParams = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. HttpConnectionParams.setConnectionTimeout(mHttpParams, CONNECTION_TIMEOUT); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(mHttpParams, SOCKET_TIMEOUT); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); ThreadSafeClientConnManager mConnectionManager = new ThreadSafeClientConnManager(mHttpParams, registry); DefaultHttpClient mHttpClient = new DefaultHttpClient(mConnectionManager, mHttpParams); if (Uri == null) throw new NullPointerException("The URL has to be passed"); String responseString = null; HttpPost post = new HttpPost(); 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(); } ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, "UnsupportedEncodingException " + e.getMessage()); return "[Error] " + e.getMessage(); } 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(); } Log.i(TAG, "doHTTPpost response = " + responseString); return responseString; }
From source file:com.vmware.appfactory.application.controller.AppApiController.java
/** * Step 2: Upload the installer and create the new file share application. * * Failure or success will respond with a json with a success flag. The Http status type does not * matter much, as this response is recieved in an iframe, and is not transposed over to the js callback. * * Docs: http://jquery.malsup.com/form/#file-upload * * @param uploadFile - multipart file being uploaded. * @param request - HttpServletRequest/*w ww.j ava2s . c o m*/ */ @ResponseBody @RequestMapping(value = "/apps/upload", method = RequestMethod.POST) public ResponseEntity<String> uploadAndCreate(@RequestParam("uploadFile") MultipartFile uploadFile, HttpServletRequest request) { ApplicationCreateRequest uploadApp = null; try { // Load and validate required fields. uploadApp = loadSessionUploadApp(uploadFile, request); final List<String> installerDirs = generateFolderNameListForUploadApp(uploadApp); // Get the destination ds and copy the installer. DsDatastore ds = _dsClient.findDatastore(uploadApp.getDsId(), true); // Developer mode! Copy the upload file to a local directory. if (_af.isDevModeDeploy() && StringUtils.isNotEmpty(_af.getDevModeUploadDir())) { // Path to file's directory String newPath = _af.getDevModeUploadDir(); for (String dir : installerDirs) { newPath = FileHelper.constructFilePath2(File.separator, newPath, dir); } FileUtils.forceMkdir(new File(newPath)); // Full path to file String newFile = FileHelper.constructFilePath2(File.separator, newPath, uploadFile.getOriginalFilename()); _log.debug("DEV MODE! Uploading " + uploadFile.getOriginalFilename() + " size " + uploadFile.getSize() + " to " + newFile); // Copy it uploadFile.transferTo(new File(newFile)); } else { // Production mode! Copy the upload file to the datastore. // Full path to directory where file will be copied to. String destFile = ds.createDirsIfNotExists(installerDirs.toArray(new String[installerDirs.size()])); destFile = destFile + uploadFile.getOriginalFilename(); _log.debug("Uploading " + uploadFile.getOriginalFilename() + " size " + uploadFile.getSize() + " to " + destFile); ds.copy(uploadFile, destFile, null); } // create the application now that uploaded installer has been copied. createUploadApp(installerDirs, uploadFile.getOriginalFilename(), request, uploadApp); _log.info("upload file & app: {} creation complete.", uploadApp.getAppName()); return respondUploadMessage("Installer was uploaded and saved.", true, request); } catch (AfBadRequestException e) { _log.error("Saving file to ds error: " + e.getMessage(), e); return respondUploadMessage("Selected datastore couldnt not be accessed.", false, request); } catch (URISyntaxException urie) { _log.error("Application create error: " + urie.getMessage(), urie); return respondUploadMessage("Saving the application after installer upload failed.", false, request); } catch (IllegalStateException e) { _log.error("Save file to ds error: " + e.getMessage(), e); return respondUploadMessage("Installer couldnt be saved onto the datastore.", false, request); } catch (IOException e) { _log.error("Create folder /save file to ds error: " + e.getMessage(), e); return respondUploadMessage("Installer couldnt be saved onto the datastore.", false, request); } catch (DsException ds) { _log.error("Saving file to ds error: " + ds.getMessage(), ds); return respondUploadMessage("Selected datastore could not be accessed.", false, request); } catch (RuntimeException rts) { // This is the default runtime exception case that needs to be handled. The client handler can only // handle json response, and hence we catch all other runtime exceptions here. _log.error("Uploading installer failed with error: " + rts.getMessage(), rts); return respondUploadMessage("Uploading and creating an application failed.", false, request); } finally { if (uploadApp != null) { // Cleanup the progress listener session variable. ProgressReporter.removeProgressListener(request, uploadApp.getUploadId()); } } }
From source file:nl.nn.adapterframework.extensions.tibco.GetTibcoQueues.java
private String getResolvedUrl(String url) { URI uri = null;//from ww w . j ava2 s.com try { uri = new URI(url); } catch (URISyntaxException e) { log.debug("Caught URISyntaxException while resolving url [" + url + "]: " + e.getMessage()); return null; } InetAddress inetAddress = null; try { inetAddress = InetAddress.getByName(uri.getHost()); } catch (UnknownHostException e) { log.debug("Caught UnknownHostException while resolving url [" + url + "]: " + e.getMessage()); return null; } return inetAddress.getCanonicalHostName(); }
From source file:com.aliyun.odps.rest.RestClient.java
private Request buildRequest(String resource, String method, Map<String, String> params, Map<String, String> headers) throws OdpsException { if (resource == null || !resource.startsWith("/")) { throw new OdpsException("Invalid resource: " + resource); }/*from w w w . j ava 2 s . co m*/ if (endpoint == null) { throw new OdpsException("Odps endpoint required."); } Request req = new Request(this); // build URL with parameters StringBuilder url = new StringBuilder(); url.append(endpoint).append(resource); if (params == null) { params = new HashMap<String, String>(); } if (!params.containsKey("curr_project") && defaultProject != null) { params.put("curr_project", defaultProject); } if (params.size() != 0) { req.setParameters(params); url.append('?'); boolean first = true; for (Entry<String, String> kv : params.entrySet()) { if (first) { first = false; } else { url.append('&'); } String key = kv.getKey(); String value = kv.getValue(); url.append(key); if (value != null && value.length() > 0) { value = ResourceBuilder.encode(value); url.append('=').append(value); } } } try { req.setURI(new URI(url.toString())); req.setMethod(Method.valueOf(method)); if (headers != null) { req.setHeaders(headers); } // set User-Agent if (req.getHeaders().get(Headers.USER_AGENT) == null && userAgent != null) { req.setHeader(Headers.USER_AGENT, userAgent); req.setHeader("x-odps-user-agent", userAgent); } req.getHeaders().put("Date", DateUtils.formatRfc822Date(new Date())); // Sign the request account.getRequestSigner().sign(resource, req); } catch (URISyntaxException e) { throw new OdpsException(e.getMessage(), e); } return req; }
From source file:com.activiti.service.activiti.ActivitiClientService.java
public URIBuilder createUriBuilder(String url) { try {/*from ww w. ja v a2s . c om*/ return new URIBuilder(url); } catch (URISyntaxException e) { throw new ActivitiServiceException("Error while creating Activiti endpoint URL: " + e.getMessage()); } }
From source file:com.activiti.service.activiti.ActivitiClientService.java
public String getServerUrl(ServerConfig serverConfig, URIBuilder builder) { try {// w w w .j a v a 2s .c o m return getServerUrl(serverConfig, builder.build().toString()); } catch (URISyntaxException e) { throw new ActivitiServiceException("Error while creating Activiti endpoint URL: " + e.getMessage()); } }