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;
}
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;
}
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;
}
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();
}
}
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));
}
Aggregations