package ejava.webservices;
/**
* @author Perrone, Chaganti, and Schwenk
*
* J2EE Developer's Handbook
*
* Package: ejava.webservices
*
* Type: SOAPManager
*
*/
import javax.xml.soap.*;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.util.*;
import javax.activation.*;
public class SOAPManager {
private static final int MAX_BUFFER = 10000;
/**
* Prints Exception message and stack trace
* prepended with passed in info String
*/
public void printException(String info, Exception ex){
System.out.println("\n" + info
+ "\nException: " + ex.getMessage()
+ "\nStack Trace: ");
ex.printStackTrace();
System.out.println("\n");
}
/**
* Prints Exception message and stack trace
*/
public void printException(Exception ex){
printException("SOAPManager Exception...", ex);
}
/**
* Creates an empty SOAPMessage object
*/
public SOAPMessage createEmptyMessage(){
MessageFactory factory = null;
SOAPMessage message = null;
// Create a message factory
try{
factory = MessageFactory.newInstance();
}
catch(SOAPException e1){
printException(e1);
}
// Create an empty SOAP Message for our request
try{
message = factory.createMessage();
}
catch(SOAPException e1){
printException(e1);
}
return message;
}
/**
* Dump the guts of the SOAP Message to screen.
*/
public void printMessage(SOAPMessage msg)
throws SOAPException, IOException{
FileOutputStream fos = new FileOutputStream(FileDescriptor.out);
DataOutputStream dos = new DataOutputStream(fos);
msg.writeTo(dos);
fos.flush();
}
/**
* Dump the attachment of the SOAP Message to screen
*/
public void readAttachments(SOAPMessage msg)
throws SOAPException, IOException{
// Get an Iterator of attachments from the SOAP message
Iterator attachments = msg.getAttachments();
while(attachments.hasNext()){
// Get an AttachmentPart from the Iterator
AttachmentPart part = (AttachmentPart) attachments.next();
// Print AttachmentPart ID and headers
System.out.println("\nReading Attachment: "
+ part.getContentId());
Iterator headers = part.getAllMimeHeaders();
while(headers.hasNext()){
MimeHeader header = (MimeHeader) headers.next();
System.out.println("\n Header Name: "
+ header.getName());
System.out.println("\n Header Value: "
+ header.getValue());
}
System.out.println("\n Opening Display of Image ... ");
ImageReader ir = null;
// Get attachment content and pop up its display on client
Object content = part.getContent();
if(content instanceof InputStream){
ir = new ImageReader((InputStream) content);
}
else{
ir = new ImageReader((java.awt.Image) content);
}
ir.render();
}
}
/**
* Generates an HTTP response header to bake into response.
* MimeHeaders are read in order to generate such a header.
* Headers read from SOAPMessage are written to OutputStream.
*/
public void writeHttpHeader(SOAPMessage msg,
OutputStream outStream){
byte headerBytes[] = null;
boolean isNotMultipart = true;
String response = "HTTP/1.1 200 OK\n";
try{
// Read MimeHeaders
MimeHeaders mhs = msg.getMimeHeaders();
Iterator it = mhs.getAllHeaders();
// Read each MimeHeader name and value
// and build up response String.
while(it.hasNext()){
MimeHeader mh = (MimeHeader) it.next();
String name = mh.getName();
String value = mh.getValue();
response += name + ": " + value +"\n";
if(value.startsWith("multipart")){
isNotMultipart = false;
}
}
response += "\n";
System.out.println("\n\nHTTP Header\n"+response+"\n");
// Only print message if has no attachments.
if(isNotMultipart){
printMessage(msg);
}
// Write the HTTP header to the output stream
headerBytes = response.getBytes("utf-8");
outStream.write(headerBytes);
}
catch(Exception e){
printException(e);
}
}
/**
* Writes the SOAPMessage to an OutputStream.
* Induces the generation and writing of
* an HTTP header to the output stream.
*/
public void writeMessage(SOAPMessage response,
OutputStream outStream){
try{
if(response.saveRequired()){
response.saveChanges();
}
writeHttpHeader(response, outStream);
response.writeTo(outStream);
outStream.flush();
}
catch(Exception e){
printException("Trouble writing message", e);
}
}
/**
* Strip off HTTP header and return SOAP String
*/
public String readMessage(InputStream msg){
String soapString = "";
String inputString = "";
byte buffer[] = new byte[MAX_BUFFER];
try{
// While haven't read whole message
while(inputString.indexOf("/soap-env:Envelope>") == -1){
// read bytes from stream
int bytesRead = msg.read(buffer, 0, MAX_BUFFER);
// Set onto inputString
inputString += new String(buffer, 0, bytesRead);
}
soapString = inputString.substring(
inputString.indexOf("<soap-env:Envelope"));
System.out.println("SOAP Request Message...\n" + soapString);
}
catch(Exception e){
printException(e);
}
return soapString;
}
/**
* Simply returns SOAP Body from SOAPMessage
*/
public SOAPBody getBody(SOAPMessage msg){
SOAPBody soapBody = null;
try{
SOAPPart part = msg.getSOAPPart();
SOAPEnvelope env = part.getEnvelope();
soapBody = env.getBody();
}
catch(Exception e){
printException(e);
}
return soapBody;
}
/**
* Create a SOAPMessage (Attachments, Header, Body) from a HashMap
* and to be sent to the actor specified by the host and port
*/
public SOAPMessage createMessage(HashMap hashMessage,
String host, String port){
// Create empty SOAP Message, get Body and create Header
SOAPMessage msg = createEmptyMessage();
SOAPHeader header = createHeader(msg, host, port);
SOAPBody body = getBody(msg);
try{
// Get names of return objects
Ite
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
J2EE开发使用手册源码 (775个子文件)
runsax.bat 461B
testJAAS.config 157B
order.dtd 1KB
beeshirts.gif 15KB
beeshirts.gif 15KB
logotitle.gif 7KB
logotitle.gif 7KB
blobExample.gif 4KB
join.gif 2KB
join.gif 2KB
deliveryinfo.gif 2KB
termsandconditions.gif 2KB
order.gif 2KB
order.gif 2KB
termsandconditions.gif 2KB
deliveryinfo.gif 2KB
checkout.gif 1KB
checkout.gif 1KB
viewCart.gif 1KB
viewCart.gif 1KB
orderstatus.gif 1KB
orderstatus.gif 1KB
freebies.gif 1KB
freebies.gif 1KB
aboutus.gif 1KB
aboutus.gif 1KB
security.gif 1KB
security.gif 1KB
contact.gif 1KB
contact.gif 1KB
browse.gif 1KB
browse.gif 1KB
delivery.gif 1KB
delivery.gif 1KB
terms.gif 1KB
terms.gif 1KB
registration.html 8KB
deliveryinformation.html 2KB
Customer.idl 491B
Customer.idl 454B
QueryServer.idl 369B
Sample.idl 215B
Order.idl 195B
SampleDynamic.idl 176B
ClientReceiver.idl 171B
SAMPLE~4.JAV 4KB
AUDITV~1.JAV 1KB
CLIENT~1.JAV 945B
CLIENT~1.JAV 916B
CUSTOM~3.JAV 716B
CLIENT~2.JAV 599B
CLIENT~2.JAV 577B
SOAPManager.java 19KB
JAXRClient.java 18KB
OrderStatusServlet.java 16KB
ScrollableResultSetExample.java 16KB
UpdateableResultSetExample.java 14KB
OrderManagerEJBean.java 14KB
CustomerManagerEJBean.java 13KB
ServletsHelper.java 13KB
SampleSearchExample.java 12KB
GenerateDSMLResponse.java 12KB
WebHelper.java 11KB
GenerateDSMLRequest.java 11KB
NewSQLTypeExample.java 11KB
MailClient.java 11KB
CreditDBAccess.java 10KB
ShoppingCartEJBean.java 10KB
SampleSearchExampleNDS.java 10KB
DOMExample.java 9KB
CreditEJBean.java 9KB
QueryClient.java 9KB
BatchUpdatesExample.java 8KB
ResultSetExample.java 8KB
BrowseShirtsServlet.java 8KB
RegistrationServlet.java 8KB
QueryServerImplementation.java 7KB
CreditManagerClient.java 7KB
SOAPClient.java 7KB
ListContentsAModule.java 7KB
QueryServerImplementation.java 7KB
QueryServerImpl.java 7KB
CustomerServer.java 7KB
SampleListAndSearchExample.java 7KB
CustomerServiceRemote.java 7KB
SimplePreparedStatementExample.java 7KB
SOAPMessageHelper.java 7KB
QueryServerImplementation.java 7KB
Client.java 6KB
TopicConsumer.java 6KB
TopicReplyConsumer.java 6KB
CustomerTradingClient.java 6KB
CartServlet.java 6KB
TopicRequestSupplier.java 6KB
QueryServerImplementation.java 6KB
DatabaseHelper.java 6KB
TestClient.java 6KB
TShirt.java 6KB
Order.java 6KB
QueueConsumer.java 6KB
共 775 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
周廉贵
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0