아래의 코드를 복사하셔서 web application context에 vm.jsp로 저장하신 후 확인하시면 됩니다.
<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.net.InetAddress" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%
if (request.getParameter("gc") != null) {
System.gc();
System.runFinalization();
}
Properties p = System.getProperties();
%>
<HTML>
<HEAD>
<META content="text/html; charset=euc-kr" http-equiv=Content-Type>
<!--META http-equiv="Refresh" content="10;url=<%= request.getRequestURI() %>"-->
<link href="style.css" rel=stylesheet type="text/css">
</HEAD>
<body leftmargin=15 topmargin=10>
<center><p>
<table width="600" cellpadding="7" cellspacing="0" border="1" bordercolordark="WHITE" bordercolorlight="BLACK">
<tr><td>
■ HOST : <%= InetAddress.getLocalHost().getHostName() %>
(<%= InetAddress.getLocalHost().getHostAddress() %>)
<% SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z", Locale.CHINA); %>
■ Current Time : <%= formatter.format(new Date()) %>
</td></tr>
<tr><td align=center>
<%
Runtime rt = Runtime.getRuntime();
long free = rt.freeMemory();
long total = rt.totalMemory();
long usedRatio = (total - free) * 100 / total;
long unusedRatio = free * 100 / total;
%>
<table width=100% bgcolor="lightgrey" border=1 cellpadding=6 cellspacing=0>
<tr>
<td align="center" colspan="2">Total Java Virual Machine Memory (<b><%= total/1024 %> KB</b>)</td>
</tr>
<tr bgcolor=#E3E3E3>
<td align="center">Used Memory (<b><%= (total - free)/1024 %> KB</b>)</td>
<td align="center">Available Memory (<b><%= free/1024 %> KB</b>)</td>
</tr>
<tr bgcolor=#E8EEEC>
<td><hr color="#CC3366" align=left size=10 width="<%= usedRatio %>%" noshade>
(<%= usedRatio %> %)</td>
<td><hr color="#0066FF" align=left size=10 width="<%= unusedRatio %>%" noshade>
(<%= unusedRatio %> %)</td>
</tr>
</table>
<p>
<a href="<%= request.getRequestURI() %>?gc=">
<img src="trash.gif" valign=middle border=0> Execution GC</a>
<a href="<%= request.getRequestURI() %>">
<img src="refresh.gif" valign=middle border=0> Reload</a>
</td></tr>
</table>
</center>
</BODY>
</HTML>
package com.jboss.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
/**
* This is a webservice class exposing a method called greet which takes a input
* parameter and greets the parameter with hello.
*
* @author Ji-Woong Choi
*/
/*
* @WebService indicates that this is webservice interface and the name
* indicates the webservice name.
*/
@WebService(name = "Hello", targetNamespace="http://client.jboss.com/", serviceName="GreetService")
/*
* @SOAPBinding indicates binding information of soap messages. Here we have
* document-literal style of webservice and the parameter style is wrapped.
*/
//@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public class Hello {
/**
* This method takes a input parameter and appends "Hello" to it and returns
* the same.
*
* @param name
* @return
*/
@WebMethod
public String greet(@WebParam(name = "name")
String name) {
System.out.println("JBoss Web Service was invoked by " + name);
return "Hello!, " + name;
}
}
Web Service Annotation을 이용하여 필요한 메소드들을 구성합니다.
2. Web.xml 파일을 편집합니다. 본 예제에서는 servlet style을 이용하여 처리합니다.
다른 방법으로는 EJB를 이용하여 port proxy를 remote stub을 이용하는 방법이 있지만 web이 테스트하기 보다 단순하므로 이 예제를 이용하겠습니다.
3. 서버에 디플로이 후 Web Service에 대한 deploy상태를 확인합니다.
http://localhost:8080/jbossws/ 라고 입력하면 웹서비스 리스트를 확인할 수 있습니다.
4. WSDL의 디플로이된 상태를 확인합니다.
5. 이제 클라이언트 코드를 작성합니다. 여기서는 DII방식(Dynamic Invocation Interface) 방식을 이용하여 작성합니다.
위의 코드를 실행하면 서버에 System console에 적은 내용이 찍히게 되며, 클라이언트에서 응답을 받을 수 있습니다.
연결이 되면 아래의 그림처럼 VM 상황에 대한 자세한 정보를 확인할 수 있습니다.#
# Specify options to pass to the Java VM.
#
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-server -Xms128m -Xmx128m"
fi
# Enable the jconsole agent locally
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote"
그런 다음 $JAVA_HOME/bin/jconsole을 실행시키면 다음의 화면이 나타납니다.
[jchoi@/opt/java1.5]jconsole
#
# Specify options to pass to the Java VM.
#
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-server -Xms128m -Xmx128m"
fi
# Enable the jconsole agent remotely on port 12345
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=12345"
만약 security 옵션을 사용하지 않고 모니터링하고 싶다는 다음과 같이 start shell을 꾸며주면 됩니다.
# Enable the jconsole agent remotely on port 8888
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=8888"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
위의 옵션을 준 후 jconsole을 실행시켜 remote탭을 보게 되면 연결할 수 있습니다.