10
10
import java .io .IOException ;
11
11
import java .io .OutputStream ;
12
12
import java .net .HttpURLConnection ;
13
+ import java .net .InetAddress ;
13
14
import java .net .URL ;
15
+ import java .net .UnknownHostException ;
14
16
import java .util .Arrays ;
15
17
import java .util .Enumeration ;
16
18
import java .util .List ;
@@ -26,7 +28,6 @@ public class ExportServlet extends HttpServlet {
26
28
private final String [] supportedServices = {"EXPORT_URL" , "PLANTUML_URL" , "VSD_CONVERT_URL" , "EMF_CONVERT_URL" };
27
29
@ Value ("${server.port}" )
28
30
private String port ;
29
- private final String EXPORT_URL = "http://localhost:" + port + "/" ;
30
31
31
32
private void doRequest (String method , HttpServletRequest request ,
32
33
HttpServletResponse response ) throws ServletException , IOException {
@@ -60,8 +61,8 @@ private void doRequest(String method, HttpServletRequest request,
60
61
// Ignore and use 0
61
62
}
62
63
64
+ String EXPORT_URL = getExportUrl ();
63
65
String exportUrl = System .getenv (supportedServices [serviceId ]);
64
-
65
66
if (exportUrl == null ) {
66
67
exportUrl = EXPORT_URL ;
67
68
}
@@ -136,6 +137,7 @@ private void doRequest(String method, HttpServletRequest request,
136
137
/**
137
138
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
138
139
*/
140
+ @ Override
139
141
protected void doGet (HttpServletRequest request ,
140
142
HttpServletResponse response ) throws ServletException , IOException {
141
143
doRequest ("GET" , request , response );
@@ -144,8 +146,17 @@ protected void doGet(HttpServletRequest request,
144
146
/**
145
147
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
146
148
*/
149
+ @ Override
147
150
protected void doPost (HttpServletRequest request ,
148
151
HttpServletResponse response ) throws ServletException , IOException {
149
152
doRequest ("POST" , request , response );
150
153
}
154
+
155
+ private String getIP () throws UnknownHostException {
156
+ return InetAddress .getLocalHost ().getHostAddress ();
157
+ }
158
+
159
+ private String getExportUrl () throws UnknownHostException {
160
+ return "http://" + getIP () + ":" + port + "/" ;
161
+ }
151
162
}
0 commit comments