List of usage examples for org.apache.commons.httpclient URI toString
@Override
public String toString()
From source file:org.parosproxy.paros.model.Session.java
/** * Returns the URL parameters for the given URL based on the parser associated with the * first context found that includes the URL, or the default parser if it is not * in a context/*from www . ja va 2 s. c om*/ * @param uri * @return * @throws URIException */ public Map<String, String> getUrlParams(URI uri) throws URIException { return this.getUrlParamParser(uri.toString()).parse(uri.getQuery()); }
From source file:org.parosproxy.paros.model.Session.java
/** * Returns the FORM parameters for the given URL based on the parser associated with the * first context found that includes the URL, or the default parser if it is not * in a context//from w w w .j a va 2 s .co m * @param uri * @param formData * @return * @throws URIException */ public Map<String, String> getFormParams(URI uri, String formData) throws URIException { return this.getFormParamParser(uri.toString()).parse(formData); }
From source file:org.parosproxy.paros.model.Session.java
public List<String> getTreePath(URI uri) throws URIException { return this.getUrlParamParser(uri.toString()).getTreePath(uri); }
From source file:org.parosproxy.paros.model.Session.java
public List<String> getTreePath(HttpMessage msg) throws URIException { URI uri = msg.getRequestHeader().getURI(); return this.getUrlParamParser(uri.toString()).getTreePath(msg); }
From source file:org.parosproxy.paros.model.SiteMap.java
/** * Add the HistoryReference with the corresponding HttpMessage into the SiteMap. * This method saves the msg to be read from the reference table. Use * this method if the HttpMessage is known. * Note that this method must only be called on the EventDispatchThread * @param msg/*from w w w. j a v a2 s . co m*/ * @return */ public SiteNode addPath(HistoryReference ref, HttpMessage msg) { if (Constant.isLowMemoryOptionSet()) { throw new InvalidParameterException("SiteMap should not be accessed when the low memory option is set"); } if (View.isInitialised() && Constant.isDevBuild() && !EventQueue.isDispatchThread()) { // In developer mode log an error if we're not on the EDT // Adding to the site tree on GUI ('initial') threads causes problems log.error("SiteMap.addPath not on EDT " + Thread.currentThread().getName(), new Exception()); } URI uri = msg.getRequestHeader().getURI(); log.debug("addPath " + uri.toString()); SiteNode parent = (SiteNode) getRoot(); SiteNode leaf = null; String folder = ""; try { String host = getHostName(uri); // add host parent = findAndAddChild(parent, host, ref, msg); List<String> path = model.getSession().getTreePath(msg); for (int i = 0; i < path.size(); i++) { folder = path.get(i); if (folder != null && !folder.equals("")) { if (i == path.size() - 1) { leaf = findAndAddLeaf(parent, folder, ref, msg); ref.setSiteNode(leaf); } else { parent = findAndAddChild(parent, folder, ref, msg); } } } if (leaf == null) { // No leaf found, which means the parent was really the leaf // The parent will have been added with a 'blank' href, so replace it with the real one parent.setHistoryReference(ref); leaf = parent; } } catch (Exception e) { // ZAP: Added error log.error("Exception adding " + uri.toString() + " " + e.getMessage(), e); } if (hrefMap.get(ref.getHistoryId()) == null) { hrefMap.put(ref.getHistoryId(), leaf); } return leaf; }
From source file:org.parosproxy.paros.network.HttpMethodHelper.java
public HttpMethod createRequestMethod(HttpRequestHeader header, HttpBody body) throws URIException { HttpMethod httpMethod = null;// ww w . j av a 2 s . c om String method = header.getMethod(); URI uri = header.getURI(); String version = header.getVersion(); if (method == null || method.trim().length() < 3) { throw new URIException("Invalid HTTP method: " + method); } if (method.equalsIgnoreCase(GET)) { //httpMethod = new GetMethod(); // ZAP: avoid discarding HTTP status code 101 that is used for WebSocket upgrade httpMethod = new ZapGetMethod(); } else if (method.equalsIgnoreCase(POST)) { httpMethod = new ZapPostMethod(); } else if (method.equalsIgnoreCase(DELETE)) { httpMethod = new ZapDeleteMethod(); } else if (method.equalsIgnoreCase(PUT)) { httpMethod = new ZapPutMethod(); } else if (method.equalsIgnoreCase(HEAD)) { httpMethod = new ZapHeadMethod(); } else if (method.equalsIgnoreCase(OPTIONS)) { httpMethod = new ZapOptionsMethod(); } else if (method.equalsIgnoreCase(TRACE)) { httpMethod = new ZapTraceMethod(uri.toString()); } else { httpMethod = new GenericMethod(method); } try { httpMethod.setURI(uri); } catch (Exception e1) { logger.error(e1.getMessage(), e1); } HttpMethodParams httpParams = httpMethod.getParams(); // default to use HTTP 1.0 httpParams.setVersion(HttpVersion.HTTP_1_0); if (version.equalsIgnoreCase(HttpHeader.HTTP11)) { httpParams.setVersion(HttpVersion.HTTP_1_1); } // set various headers int pos = 0; // ZAP: changed to always use CRLF, like the HttpHeader Pattern pattern = patternCRLF; String delimiter = header.getLineDelimiter(); // ZAP: Shouldn't happen as the HttpHeader always uses CRLF if (delimiter.equals(LF)) { delimiter = LF; pattern = patternLF; } String msg = header.getHeadersAsString(); String[] split = pattern.split(msg); String token = null; String name = null; String value = null; for (int i = 0; i < split.length; i++) { token = split[i]; if (token.equals("")) { continue; } if ((pos = token.indexOf(":")) < 0) { return null; } name = token.substring(0, pos).trim(); value = token.substring(pos + 1).trim(); httpMethod.addRequestHeader(name, value); } // set body if post method or put method if (body != null && body.length() > 0 && (httpMethod instanceof EntityEnclosingMethod)) { EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod; // post.setRequestEntity(new StringRequestEntity(body.toString())); post.setRequestEntity(new ByteArrayRequestEntity(body.getBytes())); } httpMethod.setFollowRedirects(false); return httpMethod; }
From source file:org.parosproxy.paros.network.HttpRequestHeader.java
public HttpRequestHeader(String method, URI uri, String version, ConnectionParam params) throws HttpMalformedHeaderException { this(method + " " + uri.toString() + " " + version.toUpperCase() + CRLF + CRLF); try {// w w w . j a v a 2s . c om setHeader(HOST, uri.getHost() + (uri.getPort() > 0 ? ":" + Integer.toString(uri.getPort()) : "")); } catch (URIException e) { log.error(e.getMessage(), e); } String userAgent = params != null ? params.getDefaultUserAgent() : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;)"; setHeader(USER_AGENT, userAgent); setHeader(PRAGMA, "no-cache"); // ZAP: added the Cache-Control header field to comply with HTTP/1.1 if (version.equalsIgnoreCase(HTTP11)) { setHeader(CACHE_CONTROL, "no-cache"); } // ZAP: set content type x-www-urlencoded only if it's a POST or a PUT if (method.equalsIgnoreCase(POST) || method.equalsIgnoreCase(PUT)) { setHeader(CONTENT_TYPE, "application/x-www-form-urlencoded"); } setHeader(ACCEPT_ENCODING, null); // ZAP: changed from method to version if (version.equalsIgnoreCase(HTTP11)) { setContentLength(0); } }
From source file:org.soaplab.clients.spinet.ServiceController.java
/************************************************************************* * *************************************************************************/ protected boolean urlExists(String url) { HttpMethod method = null;//w ww.j av a 2 s.co m try { // instantiating an HttpClient and its HEAD method HttpClient httpClient = new HttpClient(); URI uri = new URI(url, false); method = new HeadMethod(uri.toString()); method.setFollowRedirects(true); // execute the method int statusCode = httpClient.executeMethod(method); return (statusCode == HttpStatus.SC_OK); } catch (Throwable e) { SoaplabException.formatAndLog(e, log); return false; } finally { // release the connection if (method != null) method.releaseConnection(); } }
From source file:org.zaproxy.zap.extension.accessControl.ContextAccessRulesManager.java
/** * Import a rule from a serialized representation. The rule should have been exported via the * {@link #exportSerializedRules()} method. * * @param serializedRule the serialized rule *///w w w .j ava2 s . com protected void importSerializedRule(String serializedRule) { try { String[] values = serializedRule.split(Character.toString(SERIALIZATION_SEPARATOR), 4); int userId = Integer.parseInt(values[0]); AccessRule rule = AccessRule.valueOf(values[1]); String nodeName = new String(Base64.decodeBase64(values[2])); URI uri = new URI(values[3], true); SiteTreeNode node = new SiteTreeNode(nodeName, uri); getUserRules(userId).put(node, rule); if (log.isDebugEnabled()) { log.debug(String.format( "Imported access control rule (context, userId, node, rule): (%d, %d, %s, %s) ", context.getIndex(), userId, uri.toString(), rule)); } } catch (Exception ex) { log.error("Unable to import serialized rule for context " + context.getIndex() + ":" + serializedRule, ex); } }
From source file:org.zaproxy.zap.extension.accessControl.widgets.SiteTree.java
public SiteTreeNode addPath(Context context, URI uri, String method, Collection<String> urlParameters, Collection<String> formParameters, String contentType) { SiteTreeNode parent = this.root; SiteTreeNode leaf = null;/* ww w. java 2 s . c om*/ String pathSegment = ""; URI pathSegmentUri; try { URI hostUri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort()); String hostname = UriUtils.getHostName(uri); // add host parent = findOrAddPathSegmentNode(parent, hostname, hostUri); ParameterParser paramParser = context.getUrlParamParser(); List<String> path = paramParser.getTreePath(uri); for (int i = 0; i < path.size(); i++) { pathSegment = path.get(i); if (pathSegment != null && !pathSegment.equals("")) { if (i == path.size() - 1) { String leafName = UriUtils.getLeafNodeRepresentation(pathSegment, method, urlParameters, formParameters, contentType); leaf = findOrAddPathSegmentNode(parent, leafName, uri); } else { pathSegmentUri = new URI(hostUri, paramParser.getAncestorPath(uri, i + 1), false); parent = findOrAddPathSegmentNode(parent, pathSegment, pathSegmentUri); } } } // If no leaf found, which means the parent was really the leaf. This happens, for // example, when first adding a node for the top-level node, without any path elements if (leaf == null) { leaf = parent; } } catch (Exception e) { // ZAP: Added error log.error("Exception adding " + uri.toString() + " " + e.getMessage(), e); } return leaf; }