Example #1
0
 /**
  * connect to org.wso2.carbon to invoke different operations
  *
  * @param userName user name to connect to org.wso2.carbon
  * @param password password to connect to org.wso2.carbon
  * @param connectionType
  * @param operation
  * @throws Exception
  */
 public void connect(String userName, String password, String connectionType, String operation)
     throws Exception {
   try {
     JMXServiceURL url =
         new JMXServiceURL(
             "service:jmx:rmi://"
                 + NetworkUtils.getLocalHostname()
                 + ":"
                 + RMIServerPort
                 + "/jndi/rmi://"
                 + NetworkUtils.getLocalHostname()
                 + ":"
                 + RMIRegistryPort
                 + "/jmxrmi");
     Hashtable<String, String[]> hashT = new Hashtable<String, String[]>();
     String[] credentials = new String[] {userName, password};
     hashT.put("jmx.remote.credentials", credentials);
     jmxc = JMXConnectorFactory.connect(url, hashT);
     mbsc = jmxc.getMBeanServerConnection();
     nodeAgent = new ObjectName(connectionType);
     mbsc.invoke(nodeAgent, operation, null, null);
   } catch (Exception ex) {
     log.error("infoAdminServiceStub Initialization fail ");
     throw new Exception("infoAdminServiceStub Initialization fail " + ex.getMessage());
   }
 }
  public static String getHostName() throws IoTException {
    String hostName = ServerConfiguration.getInstance().getFirstProperty(HOST_NAME);

    try {
      if (hostName == null) {
        hostName = NetworkUtils.getLocalHostname();
      }
    } catch (SocketException e) {
      throw new IoTException("Error while trying to read hostname.", e);
    }

    return hostName;
  }
 private String getIoTUrl() {
   // Hostname
   String hostName = "localhost";
   try {
     hostName = NetworkUtils.getMgtHostName();
   } catch (Exception ignored) {
   }
   // HTTPS port
   String mgtConsoleTransport = CarbonUtils.getManagementTransport();
   ConfigurationContextService configContextService =
       IoTDeviceManagementDataHolder.getInstance().getConfigurationContextService();
   int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
   int httpsProxyPort =
       CarbonUtils.getTransportProxyPort(
           configContextService.getServerConfigContext(), mgtConsoleTransport);
   if (httpsProxyPort > 0) {
     port = httpsProxyPort;
   }
   return "https://" + hostName + ":" + port + "/devicemgt";
 }
  public QpidServiceImpl(String accessKey) {
    this.accessKey = accessKey;

    // Get the hostname that Carbon runs on
    try {
      hostname = NetworkUtils.getLocalHostname();
    } catch (SocketException e) {
      hostname = CARBON_DEFAULT_HOSTNAME;
    }

    // Read Port Offset
    portOffset = readPortOffset();

    // Read Qpid broker port from configuration file
    port = readPortFromConfig();

    // Read Qpid broker SSL port from configuration file
    sslPort = readSSLPortFromConfig();

    // Read MQTT port from configuration file
    mqttPort = readMQTTPortFromConfig();
  }
 private void initialize() {
   ConfigurationContext serverConfigurationContext =
       configurationContextService.getServerConfigContext();
   if (!configurationDone
       && listenerManager != null
       && EventingDataHolder.getInstance().getRegistryService() != null) {
     String host;
     try {
       host = NetworkUtils.getLocalHostname();
     } catch (SocketException e) {
       host = null;
       log.warn("An error occured while determining server host", e);
     }
     if (host == null) {
       host = System.getProperty("carbon.local.ip");
       log.warn(
           "Unable to obtain server host, using the carbon.local.ip system "
               + "property to determine the ip address.");
     }
     log.debug("Found Server Host: " + host);
     if (serverConfigurationContext != null) {
       AxisConfiguration config = serverConfigurationContext.getAxisConfiguration();
       if (config != null
           && config.getTransportIn("https") != null
           && config.getTransportIn("https").getReceiver() != null) {
         try {
           EndpointReference[] eprArray =
               config
                   .getTransportIn("https")
                   .getReceiver()
                   .getEPRsForService("RegistryEventingService", host);
           if (eprArray != null && eprArray[0] != null) {
             endpoint = eprArray[0].getAddress();
             if (endpoint != null && endpoint.endsWith("/")) {
               endpoint = endpoint.substring(0, endpoint.length() - 1);
             }
           } else {
             String msg =
                 "Unable to obtain EPR for service. "
                     + "Attempting to construct EPR based on known parameters.";
             log.warn(msg);
           }
         } catch (AxisFault e) {
           String msg =
               "Error occured while obtaining EPR for service. "
                   + "Attempting to construct EPR based on known parameters.";
           log.warn(msg, e);
         }
       }
     }
     if (endpoint == null) {
       // Try to an alternate strategy to obtain the endpoint URL based on the ip address
       // and the port.
       StringBuffer epBuf = new StringBuffer("https://");
       String port = null;
       try {
         port =
             Integer.toString(CarbonUtils.getTransportPort(serverConfigurationContext, "https"));
       } catch (Exception e) {
         port = null;
         log.warn(
             "Unable to get HTTP port from Server Axis Configuration, using system defined value");
       }
       if (port == null) {
         port = System.getProperty("carbon.https.port");
       }
       log.debug("Found Server Port: " + port);
       if (host != null && port != null) {
         epBuf.append(host);
         epBuf.append(':');
         epBuf.append(port);
         AxisConfiguration axisConfig = null;
         if (serverConfigurationContext != null) {
           axisConfig = serverConfigurationContext.getAxisConfiguration();
         }
         if (axisConfig != null) {
           log.debug("Successfully obtained the Axis Configuration");
         }
         if (axisConfig != null && serverConfigurationContext.getContextRoot() != null) {
           String contextRoot = serverConfigurationContext.getContextRoot();
           log.debug("Found Context Root: " + contextRoot);
           epBuf.append(contextRoot);
           if (!contextRoot.endsWith("/")) {
             epBuf.append('/');
           }
         }
         if (axisConfig != null && axisConfig.getParameter("servicePath") != null) {
           log.debug("Found Service Path: " + axisConfig.getParameter("servicePath").getValue());
           epBuf.append((String) axisConfig.getParameter("servicePath").getValue());
           epBuf.append('/');
           endpoint = epBuf.toString() + RegistryEventingConstants.EVENTING_SERVICE_NAME;
         }
       }
     }
     if (endpoint == null) {
       String msg = "Failed obtaining server configuration";
       log.error(msg);
       throw new ActivationException(msg);
     }
     log.debug("The Registry Eventing Service is available at: " + endpoint);
     try {
       /*Utils.setRemoteTopicHeaderName(Utils.getRegistryEventBrokerService()
               .getSubscriptionManager().getPropertyValue("topicHeaderName"));
       Utils.setRemoteTopicHeaderNS(Utils.getRegistryEventBrokerService()
               .getSubscriptionManager().getPropertyValue("topicHeaderNS"));
       eventingRoot = Utils.getRegistryEventBrokerService()
               .getSubscriptionManager().getPropertyValue("subscriptionStoragePath");
       Utils.setRemoteSubscriptionStoreContext(eventingRoot);*/
       setupHandlers();
       setupDispatchers();
       setupEmailVerification();
       setSubscriptionConfiguration();
       log.debug("Successfully instantiated the Registry Event Source");
     } catch (Exception e) {
       String msg = "Error Instantiating Registry Event Source";
       log.error(msg);
       throw new ActivationException(msg);
     }
     configurationDone = true;
   }
 }