Search in sources :

Example 61 with URI

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");
}
Also used : URI(org.apache.commons.httpclient.URI) Test(org.junit.Test)

Example 62 with URI

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));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) URI(org.apache.commons.httpclient.URI)

Example 63 with URI

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);
            }
        }
    }
}
Also used : HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) URI(org.apache.commons.httpclient.URI)

Example 64 with URI

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());
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) URIException(org.apache.commons.httpclient.URIException) Header(org.apache.commons.httpclient.Header) URI(org.apache.commons.httpclient.URI)

Example 65 with URI

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();
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) Header(org.apache.commons.httpclient.Header) PostMethod(org.apache.commons.httpclient.methods.PostMethod) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URI(org.apache.commons.httpclient.URI) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

URI (org.apache.commons.httpclient.URI)129 Test (org.junit.Test)72 FetchStatus (org.zaproxy.zap.spider.filters.FetchFilter.FetchStatus)33 URIException (org.apache.commons.httpclient.URIException)28 HttpMessage (org.parosproxy.paros.network.HttpMessage)10 ArrayList (java.util.ArrayList)9 HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)8 DatabaseException (org.parosproxy.paros.db.DatabaseException)7 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)6 HandleParametersOption (org.zaproxy.zap.spider.SpiderParam.HandleParametersOption)6 IOException (java.io.IOException)5 Header (org.apache.commons.httpclient.Header)4 InvalidParameterException (java.security.InvalidParameterException)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 JSONException (net.sf.json.JSONException)3 StructuralNode (org.zaproxy.zap.model.StructuralNode)3 File (java.io.File)2 List (java.util.List)2