Search in sources :

Example 1 with JsonHelper.jsonEncodeString

use of io.fabric8.internal.JsonHelper.jsonEncodeString in project fabric8 by jboss-fuse.

the class FabricCxfRegistrationHandler method registerApiEndpoint.

protected void registerApiEndpoint(Container container, ObjectName oName, String address, boolean started) {
    String actualEndpointUrl = null;
    try {
        String url;
        String id = container.getId();
        if (isFullAddress(address)) {
            url = toPublicAddress(id, address);
        } else {
            String cxfBus = getCxfServletPath(oName);
            url = "${zk:" + id + "/http}" + cxfBus + address;
        }
        actualEndpointUrl = ZooKeeperUtils.getSubstitutedData(curator.get(), url);
        // lets assume these locations are hard coded
        // may be nice to discover from JMX one day
        String apiDocPath = "/api-docs";
        String wsdlPath = "?wsdl";
        String wadlPath = "?_wadl";
        Version version = container.getVersion();
        String versionId = version != null ? version.getId() : null;
        String json = "{\"id\":" + JsonHelper.jsonEncodeString(id) + ", \"container\":" + JsonHelper.jsonEncodeString(id) + ", \"version\":" + JsonHelper.jsonEncodeString(versionId) + ", \"services\":[" + JsonHelper.jsonEncodeString(url) + "]" + ", \"objectName\":" + JsonHelper.jsonEncodeString(oName.toString()) + "";
        boolean rest = false;
        if (booleanAttribute(oName, "isWADL")) {
            rest = true;
            json += ", \"wadl\":" + JsonHelper.jsonEncodeString(wadlPath);
        }
        if (booleanAttribute(oName, "isSwagger")) {
            rest = true;
            json += ", \"apidocs\":" + JsonHelper.jsonEncodeString(apiDocPath);
        }
        if (booleanAttribute(oName, "isWSDL")) {
            json += ", \"wsdl\":" + JsonHelper.jsonEncodeString(wsdlPath);
        }
        json += "}";
        String path = getPath(container, oName, address, rest);
        LOGGER.info("Registered CXF API at " + path + " JSON: " + json);
        if (!started && !rest) {
            LOGGER.warn("Since the CXF service isn't started, this could really be a REST endpoint rather than WSDL at " + path);
        }
        registeredZkPaths.add(path);
        registeredUrls.put(oName.toString(), address);
        ZooKeeperUtils.setData(curator.get(), path, json, CreateMode.EPHEMERAL);
    } catch (Exception e) {
        LOGGER.error("Failed to register API endpoint for {}.", actualEndpointUrl, e);
    }
}
Also used : Version(io.fabric8.api.Version) URISyntaxException(java.net.URISyntaxException) BadBinaryOpValueExpException(javax.management.BadBinaryOpValueExpException) BadStringOperationException(javax.management.BadStringOperationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MalformedURLException(java.net.MalformedURLException) BadAttributeValueExpException(javax.management.BadAttributeValueExpException) IOException(java.io.IOException) InvalidApplicationException(javax.management.InvalidApplicationException)

Example 2 with JsonHelper.jsonEncodeString

use of io.fabric8.internal.JsonHelper.jsonEncodeString in project fabric8 by jboss-fuse.

the class FabricWebRegistrationHandler method registerWebapp.

/**
 * Registers a webapp to the registry.
 */
private void registerWebapp(Container container, WebEvent webEvent) {
    String id = container.getId();
    String url = "${zk:" + id + "/http}" + webEvent.getContextPath();
    String bundleName = webEvent.getBundle().getSymbolicName();
    String bundleVersion = webEvent.getBundle().getVersion().toString();
    setJolokiaUrl(container, url, bundleName);
    Version version = container.getVersion();
    String versionId = version != null ? version.getId() : null;
    String json = "{\"id\":" + jsonEncodeString(id) + ",\"services\":[" + jsonEncodeString(url) + "]" + ",\"version\":" + JsonHelper.jsonEncodeString(versionId) + ",\"bundleName\":" + jsonEncodeString(bundleName) + ",\"bundleVersion\":" + jsonEncodeString(bundleVersion) + ",\"container\":" + jsonEncodeString(id) + "}";
    try {
        synchronized (webEvent.getBundle()) {
            setData(curator.get(), ZkPath.WEBAPPS_CONTAINER.getPath(bundleName, webEvent.getBundle().getVersion().toString(), id), json, CreateMode.EPHEMERAL);
        }
    } catch (Exception e) {
        LOGGER.error("Failed to register webapp {}.", webEvent.getContextPath(), e);
    }
}
Also used : Version(io.fabric8.api.Version) JsonHelper.jsonEncodeString(io.fabric8.internal.JsonHelper.jsonEncodeString) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with JsonHelper.jsonEncodeString

use of io.fabric8.internal.JsonHelper.jsonEncodeString in project fabric8 by jboss-fuse.

the class FabricWebRegistrationHandler method registerServlet.

private void registerServlet(Container container, ServletEvent servletEvent) {
    String id = container.getId();
    Version version = container.getVersion();
    String versionId = version != null ? version.getId() : null;
    String url = "${zk:" + id + "/http}" + servletEvent.getAlias();
    String bundleName = servletEvent.getBundle().getSymbolicName();
    String bundleVersion = servletEvent.getBundle().getVersion().toString();
    String name = servletEvent.getBundle().getSymbolicName();
    setJolokiaUrl(container, url, name);
    String json = "{\"id\":" + jsonEncodeString(id) + ",\"services\":[" + jsonEncodeString(url) + "]" + ",\"container\":" + jsonEncodeString(id) + ",\"bundleName\":" + jsonEncodeString(bundleName) + ",\"bundleVersion\":" + jsonEncodeString(bundleVersion) + ",\"version\":" + JsonHelper.jsonEncodeString(versionId) + "}";
    try {
        // We don't want to register / it's fabric-redirect for hawtio
        if (!servletEvent.getAlias().equals("/")) {
            String path = createServletPath(servletEvent, id, bundleName, bundleVersion);
            synchronized (servletEvent.getBundle()) {
                setData(curator.get(), path, json, CreateMode.EPHEMERAL);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Failed to register servlet {}.", servletEvent.getAlias(), e);
    }
}
Also used : Version(io.fabric8.api.Version) JsonHelper.jsonEncodeString(io.fabric8.internal.JsonHelper.jsonEncodeString) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

Version (io.fabric8.api.Version)3 JsonHelper.jsonEncodeString (io.fabric8.internal.JsonHelper.jsonEncodeString)2 KeeperException (org.apache.zookeeper.KeeperException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 BadAttributeValueExpException (javax.management.BadAttributeValueExpException)1 BadBinaryOpValueExpException (javax.management.BadBinaryOpValueExpException)1 BadStringOperationException (javax.management.BadStringOperationException)1 InvalidApplicationException (javax.management.InvalidApplicationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1