1 57 58 package mime; 59 60 import java.awt.Image ; 61 import java.io.File ; 62 import java.io.IOException ; 63 import java.io.InputStream ; 64 65 import javax.activation.DataHandler ; 66 import javax.activation.FileDataSource ; 67 import javax.swing.ImageIcon ; 68 69 import util.TestUtilities; 70 71 75 76 public class MimeImpl { 77 78 public String dataHandlerToString(DataHandler dh) { 79 try { 80 InputStream is = dh.getInputStream(); 81 byte[] bBuff = new byte[is.available()]; 82 is.read(bBuff); 83 String sBuff = new String (bBuff); 84 return sBuff; 85 } catch (IOException ioe) { 86 ioe.printStackTrace(); 87 return null; 88 } 89 } 90 91 public DataHandler stringToDataHandler(String buff) { 92 try { 93 FileDataSource fds = getTempFile(); 94 fds.getOutputStream().write(buff.getBytes()); 95 DataHandler dh = new DataHandler (fds); 96 return dh; 97 } catch (IOException ioe) { 98 ioe.printStackTrace(); 99 return null; 100 } 101 } 102 103 public String plainTextToString(DataHandler ds) { 104 try { 105 InputStream is = ds.getInputStream(); 106 byte[] bBuff = new byte[is.available()]; 107 is.read(bBuff); 108 String sBuff = new String (bBuff); 109 return sBuff; 110 } catch (IOException ioe) { 111 ioe.printStackTrace(); 112 return null; 113 } 114 } 115 116 public DataHandler stringToPlainText(String buff) { 117 try { 118 FileDataSource fds = getTempFile(); 119 fds.getOutputStream().write(buff.getBytes()); 120 return new DataHandler (fds); 121 } catch (IOException ioe) { 122 ioe.printStackTrace(); 123 return null; 124 } 125 } 126 127 public DataHandler bounceImage(DataHandler ds) { 128 try { 129 InputStream is = ds.getInputStream(); 130 byte[] bBuff = new byte[is.available()]; 131 is.read(bBuff); 132 133 148 FileDataSource fds = getTempFile(); 149 fds.getOutputStream().write(bBuff); 150 return new DataHandler (fds); 151 } catch (Exception e) { 152 e.printStackTrace(); 153 return null; 154 } finally { 155 WSIFFrame.close(); 156 } 157 } 158 159 public DataHandler bounceImage2(DataHandler ds) { 160 return bounceImage(ds); 161 } 162 163 public DataHandler bounceImage4(boolean b, DataHandler ds) { 165 if (b && (ds != null)) 170 return bounceImage(ds); 171 else 172 return null; 173 } 174 175 public String orMultiMimeParts(DataHandler dh) { 176 return dh.getContentType(); 177 } 178 179 public String andMultiMimeParts(DataHandler dh1, DataHandler dh2) { 180 try { 181 InputStream is1 = dh1.getInputStream(); 182 byte[] bBuff1 = new byte[is1.available()]; 183 is1.read(bBuff1); 184 StringBuffer sBuff = new StringBuffer (new String (bBuff1)); 185 186 InputStream is2 = dh2.getInputStream(); 187 byte[] bBuff2 = new byte[is2.available()]; 188 is2.read(bBuff2); 189 sBuff.append(new String (bBuff2)); 190 191 return sBuff.toString(); 192 } catch (IOException ioe) { 193 ioe.printStackTrace(); 194 return null; 195 } 196 } 197 198 202 public String noContent(String s) { 203 return s; 204 } 205 206 public String typeStar(DataHandler dh) { 207 return dataHandlerToString(dh); 208 } 209 210 public String soapBodyParts1(boolean shouldBounce, DataHandler dh) { 211 return "1"; 212 } 213 214 public String soapBodyParts2(DataHandler dh) { 215 return "2"; 216 } 217 218 public String soapBodyParts3(boolean shouldBounce) { 219 return "3"; 220 } 221 222 public String soapBodyParts4() { 223 return "4"; 224 } 225 226 public String arrayOfBinary(DataHandler dh) { 227 return dataHandlerToString(dh); 228 } 229 230 public DataHandler optionalSoapBody(DataHandler ds) { 231 return bounceImage(ds); 232 } 233 234 public String mixMimeParts( 235 String pos1, 236 DataHandler dh1, 237 String pos2, 238 DataHandler dh2, 239 String pos3) 240 { 241 return pos1 242 + dataHandlerToString(dh1) 243 + pos2 244 + dataHandlerToString(dh2) 245 + pos3; 246 } 247 248 249 250 public String badNoPart(DataHandler dh) { 251 return dataHandlerToString(dh); 252 } 253 254 public String badPart(DataHandler dh) { 255 return dataHandlerToString(dh); 256 } 257 258 public String badNested(DataHandler dh) { 259 return dataHandlerToString(dh); 260 } 261 262 public String badMixSoapMime(DataHandler dh) { 263 return dataHandlerToString(dh); 264 } 265 266 public String badMultipleSoapBodies(DataHandler dh) { 267 return dataHandlerToString(dh); 268 } 269 270 public String badSoapBodyType(DataHandler dh) { 271 return dataHandlerToString(dh); 272 } 273 274 275 276 private FileDataSource getTempFile() throws IOException { 277 File f = File.createTempFile("WSIFMimeTest", "txt"); 278 f.deleteOnExit(); 279 return new FileDataSource (f); 280 } 281 } 282 | Popular Tags |