?? publisher.java
字號:
/* * 20020407
* Publisher.java
* Publishes a SOAP service over JXTA.
*/
package ch20.peer;
import ch20.peer.JXTAPeer;
import ch20.peer.HttpConnection;
import java.util.Enumeration;
import java.io.*;
import java.net.*;
import java.net.MalformedURLException;
import net.jxta.pipe.PipeID;
import net.jxta.document.TextElement;
import net.jxta.platform.Application;
import net.jxta.document.Advertisement;
import net.jxta.document.AdvertisementFactory;
import net.jxta.document.StructuredDocumentFactory;
import net.jxta.document.StructuredTextDocument;
import net.jxta.document.StructuredDocument;
import net.jxta.document.MimeMediaType;
import net.jxta.document.Element;
import net.jxta.document.StructuredDocumentUtils;
import net.jxta.endpoint.Message;
import net.jxta.pipe.PipeService;
import net.jxta.id.IDFactory;
import net.jxta.pipe.OutputPipe;
import net.jxta.pipe.InputPipe;
import net.jxta.id.ID;
import net.jxta.platform.ModuleClassID;
import net.jxta.pipe.InputPipe;
import net.jxta.peergroup.PeerGroup;
import net.jxta.peergroup.PeerGroupID;
import net.jxta.peergroup.PeerGroupFactory;
import net.jxta.protocol.PeerGroupAdvertisement;
import net.jxta.protocol.ModuleSpecAdvertisement;
import net.jxta.protocol.ModuleClassAdvertisement;
import net.jxta.protocol.PipeAdvertisement;
import net.jxta.discovery.DiscoveryService;
import net.jxta.exception.PeerGroupException;
import net.jxta.impl.peergroup.Platform;
import net.jxta.impl.peergroup.GenericPeerGroup;
import net.jxta.pipe.PipeMsgEvent;
public class Publisher extends JXTAPeer{
public Publisher() {
super();
setInputPipeMessageListener(this);
}//constructor
public void pipeMsgEvent ( PipeMsgEvent event ){
receiver.setText(receiver.getText()+"\nMessage received");
Message SOAPRequest = event.getMessage();
String SOAPServiceName = SOAPRequest.getString("ServiceName");
receiver.setText(receiver.getText()+"\n"+
"Service invocation request for: "+
SOAPServiceName);
// SOAP authoring:
StringBuffer sh = new StringBuffer();
sh.append("<?xml version=\'1.0\' encoding=\'UTF-8\'?>\r\n");
sh.append("<SOAP-ENV:Envelope");
sh.append("\r\n");
sh.append(" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" ");
sh.append("\r\n");
sh.append(" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
sh.append("\r\n");
sh.append(" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">");
sh.append("\r\n");
sh.append(
" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding\">");
sh.append("\r\n");
sh.append(" <SOAP-ENV:Body>");
sh.append("\r\n");
sh.append("<NS:invoke xmlns:NS='"+SOAPServiceName+"'>");
sh.append("</NS:invoke>");
sh.append(" </SOAP-ENV:Body>\r\n");
sh.append("</SOAP-ENV:Envelope>\r\n");
// HTTP related stuff.
HttpConnection connection;
String response = "";
try{
connection =
new HttpConnection("http://localhost/soap/servlet/rpcrouter",
8080,
"text/xml",
"POST",
sh.toString()
);
connection.setRequestProperty (
"SOAPAction:", "\"\"");
response = connection.call();
} catch(Exception e) {
receiver.setText(receiver.getText()+"\n"+
"Error connecting to SOAP server");
}//catch
// Return path.
String ResponsePipeName = SOAPRequest.getString("SOAPResponse");
// Send the response back.
createOutputPipeAndSendMessage(
ResponsePipeName,response);
receiver.setText(receiver.getText()+"\n"+
"SOAP Response sent");
}//pipeMsgEvent
}// end Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -