Search in sources :

Example 6 with OsgiClientException

use of org.apache.sling.ide.osgi.OsgiClientException in project sling by apache.

the class HttpOsgiClient method getBundleVersion.

@Override
public Version getBundleVersion(String bundleSymbolicName) throws OsgiClientException {
    GetMethod method = new GetMethod(repositoryInfo.appendPath("system/console/bundles.json"));
    HttpClient client = getHttpClient();
    try {
        int result = client.executeMethod(method);
        if (result != HttpStatus.SC_OK) {
            throw new HttpException("Got status code " + result + " for call to " + method.getURI());
        }
        try (InputStream input = method.getResponseBodyAsStream();
            Reader reader = new InputStreamReader(input, StandardCharsets.US_ASCII)) {
            return getBundleVersionFromReader(bundleSymbolicName, reader);
        }
    } catch (IOException e) {
        throw new OsgiClientException(e);
    } finally {
        method.releaseConnection();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonReader(com.google.gson.stream.JsonReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 7 with OsgiClientException

use of org.apache.sling.ide.osgi.OsgiClientException in project sling by apache.

the class TracingOsgiClient method logInstallLocalBundle.

private void logInstallLocalBundle(InputStream input, String explodedBundleLocation) throws OsgiClientException {
    Map<String, Object> props = new HashMap<>();
    long start = System.currentTimeMillis();
    if (input != null) {
        props.put(CommandExecutionProperties.ACTION_TYPE, "InstallJarredBundle");
    } else {
        props.put(CommandExecutionProperties.ACTION_TYPE, "InstallLocalBundle");
    }
    props.put(CommandExecutionProperties.ACTION_TARGET, explodedBundleLocation);
    props.put(CommandExecutionProperties.TIMESTAMP_START, start);
    try {
        if (input != null) {
            osgiClient.installLocalBundle(input, explodedBundleLocation);
        } else {
            osgiClient.installLocalBundle(explodedBundleLocation);
        }
        props.put(CommandExecutionProperties.RESULT_TEXT, "OK");
        props.put(CommandExecutionProperties.RESULT_STATUS, Boolean.TRUE);
    } catch (Throwable t) {
        props.put(CommandExecutionProperties.RESULT_TEXT, "FAILED");
        props.put(CommandExecutionProperties.RESULT_STATUS, Boolean.FALSE);
        props.put(CommandExecutionProperties.RESULT_THROWABLE, t);
        if (t instanceof OsgiClientException) {
            throw (OsgiClientException) t;
        } else if (t instanceof Error) {
            throw (Error) t;
        } else if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else {
            // should never happen
            throw new Error(t);
        }
    } finally {
        props.put(CommandExecutionProperties.TIMESTAMP_END, System.currentTimeMillis());
        Event event = new Event(CommandExecutionProperties.REPOSITORY_TOPIC, props);
        eventAdmin.postEvent(event);
    }
}
Also used : HashMap(java.util.HashMap) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) Event(org.osgi.service.event.Event)

Aggregations

OsgiClientException (org.apache.sling.ide.osgi.OsgiClientException)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 JsonReader (com.google.gson.stream.JsonReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 HttpException (org.apache.commons.httpclient.HttpException)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 OsgiClient (org.apache.sling.ide.osgi.OsgiClient)2 SourceReference (org.apache.sling.ide.osgi.SourceReference)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 Gson (com.google.gson.Gson)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Reader (java.io.Reader)1