use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.
the class VariantODataUnitTest method shouldBeAbleToHandleURIwithoutQuery.
/**
* Test that the variant handles URLs without query element
*
* @throws org.apache.commons.httpclient.URIException
* @throws NullPointerException
* @throws CloneNotSupportedException
*/
@Test
public void shouldBeAbleToHandleURIwithoutQuery() throws URIException, NullPointerException, CloneNotSupportedException {
URI sourceURI = new URI("http", null, "localhost", 15050, "/remoting/servlet.svc/Book");
doTestInjectParameter(VARIANT_ODATA_FILTER_QUERY, sourceURI, "param2", "6", "hacked", "http://localhost:15050/remoting/servlet.svc/Book");
}
use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.
the class VariantODataUnitTest method doTestInjectParameter.
/**
* Test that we can properly inject a new value to the sourceURI
*
* @param sourceURI
* @param paramName
* @param originalValue
* @param hackValue
* @param expectedHackedURI
* @throws org.apache.commons.httpclient.URIException
* @throws NullPointerException
* @throws CloneNotSupportedException
*/
private void doTestInjectParameter(Variant variant, URI sourceURI, String paramName, String originalValue, String hackValue, String expectedHackedURI) throws URIException, NullPointerException, CloneNotSupportedException {
// Given
HttpMessage msg = new HttpMessage();
msg.setRequestHeader(new HttpRequestHeader());
//When
NameValuePair originalPair = new NameValuePair(NameValuePair.TYPE_URL_PATH, paramName, originalValue, 1);
msg.getRequestHeader().setURI((URI) sourceURI.clone());
variant.setMessage(msg);
// implicit parameter name for the entity Book
String param = originalPair.getName();
setParameter(msg, param, hackValue, variant, originalPair);
//Then
// Check that the msg contains now well formated URI with the injected parameter
URI hackedURI = msg.getRequestHeader().getURI();
String hackedURIasStr = hackedURI.getURI();
assertThat("RequestHeader.uri", hackedURIasStr, is(expectedHackedURI));
}
use of org.apache.commons.httpclient.URI in project zaproxy by zaproxy.
the class FilterLogPostQuery method onHttpRequestSend.
@Override
public void onHttpRequestSend(HttpMessage httpMessage) {
HttpRequestHeader reqHeader = httpMessage.getRequestHeader();
if (reqHeader != null && reqHeader.isText() && !reqHeader.isImage()) {
if (reqHeader.getMethod().equalsIgnoreCase(HttpRequestHeader.POST)) {
try {
URI uri = reqHeader.getURI();
// ZAP: Removed unused variable (int pos).
String firstline;
URI newURI = (URI) uri.clone();
String query = httpMessage.getRequestBody().toString();
if (query != null) {
newURI.setQuery(null);
firstline = newURI.toString();
// ZAP: Added type arguments.
Hashtable<String, String> param = parseParameter(query);
writeLogFile(firstline, param);
} else {
firstline = uri.toString();
writeLogFile(firstline, null);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
}
use of org.apache.commons.httpclient.URI 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;
}
System.out.println();
System.out.println("=== Request ===");
if (Level.needsHeader(level)) {
try {
URI uri = postMethod.getURI();
System.out.println(uri.toString());
} catch (URIException e) {
e.printStackTrace();
}
// headers
Header[] headers = postMethod.getRequestHeaders();
for (Header header : headers) {
// trim the ending crlf
System.out.println(header.toString().trim());
}
System.out.println();
//cookies
if (httpState != null) {
Cookie[] cookies = httpState.getCookies();
for (Cookie cookie : cookies) {
System.out.println("Cookie: " + cookie.toString());
}
}
System.out.println();
}
if (Level.needsBody(level)) {
System.out.println(envelope.prettyPrint());
}
}
use of org.apache.commons.httpclient.URI in project cloudstack by apache.
the class UcsHttpClient method call.
public String call(String xml) {
PostMethod post = new PostMethod(url);
post.setRequestEntity(new StringRequestEntity(xml));
post.setRequestHeader("Content-type", "text/xml");
//post.setFollowRedirects(true);
try {
int result = client.executeMethod(post);
if (result == 302) {
// Handle HTTPS redirect
// Ideal way might be to configure from add manager API
// for using either HTTP / HTTPS
// Allow only one level of redirect
String redirectLocation;
Header locationHeader = post.getResponseHeader("location");
if (locationHeader != null) {
redirectLocation = locationHeader.getValue();
} else {
throw new CloudRuntimeException("Call failed: Bad redirect from UCS Manager");
}
post.setURI(new URI(redirectLocation));
result = client.executeMethod(post);
}
// Check for errors
if (result != 200) {
throw new CloudRuntimeException("Call failed: " + post.getResponseBodyAsString());
}
String res = post.getResponseBodyAsString();
if (res.contains("errorCode")) {
String err = String.format("ucs call failed:\nsubmitted doc:%s\nresponse:%s\n", xml, res);
throw new CloudRuntimeException(err);
}
return res;
} catch (Exception e) {
throw new CloudRuntimeException(e.getMessage(), e);
} finally {
post.releaseConnection();
}
}
Aggregations