Search in sources :

Example 56 with HttpException

use of org.apache.commons.httpclient.HttpException in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClient method getEngineComplianceVersion.

public static String getEngineComplianceVersion(String url) throws EngineUnavailableException, ServiceInvocationFailedException {
    String version;
    HttpClient client;
    PostMethod method;
    NameValuePair[] nameValuePairs;
    version = null;
    client = new HttpClient();
    method = new PostMethod(url);
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    //$NON-NLS-1$ //$NON-NLS-2$
    nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", "complianceVersion") };
    method.setRequestBody(nameValuePairs);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient.serviceFailed"), method.getStatusLine().toString(), //$NON-NLS-1$
            method.getResponseBodyAsString());
        } else {
            version = method.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.5", e.getMessage()));
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.6", e.getMessage()));
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return version;
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) NameValuePair(org.apache.commons.httpclient.NameValuePair) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 57 with HttpException

use of org.apache.commons.httpclient.HttpException in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClient_0_5_0 method getEngineInfo.

private String getEngineInfo(String infoType) throws EngineUnavailableException, ServiceInvocationFailedException {
    String version;
    HttpClient client;
    PostMethod method;
    NameValuePair[] nameValuePairs;
    version = null;
    client = new HttpClient();
    method = new PostMethod(getServiceUrl(ENGINE_INFO_SERVICE));
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    //$NON-NLS-1$
    nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", infoType) };
    method.setRequestBody(nameValuePairs);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient_0_5_0.serviceExcFailed") + ENGINE_INFO_SERVICE, //$NON-NLS-1$
            method.getStatusLine().toString(), method.getResponseBodyAsString());
        } else {
            version = method.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.protocolViolation") + e.getMessage());
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.transportError") + e.getMessage());
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return version;
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) NameValuePair(org.apache.commons.httpclient.NameValuePair) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 58 with HttpException

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

the class FsMountMojo method getBundleInstalledVersion.

/**
     * Get version of fsresource bundle that is installed in the instance.
     * @param targetUrl Target URL
     * @return Version number or null if non installed
     * @throws MojoExecutionException
     */
private String getBundleInstalledVersion(final String bundleSymbolicName, final String targetUrl) throws MojoExecutionException {
    final String getUrl = targetUrl + "/bundles/" + bundleSymbolicName + ".json";
    final GetMethod get = new GetMethod(getUrl);
    try {
        final int status = getHttpClient().executeMethod(get);
        if (status == 200) {
            final String jsonText;
            try (InputStream jsonResponse = get.getResponseBodyAsStream()) {
                jsonText = IOUtils.toString(jsonResponse, CharEncoding.UTF_8);
            }
            try {
                JsonObject response = JsonSupport.parseObject(jsonText);
                JsonArray data = response.getJsonArray("data");
                if (data.size() > 0) {
                    JsonObject bundleData = data.getJsonObject(0);
                    return bundleData.getString("version");
                }
            } catch (JsonException ex) {
                throw new MojoExecutionException("Reading bundle data from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
            }
        }
    } catch (HttpException ex) {
        throw new MojoExecutionException("Reading bundle data from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new MojoExecutionException("Reading bundle data from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
    } finally {
        get.releaseConnection();
    }
    // no version detected, bundle is not installed
    return null;
}
Also used : JsonArray(javax.json.JsonArray) JsonException(javax.json.JsonException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStream(java.io.InputStream) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonObject(javax.json.JsonObject) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 59 with HttpException

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

the class FsMountHelper method addConfiguration.

/**
     * Add a new configuration for the file system provider
     */
private void addConfiguration(final String targetUrl, FsResourceConfiguration cfg) throws MojoExecutionException {
    final String postUrl = targetUrl + "/configMgr/" + FS_FACTORY;
    final PostMethod post = new PostMethod(postUrl);
    post.addParameter("apply", "true");
    post.addParameter("factoryPid", FS_FACTORY);
    post.addParameter("pid", "[Temporary PID replaced by real PID upon save]");
    Map<String, String> props = toMap(cfg);
    for (Map.Entry<String, String> entry : props.entrySet()) {
        post.addParameter(entry.getKey(), entry.getValue());
    }
    post.addParameter("propertylist", StringUtils.join(props.keySet(), ","));
    try {
        final int status = httpClient.executeMethod(post);
        // we get a moved temporarily back from the configMgr plugin
        if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_OK) {
            log.info("Configuration created.");
        } else {
            log.error("Configuration on " + postUrl + " failed, cause: " + HttpStatus.getStatusText(status));
        }
    } catch (HttpException ex) {
        throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex);
    } finally {
        post.releaseConnection();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with HttpException

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

the class ContentDeploymentTest method deployFile.

@Test
public void deployFile() throws CoreException, InterruptedException, URIException, HttpException, IOException {
    wstServer.waitForServerToStart();
    // create faceted project
    IProject contentProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(contentProject);
    project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
    // install bundle facet
    project.installFacet("sling.content", "1.0");
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.installModule(contentProject);
    // create filter.xml
    project.createVltFilterWithRoots("/test");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/hello.txt"), new ByteArrayInputStream("hello, world".getBytes()));
    // verify that file is created
    final RepositoryAccessor repo = new RepositoryAccessor(config);
    Poller poller = new Poller();
    poller.pollUntil(new Callable<Void>() {

        @Override
        public Void call() throws HttpException, IOException {
            repo.assertGetIsSuccessful("test/hello.txt", "hello, world");
            return null;
        }
    }, nullValue(Void.class));
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/hello.txt"), new ByteArrayInputStream("goodbye, world".getBytes()));
    // verify that file is updated
    poller.pollUntil(new Callable<Void>() {

        @Override
        public Void call() throws HttpException, IOException {
            repo.assertGetIsSuccessful("test/hello.txt", "goodbye, world");
            return null;
        }
    }, nullValue(Void.class));
    project.deleteMember(Path.fromPortableString("jcr_root/test/hello.txt"));
    // verify that file is deleted
    poller.pollUntil(new Callable<Void>() {

        @Override
        public Void call() throws HttpException, IOException {
            repo.assertGetReturns404("test/hello.txt");
            return null;
        }
    }, nullValue(Void.class));
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) Poller(org.apache.sling.ide.test.impl.helpers.Poller) Test(org.junit.Test)

Aggregations

HttpException (org.apache.commons.httpclient.HttpException)62 IOException (java.io.IOException)55 HttpClient (org.apache.commons.httpclient.HttpClient)35 GetMethod (org.apache.commons.httpclient.methods.GetMethod)32 HttpMethod (org.apache.commons.httpclient.HttpMethod)22 InputStream (java.io.InputStream)16 Header (org.apache.commons.httpclient.Header)12 PostMethod (org.apache.commons.httpclient.methods.PostMethod)12 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)10 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)8 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)6 Test (org.junit.Test)5 ServiceException (com.zimbra.common.service.ServiceException)4 Server (com.zimbra.cs.account.Server)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 XStream (com.thoughtworks.xstream.XStream)3