org.wso2.carbon.core.util.Utils Java Examples

The following examples show how to use org.wso2.carbon.core.util.Utils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PublisherClient.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * PublisherClient constructor - Initialize a PublisherClient instance
 *
 */
public PublisherClient(RequestInterceptor requestInterceptor) {
    Feign.Builder builder = Feign.builder().client(new OkHttpClient(
            org.wso2.carbon.apimgt.integration.client.util.Utils.getSSLClient())).logger(new
            Slf4jLogger())
            .logLevel(Logger.Level.FULL)
            .requestInterceptor(requestInterceptor).encoder(new GsonEncoder()).decoder(new GsonDecoder());
    String basePath = Utils.replaceSystemProperty(APIMConfigReader.getInstance().getConfig().getPublisherEndpoint());

    api = builder.target(APIIndividualApi.class, basePath);
    apis = builder.target(APICollectionApi.class, basePath);
    document = builder.target(DocumentIndividualApi.class, basePath);
    application = builder.target(ApplicationIndividualApi.class, basePath);
    environments = builder.target(EnvironmentCollectionApi.class, basePath);
    subscriptions = builder.target(SubscriptionCollectionApi.class, basePath);
    tiers = builder.target(ThrottlingTierCollectionApi.class, basePath);
}
 
Example #2
Source File: StoreClient.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
public StoreClient(RequestInterceptor requestInterceptor) {

        Feign.Builder builder = Feign.builder().client(new OkHttpClient(
                org.wso2.carbon.apimgt.integration.client.util.Utils.getSSLClient())).logger(new
                Slf4jLogger())
                .logLevel(Logger.Level.FULL)
                .requestInterceptor(requestInterceptor).encoder(new GsonEncoder()).decoder(new GsonDecoder());
        String basePath = Utils.replaceSystemProperty(APIMConfigReader.getInstance().getConfig().getStoreEndpoint());

        apis = builder.target(APICollectionApi.class, basePath);
        individualApi = builder.target(APIIndividualApi.class, basePath);
        applications = builder.target(ApplicationCollectionApi.class, basePath);
        individualApplication = builder.target(ApplicationIndividualApi.class, basePath);
        subscriptions = builder.target(SubscriptionCollectionApi.class, basePath);
        individualSubscription = builder.target(SubscriptionIndividualApi.class, basePath);
        subscriptionMultitpleApi = builder.target(SubscriptionMultitpleApi.class, basePath);
        tags = builder.target(TagCollectionApi.class, basePath);
        individualTier = builder.target(ThrottlingTierIndividualApi.class, basePath);
        tiers = builder.retryer(new Retryer.Default(100L, TimeUnit.SECONDS.toMillis(1L), 1))
                .options(new Request.Options(10000, 5000))
                .target(ThrottlingTierCollectionApi.class, basePath);

    }
 
Example #3
Source File: DeviceTypeUtils.java    From product-iots with Apache License 2.0 6 votes vote down vote up
public static String replaceMqttProperty(String urlWithPlaceholders) {
    String mqttBrokerHost = null;
    String mqttPort = null;
    if (!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")) {
        mqttBrokerHost = "\\$".concat(DeviceTypeConstants.MQTT_BROKER_HOST);
    }
    if (!DeviceTypeConstants.MQTT_PORT.startsWith("$")) {
        mqttPort = "\\$".concat(DeviceTypeConstants.MQTT_PORT);
    }
    urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders);
    urlWithPlaceholders = urlWithPlaceholders.replaceAll(mqttPort, "" +
            (DeviceTypeConstants.DEFAULT_MQTT_PORT + getPortOffset()));
    urlWithPlaceholders = urlWithPlaceholders.replaceAll(mqttBrokerHost,
            System.getProperty(DeviceTypeConstants.DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost"));
    return urlWithPlaceholders;
}
 
Example #4
Source File: DeviceTypeUtils.java    From product-iots with Apache License 2.0 6 votes vote down vote up
public static String replaceMqttProperty(String urlWithPlaceholders) {
    String MQTT_BROKER_HOST = null;
    String MQTT_PORT = null;
    if(!DeviceTypeConstants.MQTT_BROKER_HOST.startsWith("$")){
        MQTT_BROKER_HOST = "\\$".concat(DeviceTypeConstants.MQTT_BROKER_HOST);
    }
    if(!DeviceTypeConstants.MQTT_PORT.startsWith("$")){
        MQTT_PORT = "\\$".concat(DeviceTypeConstants.MQTT_PORT);
    }
    urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders);
    urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_PORT, "" +
            (DeviceTypeConstants.DEFAULT_MQTT_PORT + getPortOffset()));
    urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_BROKER_HOST,
            System.getProperty(DeviceTypeConstants.DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost"));
    return urlWithPlaceholders;
}
 
Example #5
Source File: ZipUtil.java    From product-iots with Apache License 2.0 5 votes vote down vote up
public static String getServerUrl() {
    try {
        return org.apache.axis2.util.Utils.getIpAddress();
    } catch (SocketException e) {
        return "localhost";
    }
}
 
Example #6
Source File: DeviceTypeUtils.java    From product-iots with Apache License 2.0 5 votes vote down vote up
/**
 * Create Output Event Adapter Configuration for given configuration.
 *
 * @param name      Output Event Adapter name
 * @param type      Output Event Adapter type
 * @param msgFormat Output Event Adapter message format
 * @return OutputEventAdapterConfiguration instance for given configuration
 */
private static OutputEventAdapterConfiguration createMqttOutputEventAdapterConfiguration(String name, String type,
                                                                                         String msgFormat) throws IOException {
    OutputEventAdapterConfiguration outputEventAdapterConfiguration = new OutputEventAdapterConfiguration();
    outputEventAdapterConfiguration.setName(name);
    outputEventAdapterConfiguration.setType(type);
    outputEventAdapterConfiguration.setMessageFormat(msgFormat);
    File configFile = new File(DeviceTypeConstants.MQTT_CONFIG_LOCATION);
    if (configFile.exists()) {
        Map<String, String> mqttAdapterProperties = new HashMap<>();
        InputStream propertyStream = configFile.toURI().toURL().openStream();
        Properties properties = new Properties();
        properties.load(propertyStream);
        mqttAdapterProperties.put(DeviceTypeConstants.USERNAME_PROPERTY_KEY, properties.getProperty(
                DeviceTypeConstants.USERNAME_PROPERTY_KEY));
        mqttAdapterProperties.put(DeviceTypeConstants.DCR_PROPERTY_KEY, Utils.replaceSystemProperty(
                properties.getProperty(DeviceTypeConstants.DCR_PROPERTY_KEY)));
        mqttAdapterProperties.put(DeviceTypeConstants.BROKER_URL_PROPERTY_KEY, replaceMqttProperty(
                properties.getProperty(DeviceTypeConstants.BROKER_URL_PROPERTY_KEY)));
        mqttAdapterProperties.put(DeviceTypeConstants.SCOPES_PROPERTY_KEY, properties.getProperty(
                DeviceTypeConstants.SCOPES_PROPERTY_KEY));
        mqttAdapterProperties.put(DeviceTypeConstants.CLEAR_SESSION_PROPERTY_KEY, properties.getProperty(
                DeviceTypeConstants.CLEAR_SESSION_PROPERTY_KEY));
        mqttAdapterProperties.put(DeviceTypeConstants.QOS_PROPERTY_KEY, properties.getProperty(
                DeviceTypeConstants.QOS_PROPERTY_KEY));
        mqttAdapterProperties.put(DeviceTypeConstants.CLIENT_ID_PROPERTY_KEY, "");
        mqttAdapterProperties.put(DeviceTypeConstants.RESOURCE, "output-event");
        outputEventAdapterConfiguration.setStaticProperties(mqttAdapterProperties);
    }
    return outputEventAdapterConfiguration;
}
 
Example #7
Source File: APIPublisherUtil.java    From carbon-device-mgt with Apache License 2.0 4 votes vote down vote up
public static String getServerBaseUrl() {
    WebappPublisherConfig webappPublisherConfig = WebappPublisherConfig.getInstance();
    return Utils.replaceSystemProperty(webappPublisherConfig.getHost());
}
 
Example #8
Source File: JWTConfig.java    From carbon-device-mgt with Apache License 2.0 4 votes vote down vote up
public String getTokenEndpoint() {
	return Utils.replaceSystemProperty(tokenEndpoint);
}
 
Example #9
Source File: ZipUtil.java    From product-iots with Apache License 2.0 4 votes vote down vote up
/**
 * Create agent zip file.
 *
 * @param owner             Owner of device.
 * @param tenantDomain      Tenant of the device.
 * @param deviceType        Device type.
 * @param deviceId          Device ID.
 * @param deviceName        Device Name
 * @param token             Auth token to access the api.
 * @param refreshToken      Refresh token to generate new auth token.
 * @param apiApplicationKey Application key.
 * @return Zip archive.
 * @throws DeviceManagementException Error creating zip archive.
 */
public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType,
                                String deviceId, String deviceName, String token,
                                String refreshToken, String apiApplicationKey)
        throws DeviceManagementException {

    String sketchFolder = "repository" + File.separator + "resources" + File.separator + "sketches";
    String archivesPath = CarbonUtils.getCarbonHome() + File.separator + sketchFolder
            + File.separator + "archives" + File.separator + deviceId;
    String templateSketchPath = sketchFolder + File.separator + deviceType;
    String iotServerIP;

    try {
        iotServerIP = getServerUrl();
        String httpsServerEP = Utils.replaceSystemProperty(HTTPS_PROTOCOL_URL);
        String httpServerEP = Utils.replaceSystemProperty(HTTP_PROTOCOL_URL);
        String mqttEndpoint = Utils.replaceSystemProperty(DEFAULT_MQTT_ENDPOINT);
        if (mqttEndpoint.contains(LOCALHOST)) {
            mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP);
            httpsServerEP = httpsServerEP.replace(LOCALHOST, iotServerIP);
            httpServerEP = httpServerEP.replace(LOCALHOST, iotServerIP);
        }
        String base64EncodedApplicationKey = getBase64EncodedAPIAppKey(apiApplicationKey).trim();

        Map<String, String> contextParams = new HashMap<>();
        contextParams.put("SERVER_NAME", APIUtil.getTenantDomainOftheUser());
        contextParams.put("DEVICE_OWNER", owner);
        contextParams.put("DEVICE_ID", deviceId);
        contextParams.put("DEVICE_NAME", deviceName);
        contextParams.put("HTTPS_EP", httpsServerEP);
        contextParams.put("HTTP_EP", httpServerEP);
        contextParams.put("APIM_EP", httpsServerEP);
        contextParams.put("MQTT_EP", mqttEndpoint);
        contextParams.put("DEVICE_TOKEN", token);
        contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken);
        contextParams.put("API_APPLICATION_KEY", base64EncodedApplicationKey);

        ZipArchive zipFile;
        zipFile = getSketchArchive(archivesPath, templateSketchPath, contextParams, deviceName);
        return zipFile;
    } catch (IOException e) {
        throw new DeviceManagementException("Zip File Creation Failed", e);
    }
}
 
Example #10
Source File: Activator.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
public void start(BundleContext bundleContext) throws Exception {
    Utils.registerHTTPGetRequestProcessors(bundleContext);
}
 
Example #11
Source File: Activator.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
public void start(BundleContext bundleContext) throws Exception {
    Utils.registerHTTPGetRequestProcessors(bundleContext);
}