use of org.apache.commons.httpclient.URIException in project openhab1-addons by openhab.
the class SystemsRequest method prepare.
public String prepare() {
final StringBuilder urlBuilder = new StringBuilder(RESOURCE_URL);
urlBuilder.append("/");
urlBuilder.append(this.system_id);
urlBuilder.append("/summary");
urlBuilder.append("?key=");
urlBuilder.append(this.key);
urlBuilder.append("&user_id=");
urlBuilder.append(this.user_id);
try {
return encodeQuery(urlBuilder.toString());
} catch (final URIException e) {
throw new EnphaseenergyException("Could not prepare systems request!", e);
}
}
use of org.apache.commons.httpclient.URIException in project pinpoint by naver.
the class HttpMethodBaseExecuteMethodInterceptor method recordDestination.
private void recordDestination(final Trace trace, final HttpMethod httpMethod, final Object[] args) {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
try {
final URI uri = httpMethod.getURI();
final HttpConnection httpConnection = getHttpConnection(args);
// if uri have schema or not found HttpConnection argument.
if (uri.isAbsoluteURI() || httpConnection == null) {
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(uri.getURI(), param));
recorder.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort()));
return;
}
if (isDebug) {
logger.debug("URI is not absolute. {}", uri.getURI());
}
// use HttpConnection argument.
final String host = httpConnection.getHost();
int port = httpConnection.getPort();
final StringBuilder httpUrl = new StringBuilder();
final Protocol protocol = httpConnection.getProtocol();
if (protocol != null) {
httpUrl.append(protocol.getScheme()).append("://");
httpUrl.append(httpConnection.getHost());
// if port is default port number.
if (httpConnection.getPort() == protocol.getDefaultPort()) {
port = -1;
} else {
httpUrl.append(":").append(port);
}
}
httpUrl.append(uri.getURI());
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(httpUrl.toString(), param));
recorder.recordDestinationId(getEndpoint(host, port));
} catch (URIException e) {
logger.error("Fail get URI", e);
recorder.recordDestinationId("unknown");
}
}
use of org.apache.commons.httpclient.URIException in project zaproxy by zaproxy.
the class FilterLogCookie method onHttpRequestSend.
@Override
public void onHttpRequestSend(HttpMessage msg) {
HttpRequestHeader header = msg.getRequestHeader();
if (header != null) {
String cookie = header.getHeader("Cookie");
synchronized (cookieList) {
if (cookie != null && cookieList.indexOf(cookie) == -1) {
try {
// ZAP: catch CloneNotSupportedException as introduced with version 3.1 of HttpClient
URI uri;
try {
uri = (URI) header.getURI().clone();
} catch (CloneNotSupportedException e) {
throw new URIException(e.getMessage());
}
uri.setQuery(null);
String sUri = uri.toString();
cookieList.add(cookie);
getView().getOutputPanel().append(sUri + DELIM + cookie + "\n");
} catch (URIException e) {
// ZAP: Print stack trace to Output tab
getView().getOutputPanel().append(e);
}
}
}
}
}
use of org.apache.commons.httpclient.URIException in project zaproxy by zaproxy.
the class Spider method addSeed.
/**
* Adds a new seed for the Spider.
*
* @param uri the uri
*/
public void addSeed(URI uri) {
// Update the scope of the spidering process
String host = null;
try {
host = uri.getHost();
defaultFetchFilter.addScopeRegex(host);
} catch (URIException e) {
log.error("There was an error while adding seed value: " + uri, e);
return;
}
// Add the seed to the list -- it will be added to the task list only when the spider is
// started
this.seedList.add(uri);
// Add the appropriate 'robots.txt' as a seed
if (getSpiderParam().isParseRobotsTxt()) {
try {
// Build the URI of the robots.txt file
URI robotsUri;
// If the port is not 80 or 443, add it to the URI
if (uri.getPort() == 80 || uri.getPort() == 443) {
robotsUri = new URI(uri.getScheme() + "://" + host + "/robots.txt", true);
} else {
robotsUri = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + "/robots.txt", true);
}
this.seedList.add(robotsUri);
} catch (Exception e) {
log.warn("Error while creating URI for robots.txt file for site " + uri, e);
}
}
// Add the appropriate 'sitemap.xml' as a seed
if (getSpiderParam().isParseSitemapXml()) {
try {
// Build the URI of the sitemap.xml file
URI sitemapUri;
// If the port is not 80 or 443, add it to the URI
if (uri.getPort() == 80 || uri.getPort() == 443) {
sitemapUri = new URI(uri.getScheme() + "://" + host + "/sitemap.xml", true);
} else {
sitemapUri = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + "/sitemap.xml", true);
}
this.seedList.add(sitemapUri);
} catch (Exception e) {
log.warn("Error while creating URI for sitemap.xml file for site " + uri, e);
}
}
// And add '.svn/entries' as a seed, for SVN based spidering
if (getSpiderParam().isParseSVNEntries()) {
try {
URI svnEntriesURI1, svnEntriesURI2;
// If the port is not 80 or 443, add it to the URI
// SVN entries can exist in multiple directories, so make sure to add in the full path.
String fullpath = uri.getPath();
String name = uri.getName();
if (fullpath == null)
fullpath = "";
if (name == null)
name = "";
String pathminusfilename = fullpath.substring(0, fullpath.lastIndexOf(name));
if (pathminusfilename.equals(""))
pathminusfilename = "/";
//if it's not an svn folder, add the seeds.
Matcher matcherSvnUrl = svnUrlPattern.matcher(pathminusfilename);
if (!matcherSvnUrl.find()) {
if (uri.getPort() == 80 || uri.getPort() == 443) {
svnEntriesURI1 = new URI(uri.getScheme() + "://" + host + pathminusfilename + ".svn/entries", true);
svnEntriesURI2 = new URI(uri.getScheme() + "://" + host + pathminusfilename + ".svn/wc.db", true);
} else {
svnEntriesURI1 = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + pathminusfilename + ".svn/entries", true);
svnEntriesURI2 = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + pathminusfilename + ".svn/wc.db", true);
}
this.seedList.add(svnEntriesURI1);
this.seedList.add(svnEntriesURI2);
}
} catch (Exception e) {
log.warn("Error while creating a seed URI for the SVN files for site " + uri, e);
}
}
// And add '.git/index' as a seed, for Git based spidering
if (getSpiderParam().isParseGit()) {
try {
URI gitEntriesURI;
// If the port is not 80 or 443, add it to the URI
// Make sure to add in the full path.
String fullpath = uri.getPath();
String name = uri.getName();
if (fullpath == null)
fullpath = "";
if (name == null)
name = "";
String pathminusfilename = fullpath.substring(0, fullpath.lastIndexOf(name));
if (pathminusfilename.equals(""))
pathminusfilename = "/";
//if it's not in a Git folder, add the seed.
Matcher matcherGitUrl = gitUrlPattern.matcher(pathminusfilename);
if (!matcherGitUrl.find()) {
if (uri.getPort() == 80 || uri.getPort() == 443) {
gitEntriesURI = new URI(uri.getScheme() + "://" + host + pathminusfilename + ".git/index", true);
} else {
gitEntriesURI = new URI(uri.getScheme() + "://" + host + ":" + uri.getPort() + pathminusfilename + ".git/index", true);
}
this.seedList.add(gitEntriesURI);
}
} catch (Exception e) {
log.warn("Error while creating a seed URI for the Git files for site " + uri, e);
}
}
}
use of org.apache.commons.httpclient.URIException in project zm-mailbox by Zimbra.
the class SoapDebugListener method sendSoapMessage.
@Override
public void sendSoapMessage(PostMethod postMethod, Element envelope, HttpState httpState) {
if (level == Level.OFF) {
return;
}
printer.println();
printer.println("=== Request ===");
if (Level.needsHeader(level)) {
try {
URI uri = postMethod.getURI();
printer.println(uri.toString());
} catch (URIException e) {
e.printStackTrace();
}
// headers
Header[] headers = postMethod.getRequestHeaders();
for (Header header : headers) {
// trim the ending crlf
printer.println(header.toString().trim());
}
printer.println();
//cookies
if (httpState != null) {
Cookie[] cookies = httpState.getCookies();
for (Cookie cookie : cookies) {
printer.println("Cookie: " + cookie.toString());
}
}
printer.println();
}
if (Level.needsBody(level)) {
printer.println(envelope.prettyPrint());
}
}
Aggregations