webservicesexample.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 111 行
JAVA
111 行
package Jt.examples;
import java.util.Date;
import Jt.*;
import Jt.axis.JtWebServicesAdapter;
/**
* Demonstrates the use of the Jt Web Service Adapter (JtWebServicesAdapter).
*/
public class WebServicesExample {
private static final long serialVersionUID = 1L;
public static final String GET_DATE = "GET_DATE";
public static final String GET_DATE_TIME = "GET_DATE_TIME";
public WebServicesExample () {
}
public static void main(String[] args) {
JtObject factory = new JtObject ();
JtWebServicesAdapter adapter;
Date reply = null;
Exception ex;
JtMessage msg;
JtList col;
JtIterator iterator = null;
Long time;
JtProxy proxy;
// Create the Jt Web service Adapter
adapter = (JtWebServicesAdapter) factory.createObject (JtWebServicesAdapter.JtCLASS_NAME,
"service");
// Set the service url property (if it is not present in the resource file)
if (adapter.getUrl() == null)
adapter.setUrl("http://localhost:8080/axis/services/JtAxisService");
// Create a remote instance of the DateService class. The Jt Web service adapter
// can be used to create remote objects. A local proxy is returned.
msg = new JtMessage (JtWebServicesAdapter.JtCREATE_PROXY);
msg.setMsgContent("Jt.examples.DateService");
//msg.setMsgData("helloWorld");
proxy = (JtProxy) factory.sendMessage (adapter, msg);
//adapter.setValue("remote", "logging", "true");
//myService.setValue("remote", "logFile", "c:\\log.txt");
//adapter.setValue("remote", "logLevel", "10");
// Send a message to the remote DateService object
reply = (Date) factory.sendMessage (proxy, new JtMessage (WebServicesExample.GET_DATE));
//ex = (Exception) factory.getValue (adapter, "objException");
ex = (Exception) proxy.getObjException();
// Display the reply unless an exception is detected
if (ex == null)
System.out.println ("Date:" + reply);
// Request date and time
msg = new JtMessage (WebServicesExample.GET_DATE_TIME);
col = (JtList) adapter.sendMessage (proxy, msg);
//ex = (Exception) factory.getValue (adapter, "objException");
ex = (Exception) proxy.getObjException();
if (ex == null) {
if (col != null)
iterator = (JtIterator) col.getIterator();
msg = new JtMessage (JtIterator.JtNEXT);
if (iterator != null) {
reply = (Date) factory.sendMessage (iterator, msg);
System.out.println ("Date:" + reply);
time = (Long) factory.sendMessage (iterator, msg);
System.out.println ("Time:" + time);
}
}
// Remove the remote object and the adapter instance
adapter.removeObject (proxy);
factory.removeObject(adapter);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?