1 23 package com.sun.enterprise.jbi.serviceengine.bridge.transport; 24 25 26 import com.sun.xml.ws.spi.runtime.WSConnection; 27 import java.io.ByteArrayInputStream ; 28 import java.io.InputStream ; 29 import java.io.OutputStream ; 30 import java.nio.ByteBuffer ; 31 import java.util.ArrayList ; 32 import java.util.HashMap ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.io.ByteArrayOutputStream ; 36 import java.io.IOException ; 37 import java.io.ObjectInputStream ; 38 import java.io.ObjectOutputStream ; 39 import javax.jbi.messaging.MessageExchange; 40 import javax.xml.soap.SOAPMessage ; 41 import javax.xml.soap.MessageFactory ; 42 46 public abstract class NMRConnection implements WSConnection { 47 48 Map <String , List <String >> headers = new HashMap <String , List <String >>(); 49 public OutputStream debugStream = null; 50 public OutputStream outputStream = null; 51 public InputStream inputStream = null; 52 int statusCode; 53 static String CONTENT_TYPE_HEADER = "Content-Type"; 54 static String XML_CONTENT_TYPE = "text/xml"; 55 56 public int getStatus () { 57 return statusCode; 58 } 59 60 public void setStatus (int statusCode) { 61 this.statusCode = statusCode; 62 } 63 64 public OutputStream getDebug () { 65 return debugStream; 66 } 67 68 74 public OutputStream getOutput() { 75 outputStream = new ByteArrayOutputStream (); 76 77 return outputStream; 78 } 79 80 86 public InputStream getInput() { 87 88 return inputStream; 90 } 91 92 public Map <String , List <String >> getHeaders () { 93 return headers; 94 } 95 96 public void setHeaders (Map <String , List <String >> headers) { 97 this.headers = headers; 98 } 99 100 101 protected void createSOAPMessageInputStream(SOAPMessage soapMessage) { 102 if(soapMessage != null) { 103 try { 104 105 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 106 soapMessage.writeTo(baos); 107 inputStream = new ByteArrayInputStream (baos.toByteArray()); 108 } catch(Exception soapException) { 109 soapException.printStackTrace(); 110 throw new TransportFailedException(soapException.getMessage()); 111 } 112 } 113 } 114 115 protected SOAPMessage createSOAPMessageFromOutputStream(){ 116 ObjectInputStream objInputStream = null; 117 try { 118 119 if (outputStream != null) { 120 outputStream.flush(); 121 outputStream.close(); 122 byte[] message = ((ByteArrayOutputStream )outputStream).toByteArray(); 123 124 ByteArrayInputStream is = new ByteArrayInputStream (message); 125 SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null,is); 126 return soapMessage; 127 } 128 } catch(Exception e) { 129 throw new TransportFailedException(e.getMessage()); 130 } finally { 131 try { 132 if(objInputStream != null) 133 objInputStream.close(); 134 } catch(Exception ioe) { 135 ioe.printStackTrace(); 136 } 137 } 138 return null; 139 } 140 141 protected void setContentType() { 142 List <String > ctHeader = new ArrayList <String >(); 143 ctHeader.add(XML_CONTENT_TYPE); 144 headers.put(CONTENT_TYPE_HEADER, ctHeader); 145 } 146 147 public void closeInput() {} 148 public void closeOutput() {} 149 public void close() {} 150 151 } 152 | Popular Tags |