Search in sources :

Example 56 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project cloudstack by apache.

the class BigSwitchApiTest method setUp.

@Before
public void setUp() {
    HttpClientParams hmp = mock(HttpClientParams.class);
    when(_client.getParams()).thenReturn(hmp);
    _api = new BigSwitchBcfApi() {

        @Override
        protected HttpClient createHttpClient() {
            return _client;
        }

        @Override
        protected HttpMethod createMethod(String type, String uri, int port) {
            return _method;
        }
    };
    _api.setControllerAddress("10.10.0.10");
    _api.setControllerUsername("myname");
    _api.setControllerPassword("mypassword");
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) HttpMethod(org.apache.commons.httpclient.HttpMethod) Before(org.junit.Before)

Example 57 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project sling by apache.

the class FiltersTest method testCounters.

public void testCounters() throws IOException {
    HttpMethod get = assertHttpStatus(HTTP_BASE_URL + "/index.html", HttpServletResponse.SC_OK);
    final String[] headers = { "FILTER_COUNTER_SLING", "FILTER_COUNTER_NOPROP" };
    for (String header : headers) {
        assertNotNull("Expecting header '" + header + "'", get.getResponseHeader(header));
        assertEquals("Expecting value 1 for header '" + header + "'", "1", get.getResponseHeader(header).getValue());
    }
    assertNull(get.getResponseHeader("FILTER_COUNTER_SLING_WITH_PATTERN"));
}
Also used : HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 58 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project intellij-plugins by JetBrains.

the class CfmlUnitRemoteTestsRunner method executeScript.

public static void executeScript(final CfmlUnitRunnerParameters params, final ProcessHandler processHandler, /*final String webPath,
                                   final String componentFilePath,
                                   final String methodName,
                                   final ProcessHandler processHandler*/
final Project project) throws ExecutionException {
    final Ref<ExecutionException> ref = new Ref<>();
    ApplicationManager.getApplication().assertIsDispatchThread();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        try {
            final VirtualFile componentFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(params.getPath());
            if (componentFile == null) {
                throw new ExecutionException("File " + params.getPath() + " not found");
            }
            // creating script files
            final VirtualFile directory = componentFile.getParent();
            //generateUniqueName("mxunit-launcher", project);
            final String launcherFileName = "mxunit-launcher.cfc";
            LOG.debug("Copying script file" + launcherFileName + " to component folder: " + directory);
            createFile(project, directory, launcherFileName, getLauncherText("/scripts/mxunit-launcher.cfc"));
            //generateUniqueName("mxunit-result-capture", project);
            final String resultsFileName = "mxunit-result-capture.cfc";
            LOG.debug("Copying results capture file " + resultsFileName + " to component folder: " + directory);
            createFile(project, directory, resultsFileName, getLauncherText("/scripts/mxunit-result-capture.cfc"));
            // retrieving data through URL
            String webPath = params.getWebPath();
            if (webPath.endsWith("/") || webPath.endsWith("\\")) {
                webPath = webPath.substring(0, webPath.length() - 1);
            }
            String agentPath = webPath.substring(0, webPath.lastIndexOf('/')) + "/" + launcherFileName;
            LOG.debug("Retrieving data from coldfusion server by " + agentPath + " URL");
            BufferedReader reader = null;
            String agentUrl;
            if (params.getScope() == CfmlUnitRunnerParameters.Scope.Directory) {
                agentUrl = agentPath + "?method=executeDirectory&directoryName=" + componentFile.getName();
            } else {
                agentUrl = agentPath + "?method=executeTestCase&componentName=" + componentFile.getNameWithoutExtension();
                if (params.getScope() == CfmlUnitRunnerParameters.Scope.Method) {
                    agentUrl += "&methodName=" + params.getMethod();
                }
            }
            HttpMethod method = null;
            try {
                LOG.debug("Retrieving test results from: " + agentUrl);
                /*
          final FileObject httpFile = getManager().resolveFile(agentUrl);

          reader = new BufferedReader(new InputStreamReader(httpFile.getContent().getInputStream()));
          */
                HttpClient client = new HttpClient();
                method = new GetMethod(agentUrl);
                int statusCode = client.executeMethod(method);
                if (statusCode != HttpStatus.SC_OK) {
                    LOG.debug("Http request failed: " + method.getStatusLine());
                    processHandler.notifyTextAvailable("Http request failed: " + method.getStatusLine(), ProcessOutputTypes.SYSTEM);
                }
                final InputStream responseStream = method.getResponseBodyAsStream();
                reader = new BufferedReader(new InputStreamReader(responseStream));
                String line;
                while (!processHandler.isProcessTerminating() && !processHandler.isProcessTerminated() && (line = reader.readLine()) != null) {
                    if (!StringUtil.isEmptyOrSpaces(line)) {
                        LOG.debug("MXUnit: " + line);
                        processHandler.notifyTextAvailable(line + "\n", ProcessOutputTypes.SYSTEM);
                    }
                }
            } catch (IOException e) {
                LOG.warn(e);
                processHandler.notifyTextAvailable("Failed to retrieve test results from the server at " + agentUrl + "\n", ProcessOutputTypes.SYSTEM);
            } finally {
                if (method != null) {
                    method.releaseConnection();
                }
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
            LOG.debug("Cleaning temporary files");
            deleteFile(project, directory.findChild(launcherFileName));
            deleteFile(project, directory.findChild(resultsFileName));
            if (!processHandler.isProcessTerminated() && !processHandler.isProcessTerminating()) {
                processHandler.destroyProcess();
            }
        } catch (ExecutionException e) {
            ref.set(e);
        }
    });
    if (!ref.isNull()) {
        throw ref.get();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Ref(com.intellij.openapi.util.Ref) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ExecutionException(com.intellij.execution.ExecutionException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 59 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project sling by apache.

the class AuthenticationResponseCodeTest method testValidatingIncorrectCredentials.

@Test
public void testValidatingIncorrectCredentials() throws Exception {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_username", "garbage"));
    params.add(new NameValuePair("j_password", "garbage"));
    params.add(new NameValuePair("j_validate", "true"));
    HttpMethod post = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_FORBIDDEN, params, null);
    assertNotNull(post.getResponseHeader("X-Reason"));
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) HttpMethod(org.apache.commons.httpclient.HttpMethod) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 60 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project sling by apache.

the class AuthenticationResponseCodeTest method testValidatingIncorrectCookie.

@Test
public void testValidatingIncorrectCookie() throws Exception {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_validate", "true"));
    List<Header> headers = new ArrayList<Header>();
    headers.add(new Header("Cookie", "sling.formauth=garbage"));
    HttpMethod post = assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_FORBIDDEN, params, headers, null);
    assertXReason(post);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Header(org.apache.commons.httpclient.Header) ArrayList(java.util.ArrayList) HttpMethod(org.apache.commons.httpclient.HttpMethod) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Aggregations

HttpMethod (org.apache.commons.httpclient.HttpMethod)151 HttpClient (org.apache.commons.httpclient.HttpClient)99 GetMethod (org.apache.commons.httpclient.methods.GetMethod)95 InputStream (java.io.InputStream)61 IOException (java.io.IOException)43 ArrayList (java.util.ArrayList)30 HttpException (org.apache.commons.httpclient.HttpException)28 Map (java.util.Map)24 Test (org.junit.Test)23 Element (org.w3c.dom.Element)22 HashMap (java.util.HashMap)20 PostMethod (org.apache.commons.httpclient.methods.PostMethod)19 Header (org.apache.commons.httpclient.Header)17 List (java.util.List)14 NameValuePair (org.apache.commons.httpclient.NameValuePair)13 NodeList (org.w3c.dom.NodeList)12 FileInputStream (java.io.FileInputStream)10 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)10 SAXBuilder (org.jdom.input.SAXBuilder)10 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)9