Skip to content

Commit

Permalink
Merge pull request #156 from charithag/IoTS-1.0.0-M1
Browse files Browse the repository at this point in the history
Get hostname from carbon.xml
  • Loading branch information
ruwany committed Jan 13, 2016
2 parents 2228836 + b95e229 commit 68beeca
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -11,7 +11,7 @@
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
Expand All @@ -32,12 +32,15 @@
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.device.mgt.iot.exception.IoTException;
import org.wso2.carbon.device.mgt.iot.internal.IoTCommonDataHolder;
import org.wso2.carbon.utils.NetworkUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.SocketException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -46,7 +49,8 @@

public class IoTUtil {

private static final Log log = LogFactory.getLog(IoTUtil.class);
public static final String HOST_NAME = "HostName";
private static final Log log = LogFactory.getLog(IoTUtil.class);

/**
* Return a http client instance
Expand Down Expand Up @@ -106,4 +110,18 @@ public static String getResponseString(HttpResponse httpResponse) throws IoTExce
}
}

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;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -11,7 +11,7 @@
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
Expand All @@ -22,6 +22,7 @@
import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.exception.IoTException;
import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil;
import org.wso2.carbon.utils.CarbonUtils;

Expand All @@ -33,7 +34,6 @@

public class ZipUtil {

private static final String LOCAL_BIND_ADDRESS_PROPERTY = "carbon.local.ip";
private static final String HTTPS_PORT_PROPERTY = "httpsPort";
private static final String HTTP_PORT_PROPERTY = "httpPort";

Expand All @@ -56,9 +56,14 @@ public ZipArchive createZipFile(String owner, String tenantDomain, String device
String templateSketchPath = sketchFolder + sep + deviceType;

String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName();
String iotServerIP = System.getProperty(LOCAL_BIND_ADDRESS_PROPERTY); // bind.address
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String iotServerIP;
try {
iotServerIP = IoTUtil.getHostName();
} catch (IoTException e) {
throw new DeviceManagementException(e.getMessage());
}
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);

String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort;
Expand Down Expand Up @@ -87,8 +92,8 @@ public ZipArchive createZipFile(String owner, String tenantDomain, String device

xmppEndpoint = xmppEndpoint + ":" + XmppConfig.getInstance().getSERVER_CONNECTION_PORT();

Map<String, String> contextParams = new HashMap<String, String>();
contextParams.put("SERVER_NAME", serverName);
Map<String, String> contextParams = new HashMap<>();
contextParams.put("SERVER_NAME", serverName);
contextParams.put("DEVICE_OWNER", owner);
contextParams.put("DEVICE_ID", deviceId);
contextParams.put("DEVICE_NAME", deviceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Fill login
form with the
credentials.
<i>(Use server URL as [&nbsp;https://&lt;WSO2_IoT_SERVER_HOST&gt;:&lt;SERVER_PORT&gt;&nbsp;] and click on
<i>(Use server URL as [&nbsp;https://&lt;WSO2_IoT_SERVER_HOST&gt;:&lt;HTTPS_SERVER_PORT&gt;&nbsp;]
and click on
<strong>Register Device</strong> button.)</i>
</li>
<li>
Expand Down

0 comments on commit 68beeca

Please sign in to comment.