List of usage examples for java.net URISyntaxException toString
public String toString()
From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java
private void initialiseFromOptions() { outputDirectory = options.parameter(this.getClass().getName(), "outputDirectory"); if (outputDirectory == null) outputDirectory = options.parameter("outputDirectory"); if (outputDirectory == null) outputDirectory = "."; outputFilename = options.parameter(this.getClass().getName(), "outputFilename"); if (outputFilename == null) outputFilename = "FeatureCatalogue"; docxTemplateFilePath = options.parameter(this.getClass().getName(), "docxTemplateFilePath"); if (docxTemplateFilePath == null) docxTemplateFilePath = options.parameter("docxTemplateFilePath"); // if no path is provided, use the directory of the default template if (docxTemplateFilePath == null) { docxTemplateFilePath = DOCX_TEMPLATE_URL; result.addDebug(this, 17, "docxTemplateFilePath", DOCX_TEMPLATE_URL); }// ww w . j av a2 s .co m String s = options.parameter(this.getClass().getName(), "inheritedProperties"); if (s != null && s.equals("true")) Inherit = true; s = options.parameter(this.getClass().getName(), "deleteXmlfile"); if (s != null && s.equals("true")) deleteXmlFile = true; s = options.parameter(this.getClass().getName(), "package"); if (s != null && s.length() > 0) Package = s; else Package = ""; s = options.parameter(this.getClass().getName(), "outputFormat"); if (s != null && s.length() > 0) OutputFormat = s; else OutputFormat = ""; s = options.parameter(this.getClass().getName(), "featureTerm"); if (s != null && s.length() > 0) featureTerm = s; s = options.parameter(this.getClass().getName(), "includeDiagrams"); if (s != null && s.equals("true")) includeDiagrams = true; s = options.parameter(this.getClass().getName(), PARAM_DONT_TRANSFORM); if (s != null && s.equals("true")) dontTransform = true; s = options.parameter(this.getClass().getName(), PARAM_INCLUDE_CODELIST_URI); if (s != null && s.equalsIgnoreCase("false")) includeCodelistURI = false; // TBD: one could check that input has actually loaded the diagrams; // however, in future a transformation could create images as well s = options.parameter(this.getClass().getName(), "includeVoidable"); if (s != null && s.equalsIgnoreCase("false")) includeVoidable = false; s = options.parameter(this.getClass().getName(), "includeTitle"); if (s != null && s.equalsIgnoreCase("false")) includeTitle = false; if (model != null) { encoding = model.characterEncoding(); } s = options.parameter(this.getClass().getName(), "xslTransformerFactory"); if (s != null && s.length() > 0) xslTransformerFactory = s; s = options.parameter(this.getClass().getName(), "xslhtmlFile"); if (s != null && s.length() > 0) xslhtmlfileName = s; s = options.parameter(this.getClass().getName(), "xslframeHtmlFileName"); if (s != null && s.length() > 0) xslframeHtmlFileName = s; s = options.parameter(this.getClass().getName(), "xslfoFile"); if (s != null && s.length() > 0) xslfofileName = s; s = options.parameter(this.getClass().getName(), "xslrtfFile"); if (s != null && s.length() > 0) xslrtffileName = s; s = options.parameter(this.getClass().getName(), "xsldocxFile"); if (s != null && s.length() > 0) xsldocxfileName = s; s = options.parameter(this.getClass().getName(), "xslxmlFile"); if (s != null && s.length() > 0) xslxmlfileName = s; /* * first check the xslt path setting(s), then anything that depends on * it for example the css path defaults to the xslt path */ s = options.parameter(this.getClass().getName(), "xsltPfad"); if (s != null && s.length() > 0) xsltPath = s; s = options.parameter(this.getClass().getName(), "xsltPath"); if (s != null && s.length() > 0) xsltPath = s; /* * check cssPath only after xslt path has been checked if no value is * provided for cssPath it defaults to the xslt path */ s = options.parameter(this.getClass().getName(), "cssPath"); if (s != null && s.length() > 0) { cssPath = s; } else { cssPath = xsltPath; } s = options.parameter(this.getClass().getName(), "lang"); if (s != null && s.length() > 0) lang = s; s = options.parameter(this.getClass().getName(), "noAlphabeticSortingForProperties"); if (s != null && s.trim().length() > 0) noAlphabeticSortingForProperties = s.trim(); s = options.parameter(this.getClass().getName(), "xslLocalizationUri"); if (s != null && s.length() > 0) { try { URI locXslUri; if (s.startsWith("http")) { locXslUri = new URI(s); } else { locXslUri = new URI(s); File f; if (!locXslUri.isAbsolute()) { f = new File(s); locXslUri = f.toURI(); } } hrefMappings.put(localizationXslDefaultUri, locXslUri); } catch (URISyntaxException e) { result.addError(this, 15, "xslLocalizationUri", s, e.toString()); } } s = options.parameter(this.getClass().getName(), "localizationMessagesUri"); if (s != null && s.length() > 0) { try { URI locMsgUri; if (s.startsWith("http")) { locMsgUri = new URI(s); } else { locMsgUri = new URI(s); File f; if (!locMsgUri.isAbsolute()) { f = new File(s); locMsgUri = f.toURI(); } } hrefMappings.put(localizationMessagesDefaultUri, locMsgUri); } catch (URISyntaxException e) { result.addError(this, 15, "localizationMessagesUri", s, e.toString()); } } }
From source file:org.mustard.util.HttpManager.java
private InputStream requestData(String url, ArrayList<NameValuePair> params, String attachmentParam, File attachment) throws IOException, MustardException, AuthException { URI uri;/*from w ww . java2s .c om*/ try { uri = new URI(url); } catch (URISyntaxException e) { throw new IOException("Invalid URL."); } if (MustardApplication.DEBUG) Log.d("HTTPManager", "Requesting " + uri); HttpPost post = new HttpPost(uri); HttpResponse response; // create the multipart request and add the parts to it MultipartEntity requestContent = new MultipartEntity(); long len = attachment.length(); InputStream ins = new FileInputStream(attachment); InputStreamEntity ise = new InputStreamEntity(ins, -1L); byte[] data = EntityUtils.toByteArray(ise); String IMAGE_MIME = attachment.getName().toLowerCase().endsWith("png") ? IMAGE_MIME_PNG : IMAGE_MIME_JPG; requestContent.addPart(attachmentParam, new ByteArrayBody(data, IMAGE_MIME, attachment.getName())); if (params != null) { for (NameValuePair param : params) { len += param.getValue().getBytes().length; requestContent.addPart(param.getName(), new StringBody(param.getValue())); } } post.setEntity(requestContent); Log.d("Mustard", "Length: " + len); if (mHeaders != null) { Iterator<String> headKeys = mHeaders.keySet().iterator(); while (headKeys.hasNext()) { String key = headKeys.next(); post.setHeader(key, mHeaders.get(key)); } } if (consumer != null) { try { consumer.sign(post); } catch (OAuthMessageSignerException e) { } catch (OAuthExpectationFailedException e) { } catch (OAuthCommunicationException e) { } } try { mClient.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, DEFAULT_POST_REQUEST_TIMEOUT); mClient.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, DEFAULT_POST_REQUEST_TIMEOUT); response = mClient.execute(post); } catch (ClientProtocolException e) { e.printStackTrace(); throw new IOException("HTTP protocol error."); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 401) { throw new AuthException(401, "Unauthorized: " + url); } else if (statusCode == 403 || statusCode == 406) { try { JSONObject json = null; try { json = new JSONObject(StreamUtil.toString(response.getEntity().getContent())); } catch (JSONException e) { throw new MustardException(998, "Non json response: " + e.toString()); } throw new MustardException(statusCode, json.getString("error")); } catch (IllegalStateException e) { throw new IOException("Could not parse error response."); } catch (JSONException e) { throw new IOException("Could not parse error response."); } } else if (statusCode != 200) { Log.e("Mustard", response.getStatusLine().getReasonPhrase()); throw new MustardException(999, "Unmanaged response code: " + statusCode); } return response.getEntity().getContent(); }
From source file:org.mumod.util.HttpManager.java
private InputStream requestData(String url, ArrayList<NameValuePair> params, String attachmentParam, File attachment) throws IOException, MustardException, AuthException { URI uri;/* w w w. jav a2 s . c o m*/ try { uri = new URI(url); } catch (URISyntaxException e) { throw new IOException("Invalid URL."); } if (MustardApplication.DEBUG) Log.d("HTTPManager", "Requesting " + uri); HttpPost post = new HttpPost(uri); HttpResponse response; // create the multipart request and add the parts to it MultipartEntity requestContent = new MultipartEntity(); long len = attachment.length(); InputStream ins = new FileInputStream(attachment); InputStreamEntity ise = new InputStreamEntity(ins, -1L); byte[] data = EntityUtils.toByteArray(ise); String IMAGE_MIME = attachment.getName().toLowerCase().endsWith("png") ? IMAGE_MIME_PNG : IMAGE_MIME_JPG; requestContent.addPart(attachmentParam, new ByteArrayBody(data, IMAGE_MIME, attachment.getName())); if (params != null) { for (NameValuePair param : params) { len += param.getValue().getBytes().length; requestContent.addPart(param.getName(), new StringBody(param.getValue())); } } post.setEntity(requestContent); Log.d("Mustard", "Length: " + len); if (mHeaders != null) { Iterator<String> headKeys = mHeaders.keySet().iterator(); while (headKeys.hasNext()) { String key = headKeys.next(); post.setHeader(key, mHeaders.get(key)); } } if (consumer != null) { try { consumer.sign(post); } catch (OAuthMessageSignerException e) { } catch (OAuthExpectationFailedException e) { } catch (OAuthCommunicationException e) { } } try { mClient.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, DEFAULT_POST_REQUEST_TIMEOUT); mClient.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, DEFAULT_POST_REQUEST_TIMEOUT); response = mClient.execute(post); } catch (ClientProtocolException e) { e.printStackTrace(); throw new IOException("HTTP protocol error."); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 401) { throw new AuthException(401, "Unauthorized: " + url); } else if (statusCode == 400 || statusCode == 403 || statusCode == 406) { try { JSONObject json = null; try { json = new JSONObject(StreamUtil.toString(response.getEntity().getContent())); } catch (JSONException e) { throw new MustardException(998, "Non json response: " + e.toString()); } throw new MustardException(statusCode, json.getString("error")); } catch (IllegalStateException e) { throw new IOException("Could not parse error response."); } catch (JSONException e) { throw new IOException("Could not parse error response."); } } else if (statusCode != 200) { Log.e("Mustard", response.getStatusLine().getReasonPhrase()); throw new MustardException(999, "Unmanaged response code: " + statusCode); } return response.getEntity().getContent(); }
From source file:xtremweb.dispatcher.HTTPHandler.java
/** * This handles incoming connections. This is inherited from * org.mortbay.jetty.Handler. This expects a POST parameter : * XWPostParams.COMMAND/*w w w . j a v a 2 s . c om*/ * @see xtremweb.communications.XWPostParams */ @Override public synchronized void handle(final String target, final Request baseRequest, final HttpServletRequest _request, final HttpServletResponse _response) throws IOException, ServletException { XMLRPCCommand command = null; final Logger logger = getLogger(); Table obj = null; dataUpload = null; request = _request; response = _response; response.setHeader("Access-Control-Allow-Origin", "*"); String reqUri = baseRequest.getRequestURI(); if (request.getUserPrincipal() == null) { logger.debug("Handling user principal = null"); } else { logger.debug("Handling user principal = " + request.getUserPrincipal().getName()); } logger.debug("Handling target = " + target); logger.finest("Handling request = " + request.getContentLength() + " " + request.getContentType()); logger.debug("Handling request auth = " + request.getAuthType()); logger.debug("Handling request user = " + request.getRemoteUser()); logger.debug("Handling parameter size = " + request.getParameterMap().size()); logger.debug("Handling query string = " + request.getQueryString()); logger.debug("Handling method = " + request.getMethod()); logger.debug("Request URI = " + reqUri); // logger.debug("Request server = " + request.getServerName()); // logger.debug("Request port = " + request.getServerPort()); // logger.debug("Authorization = " + // request.getHeader(HttpHeaders.AUTHORIZATION)); for (final Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) { logger.finest("parameter " + e.nextElement()); } for (final Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements();) { final String headerName = e.nextElement(); logger.finest("header " + headerName + " : " + request.getHeader(headerName)); } final Cookie[] cookies = request.getCookies(); logger.debug("cookies.length = " + (cookies == null ? "0" : cookies.length)); if (cookies != null) { for (int c = 0; c < cookies.length; c++) { final Cookie cookie = cookies[c]; logger.finest("cookie " + cookie.getName() + " : " + cookie.getValue()); } } if (request.getParameterMap().size() <= 0) { if (target.equals(PATH)) { logger.debug("redirecting to dashboard"); redirectPage(baseRequest, Resources.DASHBOARDHTML); return; } for (final Resources r : Resources.values()) { if (r.getName().compareToIgnoreCase(target) == 0) { logger.debug("redirecting to " + r); sendResource(r); return; } } } final HttpSession session = request.getSession(true); final String mandatingLogin = (request.getParameter(XWPostParams.XWMANDATINGLOGIN.toString()) != null ? request.getParameter(XWPostParams.XWMANDATINGLOGIN.toString()) : (String) session.getAttribute(XWPostParams.XWMANDATINGLOGIN.toString())); final String authState = (request.getParameter(XWPostParams.AUTH_STATE.toString()) != null ? request.getParameter(XWPostParams.AUTH_STATE.toString()) : (String) session.getAttribute(XWPostParams.AUTH_STATE.toString())); final String authEmail = (request.getParameter(XWPostParams.AUTH_EMAIL.toString()) != null ? request.getParameter(XWPostParams.AUTH_EMAIL.toString()) : (String) session.getAttribute(XWPostParams.AUTH_EMAIL.toString())); final String authId = (request.getParameter(XWPostParams.AUTH_IDENTITY.toString()) != null ? request.getParameter(XWPostParams.AUTH_IDENTITY.toString()) : (String) session.getAttribute(XWPostParams.AUTH_IDENTITY.toString())); getLogger().debug("oauthState = " + authState); getLogger().debug("oauthEmail= " + authEmail); getLogger().debug("oauthId= " + authId); final UserInterface user = getUser(); final Vector<String> paths = (Vector<String>) XWTools.split(target, "/"); logger.debug("paths.size() = " + paths.size()); URI baseUri = null; try { baseUri = new URI(Connection.httpsScheme() + "://" + XWTools.getHostName(request.getServerName()) + ":" + request.getServerPort()); } catch (final URISyntaxException e) { resetIdRpc(); throw new IOException(e); } if (target.compareToIgnoreCase(APIPATH) == 0) { resetIdRpc(); writeApi(user, baseUri); baseRequest.setHandled(true); return; } if (!target.equals(PATH)) { try { final IdRpc i = IdRpc.valueOf(paths.elementAt(0).toUpperCase()); waitIdRpc(i); } catch (final Exception e) { // let other handlers manage this (e.g. /stats, /openid) logger.debug("not handling " + reqUri); return; } } if (user == null) { resetIdRpc(); logger.debug("no credential found"); redirectPage(baseRequest, Resources.DASHBOARDHTML); return; } logger.debug("User = " + user.toString()); try { final boolean isMultipart = ServletFileUpload.isMultipartContent(request); logger.debug("Handling ismultipart = " + isMultipart); // // HTML form // if (isMultipart) { final List parts = servletUpload.parseRequest(request); logger.debug("parts.size = " + parts.size()); if (parts != null) { for (final Iterator it = parts.iterator(); it.hasNext();) { final FileItem item = (FileItem) it.next(); logger.debug("multipart item = " + item.getFieldName().toUpperCase()); try { logger.debug("XWPostParams.valueOf(" + item.getFieldName().toUpperCase() + ") = " + XWPostParams.valueOf(item.getFieldName().toUpperCase())); switch (XWPostParams.valueOf(item.getFieldName().toUpperCase())) { case DATAUID: reqUri += "/" + item.getString(); break; case DATAFILE: dataUpload = item; break; case DATASHASUM: dataUploadshasum = item.getString(); break; } } catch (final Exception e) { logger.exception(e); } } } } for (final Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) { logger.debug("parameter " + e.nextElement()); } for (final Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements();) { logger.debug("header " + e.nextElement()); } if (target.equals(PATH)) { sendDashboard(user); baseRequest.setHandled(true); return; } if (dataUpload != null) { final String value = request.getParameter(XWPostParams.DATASHASUM.toString()); if (value != null) { if (dataUploadshasum == null) { dataUploadshasum = value; } } logger.debug("Parameters upload size = " + dataUpload.getSize() + " dataUploadshasum = " + dataUploadshasum); } final Iterator<String> it = paths.iterator(); final StringBuilder uriWithoutCmd = new StringBuilder(); int i = 0; while (it.hasNext()) { final String st = it.next(); logger.debug("Parsing path path = " + st); if (i++ > 0) { uriWithoutCmd.append("/" + st); } } final URI uri = new URI(Connection.httpsScheme() + "://" + XWTools.getHostName(request.getServerName()) + ":" + request.getServerPort() + uriWithoutCmd.toString()); logger.debug("URI = " + uri); final String objXmlDesc = request.getParameter(XWPostParams.XMLDESC.toString()); logger.finest("objXmlDesc = " + objXmlDesc); if (objXmlDesc != null) { final ByteArrayInputStream in = new ByteArrayInputStream(objXmlDesc.getBytes()); try { obj = Table.newInterface(in); } finally { in.close(); } } if (obj != null) { logger.debug("obj = " + obj.toXml()); if (obj.getUID() == null) { obj.setUID(new UID()); } } else { logger.debug("obj = null"); } command = getIdRpc().newCommand(uri, user, obj); command.setMandatingLogin(mandatingLogin); final String parameter = request.getParameter(XWPostParams.PARAMETER.toString()); logger.debug("parameter = " + parameter); if (parameter != null) { switch (getIdRpc()) { case CHMOD: { final XWAccessRights ar = new XWAccessRights(parameter); ((XMLRPCCommandChmod) command).setModifier(ar); break; } case ACTIVATEHOST: { final Boolean b = new Boolean(parameter); ((XMLRPCCommandActivateHost) command).setActivation(b); break; } case WORKALIVE: { final XMLHashtable p = new XMLHashtable(StreamIO.stream(parameter)); logger.debug("XMLHastable = " + (p == null ? "null" : p.toXml())); ((XMLRPCCommandWorkAlive) command).setParameter(p); break; } default: break; } } command.getUser().setLogin(user.getLogin()); command.getUser().setPassword(user.getPassword()); command.getUser().setUID(user.getUID()); } catch (final Exception e) { command = null; logger.exception(e); logger.error(e.toString()); } try { if (command != null) { command.setRemoteName(request.getRemoteHost()); command.setRemoteIP(request.getRemoteAddr()); command.setRemotePort(request.getRemotePort()); logger.debug("cmd = " + command.toXml()); if (command.getIdRpc() == IdRpc.DOWNLOADDATA) { final UID uid = command.getURI().getUID(); String contentTypeValue = CONTENTTYPEVALUE; try { final DataInterface theData = DBInterface.getInstance().getData(command); final DataTypeEnum dataType = theData != null ? theData.getType() : null; final Date lastModified = theData != null ? theData.getMTime() : null; if (theData != null) { if (lastModified != null) { response.setHeader(LASTMODIFIEDLABEL, lastModified.toString()); } response.setHeader(CONTENTLENGTHLABEL, "" + theData.getSize()); response.setHeader(CONTENTSHASUMLABEL, theData.getShasum()); response.setHeader(CONTENTDISPOSITIONLABEL, "attachment; filename=\"" + theData.getName() + "\""); } if (dataType != null) { contentTypeValue = dataType.getMimeType(); } } catch (final Exception e) { if (logger.debug()) { logger.exception(e); } } logger.debug("set " + CONTENTTYPELABEL + " : " + contentTypeValue); response.setHeader(CONTENTTYPELABEL, contentTypeValue); } super.run(command); } else { write((XMLable) null); } } finally { command = null; obj = null; baseRequest.setHandled(true); notifyAll(); } }