Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit c7eefb4

Browse files
authored
Merge pull request #22 from groupdocs-viewer/fix-config-hostaddress
added hostAddress config into application configuration
2 parents a0b9ade + 9b96cdb commit c7eefb4

File tree

6 files changed

+33
-28
lines changed

6 files changed

+33
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Use [docker](https://www.docker.com/) image.
9090
```bash
9191
mkdir DocumentSamples
9292
mkdir Licenses
93-
docker run -p 8080:8080 -v `pwd`/DocumentSamples:/home/groupdocs/app/DocumentSamples -v `pwd`/Licenses:/home/groupdocs/app/Licenses groupdocs/viewer-for-java-spring
93+
docker run -p 8080:8080 --env application.hostAddress=localhost -v `pwd`/DocumentSamples:/home/groupdocs/app/DocumentSamples -v `pwd`/Licenses:/home/groupdocs/app/Licenses groupdocs/viewer-for-java-spring
9494
## Open http://localhost:8080/viewer/ in your favorite browser.
9595
```
9696

configuration.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ server:
1414
application:
1515
# License path
1616
# Absolute or relative path to GroupDocs license file
17-
licensePath:
17+
licensePath:
18+
# Host name or ip for server instance
19+
hostAddress:
1820

1921
################################################
2022
# Common configurations

src/main/java/com/groupdocs/ui/config/ApplicationConfiguration.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
package com.groupdocs.ui.config;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
35
import org.springframework.beans.factory.annotation.Value;
46
import org.springframework.stereotype.Component;
57
import org.springframework.util.StringUtils;
68

79
import javax.annotation.PostConstruct;
810

11+
import java.net.InetAddress;
12+
import java.net.UnknownHostException;
13+
914
import static com.groupdocs.ui.config.DefaultDirectories.defaultLicenseDirectory;
1015
import static com.groupdocs.ui.config.DefaultDirectories.relativePathToAbsolute;
1116

1217
@Component
1318
public class ApplicationConfiguration {
19+
private static final Logger logger = LoggerFactory.getLogger(ApplicationConfiguration.class);
1420

21+
@Value("${application.hostAddress}")
22+
private String hostAddress;
1523
@Value("${application.licensePath}")
1624
private String licensePath;
1725

1826
@PostConstruct
1927
public void init() {
28+
if (StringUtils.isEmpty(hostAddress)) {
29+
try {
30+
hostAddress = InetAddress.getLocalHost().getHostAddress();
31+
} catch (UnknownHostException e) {
32+
logger.error("Can not get host address ", e);
33+
hostAddress = "localhost";
34+
}
35+
}
2036
this.licensePath = StringUtils.isEmpty(this.licensePath) ? defaultLicenseDirectory() : relativePathToAbsolute(this.licensePath);
2137
}
2238

39+
public String getHostAddress() {
40+
return hostAddress;
41+
}
42+
43+
public void setHostAddress(String hostAddress) {
44+
this.hostAddress = hostAddress;
45+
}
46+
2347
public String getLicensePath() {
2448
return licensePath;
2549
}
@@ -32,6 +56,7 @@ public void setLicensePath(String licensePath) {
3256
public String toString() {
3357
return "ApplicationConfiguration{" +
3458
"licensePath='" + licensePath + '\'' +
59+
", hostAddress='" + hostAddress + '\'' +
3560
'}';
3661
}
3762
}

src/main/java/com/groupdocs/ui/config/ServerConfiguration.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,14 @@
55
import org.springframework.beans.factory.annotation.Value;
66
import org.springframework.stereotype.Component;
77

8-
import javax.annotation.PostConstruct;
9-
import java.net.InetAddress;
10-
import java.net.UnknownHostException;
11-
128
@Component
139
public class ServerConfiguration {
1410
private static final Logger logger = LoggerFactory.getLogger(ServerConfiguration.class);
1511

1612
private Integer httpPort;
17-
private String hostAddress;
1813
@Value("#{servletContext.contextPath}")
1914
private String applicationContextPath;
2015

21-
@PostConstruct
22-
public void init() {
23-
try {
24-
hostAddress = InetAddress.getLocalHost().getHostAddress();
25-
} catch (UnknownHostException e) {
26-
logger.error("Can not get host address ", e);
27-
hostAddress = "localhost";
28-
}
29-
}
30-
3116
public Integer getHttpPort() {
3217
return httpPort;
3318
}
@@ -36,14 +21,6 @@ public void setHttpPort(Integer httpPort) {
3621
this.httpPort = httpPort;
3722
}
3823

39-
public String getHostAddress() {
40-
return hostAddress;
41-
}
42-
43-
public void setHostAddress(String hostAddress) {
44-
this.hostAddress = hostAddress;
45-
}
46-
4724
public String getApplicationContextPath() {
4825
return applicationContextPath;
4926
}
@@ -56,7 +33,6 @@ public void setApplicationContextPath(String applicationContextPath) {
5633
public String toString() {
5734
return "ServerConfiguration{" +
5835
"httpPort=" + httpPort +
59-
", hostAddress='" + hostAddress + '\'' +
6036
", applicationContextPath='" + applicationContextPath + '\'' +
6137
'}';
6238
}

src/main/resources/defaultConfiguration.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ server:
1414
application:
1515
# License path
1616
# Absolute or relative path to GroupDocs license file
17-
licensePath:
17+
licensePath:
18+
# Host name or ip for server instance
19+
hostAddress:
1820

1921
################################################
2022
# Common configurations

src/main/resources/templates/viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/*<![CDATA[*/
2020
$('#element').viewer({
2121
/*[+
22-
applicationPath: 'http://' + [[${globalConfiguration.server.hostAddress}]] + ':' + [[${globalConfiguration.server.httpPort}]] + [[${globalConfiguration.server.applicationContextPath}]] + '/viewer',
22+
applicationPath: 'http://' + [[${globalConfiguration.application.hostAddress}]] + ':' + [[${globalConfiguration.server.httpPort}]] + [[${globalConfiguration.server.applicationContextPath}]] + '/viewer',
2323
+]*/
2424
defaultDocument: /*[[${viewerConfiguration.defaultDocument}]]*/'',
2525
htmlMode: /*[[${viewerConfiguration.htmlMode}]]*/'',

0 commit comments

Comments
 (0)