| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package sk.baka.webvm; |
| 20 | |
|
| 21 | |
import java.net.Inet4Address; |
| 22 | |
import java.net.InetAddress; |
| 23 | |
import java.net.NetworkInterface; |
| 24 | |
import java.util.Collections; |
| 25 | |
import java.util.Properties; |
| 26 | |
import java.util.logging.Level; |
| 27 | |
import java.util.logging.Logger; |
| 28 | |
import javax.naming.Context; |
| 29 | |
import org.apache.wicket.markup.html.basic.Label; |
| 30 | |
import sk.baka.tools.javaee.JeeServer; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public class AppServer extends WebVMPage { |
| 37 | |
|
| 38 | |
public AppServer(final JeeServer server) { |
| 39 | 0 | super(); |
| 40 | 0 | border.add(new Label("appServerName", server.getServerName())); |
| 41 | 0 | border.add(new Label("sampleCodeRemoteEjb", getSampleCodeRemoteEjb(server))); |
| 42 | 0 | border.add(new Label("userTransactionJndi", nullable(server.getUserTransactionJndi()))); |
| 43 | 0 | String tm = null; |
| 44 | |
try { |
| 45 | 0 | tm = nullable(server.getTransactionManagerJndi()); |
| 46 | 0 | } catch (Exception e) { |
| 47 | 0 | tm = e.toString(); |
| 48 | 0 | } |
| 49 | 0 | border.add(new Label("transactionManagerJndi", tm)); |
| 50 | 0 | border.add(new Label("managerLookupClass", nullable(server.getHibernateTransactionManagerFactory()))); |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
private static String nullable(final String str) { |
| 54 | 0 | return str == null ? "unknown" : str; |
| 55 | |
} |
| 56 | |
|
| 57 | |
private String getSampleCodeRemoteEjb(final JeeServer server) { |
| 58 | 0 | final StringBuilder sb = new StringBuilder(); |
| 59 | 0 | sb.append("final Properties p = new Properties();\n"); |
| 60 | 0 | final Properties p = server.getJNDIProperties(false); |
| 61 | 0 | p.put(Context.PROVIDER_URL, server.getRemoteURL(getMyIp(), null)); |
| 62 | 0 | for (Object key : p.keySet()) { |
| 63 | 0 | sb.append("p.put(\""); |
| 64 | 0 | sb.append(key); |
| 65 | 0 | sb.append("\", \""); |
| 66 | 0 | sb.append(p.get(key)); |
| 67 | 0 | sb.append("\");\n"); |
| 68 | |
} |
| 69 | 0 | sb.append("final Context c = new InitialContext(p);"); |
| 70 | 0 | return sb.toString(); |
| 71 | |
} |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
private static String getMyIp() { |
| 78 | |
try { |
| 79 | 0 | for (final NetworkInterface iface : Collections.list(NetworkInterface.getNetworkInterfaces())) { |
| 80 | 0 | for (final InetAddress ia : Collections.list(iface.getInetAddresses())) { |
| 81 | |
|
| 82 | 0 | if (ia instanceof Inet4Address && ia.getAddress()[0] != 127) { |
| 83 | 0 | return HomePage.getIP(ia); |
| 84 | |
} |
| 85 | |
} |
| 86 | |
} |
| 87 | 0 | } catch (Exception ex) { |
| 88 | 0 | log.log(Level.WARNING, "Failed to detect IP address of this machine", ex); |
| 89 | 0 | } |
| 90 | 0 | return "127.0.0.1"; |
| 91 | |
} |
| 92 | 0 | private final static Logger log = Logger.getLogger(AppServer.class.getName()); |
| 93 | |
} |