jtaxisadapter.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 284 行
JAVA
284 行
package Jt.axis;
import Jt.*;
import Jt.xml.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
/**
* Jt Adapter for the Axis API.
*/
public class JtAxisAdapter extends JtAdapter {
private static final long serialVersionUID = 1L;
public static final String JtCLASS_NAME = JtAxisAdapter.class.getName();
private String url = null;
private Service service = null;
private Call call = null;
private String remoteLogFile;
public JtAxisAdapter() {
}
// Attributes
/**
* Specifies the service URL.
* @param url service url
*/
public void setUrl (String url) {
this.url = url;
}
/**
* Returns the service URL.
*/
public String getUrl () {
return (url);
}
/**
* Returns the name of the remote log file
*/
public String getRemoteLogFile () {
return (remoteLogFile);
}
/**
* Specifies the name of the remote log file
* @param remoteLogFile remote log file
*/
public void setRemoteLogFile (String remoteLogFile) {
this.remoteLogFile = remoteLogFile;
}
// Process object messages
public Object processMessage (Object event) {
String msgid = null;
JtMessage e = (JtMessage) event;
Object content;
if (e == null)
return null;
msgid = (String) e.getMsgId ();
if (msgid == null)
return null;
content = e.getMsgContent();
this.setObjException(null);
if (msgid.equals (JtScriptInterpreter.JtSCRIPT)) {
return (processJtScript ((String) content));
}
if (msgid.equals (JtObject.JtREMOVE)) {
return (null);
}
return (super.processMessage(event));
//handleError ("JtAxisAdapter.processMessage: invalid message id:" + msgid);
//return (null);
}
private Object processJtScript (String xmlMsg)
{
String ret = null;
JtXMLHelper xmlHelper = null;
JtMessage msg = new JtMessage (JtObject.JtXML_DECODE);
//String xmlOutput = null;
Object tmp, tmp1, output = null;
JtIterator it;
if (xmlMsg == null)
return (null);
try { // check xmlMsg
if (service == null) {
service = new Service();
//service.setMaintainSession (true);
call = (Call) service.createCall();
if (url == null) {
handleError ("processxmlMessage: invalid attribute value: url (null)");
return (null);
}
call.setTargetEndpointAddress( new java.net.URL(url) );
call.setMaintainSession (true);
// check
//call.setOperationName( new QName("http://example3.userguide.samples", "processMessage") );
call.setOperationName("processMessage");
call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
}
ret = (String) call.invoke( new Object[] { xmlMsg } );
} catch (Exception e) {
handleException (e);
return (null);
}
if (xmlHelper == null)
xmlHelper = new JtXMLHelper ();
// Convert XML message back to its object
// representation
msg.setMsgContent (ret);
handleTrace ("JtAxisAdapter.processJtScript(returned message from service invocation):\n" + ret);
//tmp = sendMessage (xmlHelper, msg);
tmp = xmlHelper.processMessage(msg);
if (!(tmp instanceof JtList)) {
handleError ("Fatal Error:" + ret);
return null;
}
//it = (JtIterator) getValue (tmp, "iterator");
it = (JtIterator) ((JtList) tmp).getIterator();
if (it == null) {
//handleError ("Fatal Error:" + ret);
return (null);
}
output = it.processMessage (new JtMessage (JtIterator.JtNEXT));
if (output instanceof JtNull) {
output = null;
}
if (((JtList) tmp).getSize() < 2) {
return (output);
}
tmp1 = it.processMessage (new JtMessage (JtIterator.JtNEXT));
if (tmp1 != null && tmp1 instanceof Exception) {
handleError ("JtAxisAdapter.processJtScript: remote exception detected");
if (tmp1 instanceof JtRemoteException)
handleWarning ("<Remote Exception>\n" +
((JtRemoteException) tmp1).getTrace () + "</Remote Exception>\n");
//setValue (this, "objException", tmp1);
}
return (output);
// If it is a list, an exception was detected
/*
if (tmp instanceof JtList) {
it = (JtIterator) getValue (tmp, "iterator");
if (it == null)
return (null);
for (;;) {
//tmp1 = sendMessage (it, new JtMessage ("JtNEXT"));
tmp1 = it.processMessage (new JtMessage ("JtNEXT"));
if (tmp1 == null)
break;
if (tmp1 instanceof Exception) {
handleError ("JtAxisAdapter.processJtScript: remote exception detected");
if (tmp1 instanceof JtRemoteException)
handleWarning ("<Remote Exception>\n" +
((JtRemoteException) tmp1).getTrace () + "</Remote Exception>\n");
//setValue (this, "objException", tmp1);
} else
output = tmp1; // check size
}
return (output); // check
} else
return (tmp);
*/
}
/**
* Demonstrates all the message processed by JtAxisAdapter
*/
public static void main(String[] args) {
JtObject main = new JtObject ();
JtMessage msg;
JtAxisAdapter adapter;
/*
String st = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<Object>\n" +
"<classname>Jt.JtList</classname>\n" +
"<Object>\n" +
"<classname>Jt.JtMessage</classname>\n" +
"<msgId>JtCREATE_OBJECT</msgId>\n" +
"<msgContent>Jt.JtObject</msgContent>\n" +
"<msgData>test</msgData>\n" +
"</Object>\n";
*/
//main.setLogFile ("log.txt");
msg = new JtMessage ();
msg.setMsgId (JtScriptInterpreter.JtSCRIPT);
msg.setMsgContent ("Hello world");
// Create template object
adapter = (JtAxisAdapter) main.createObject (JtAxisAdapter.JtCLASS_NAME, "adapter");
main.setValue (adapter, "url",
"http://localhost:8080/axis/services/MyService");
main.sendMessage (adapter, msg);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?