1 package com.sun.xml.registry.ebxml; 2 3 import java.io.*; 4 import java.net.*; 5 import java.util.*; 6 7 import javax.activation.*; 8 import javax.xml.registry.*; 9 import javax.xml.registry.infomodel.*; 10 11 /* 12 * 13 * $Header: /cvsroot/ebxmlrr/jaxr/test/com/sun/xml/registry/ebxml/SoapMessengerTest.java,v 1.5 2002/11/09 01:44:09 jasilva Exp $ 14 * 15 */ 16 17 public class SoapMessengerTest { 18 public static void out(String s) { 19 System.out.println(s); 20 } 21 22 public static void outp(String s) { 23 System.out.print(s); 24 } 25 26 static String toName(Object registryObject) throws JAXRException { 27 RegistryObject ro = (RegistryObject)registryObject; 28 return ro.getName().getValue(); 29 } 30 31 static String toStatusString(int status) throws JAXRException { 32 if (status == JAXRResponse.STATUS_FAILURE) { 33 return "STATUS_FAILURE"; 34 } else if (status == JAXRResponse.STATUS_SUCCESS) { 35 return "STATUS_SUCCESS"; 36 } else if (status == JAXRResponse.STATUS_UNAVAILABLE) { 37 return "STATUS_UNAVAILABLE"; 38 } else if (status == JAXRResponse.STATUS_WARNING) { 39 return "STATUS_WARNING"; 40 } else { 41 return "[unkown status]"; 42 } 43 } 44 45 static void outResponse(BulkResponse br) throws JAXRException { 46 out("BulkResponse: status=" + toStatusString(br.getStatus())); 47 outCollection(br.getCollection(), " .collection:"); 48 outCollection(br.getExceptions(), " .exceptions:"); 49 } 50 51 static void outCollection(Collection col, String prompt) 52 throws JAXRException 53 { 54 outp(prompt); 55 if (col == null || col.size() == 0) { 56 out(" [empty collection]"); 57 return; 58 } 59 out(""); 60 for (Iterator it = col.iterator(); it.hasNext(); ) { 61 Object obj = it.next(); 62 if (obj instanceof RegistryObject) { 63 RegistryObject ro = (RegistryObject)obj; 64 String objType = ro.getObjectType() != null ? 65 ro.getObjectType().getValue() : "null"; 66 out(" name=" + toName(obj) + ", type=" 67 + obj.getClass().getName() 68 + ", objType=" + objType); 69 } else { 70 out(" obj=" + obj); 71 } 72 } 73 } 74 75 private static void usage() { 76 System.err.println("Usage: xxxTest [-opts] <SQL query>"); 77 System.err.println(" -qm1"); 78 System.err.println(" -[no]proxy"); 79 System.err.println(" -usage or -help = this message"); 80 System.err.println(" req=<requestFile.xml>"); 81 System.err.println(" attach=<file>,mimeType,id"); 82 System.exit(1); 83 } 84 85 public static void main(String[] args) throws Exception 86 { 87 String qmUrl = "http://localhost:8081/ebxmlrr/registry"; 88 boolean useProxy = true; 89 String qs = null; 90 String reqFileName = null; 91 ArrayList attachList = new ArrayList(); 92 93 for (int i = 0; i < args.length; i++) { 94 if (args[i].equals("-qm0")) { 95 // use default 96 } else if (args[i].equals("-qm1")) { 97 qmUrl = "http://registry.csis.hku.hk:8201/ebxmlrr/registry"; 98 } else if (args[i].equals("-proxy")) { 99 useProxy = true; 100 } else if (args[i].equals("-noproxy")) { 101 useProxy = false; 102 } else if (args[i].equals("-usage")) { 103 usage(); 104 } else if (args[i].equals("-help")) { 105 usage(); 106 } else if (args[i].startsWith("req=")) { 107 reqFileName = args[i].substring(4); 108 } else if (args[i].startsWith("attach=")) { 109 StringTokenizer tokenizer = 110 new StringTokenizer(args[i], "=,"); 111 112 String attachFileName = null; 113 String mimeType = "text/plain"; 114 String attachId = "id"; 115 116 int j=0; 117 while ( tokenizer.hasMoreTokens() ) { 118 String token = tokenizer.nextToken(); 119 if (j==1) { 120 attachFileName = token; 121 } 122 else if (j==2) { 123 mimeType = token; 124 } 125 if (j==3) { 126 attachId = token; 127 } 128 j++; 129 } 130 131 AttachmentInfo ai = new AttachmentInfo(attachFileName, mimeType, attachId); 132 attachList.add(ai); 133 } else { 134 qs = args[i]; 135 136 // Must be last arg 137 if (i != args.length - 1) { 138 usage(); 139 } 140 } 141 } 142 143 if (useProxy) { 144 System.setProperty("http.proxyHost", "webcache"); 145 System.setProperty("http.proxyPort", "8080"); 146 System.setProperty("http.noProxyHosts", "localhost"); 147 } 148 149 ConnectionFactory connFactory = new ConnectionFactoryImpl(); 150 151 Properties props = new Properties(); 152 props.put("javax.xml.registry.queryManagerURL", qmUrl); 153 // props.put("javax.xml.registry.lifeCycleManagerURL", lcmUrl); 154 connFactory.setProperties(props); 155 Connection connection = connFactory.createConnection(); 156 RegistryServiceImpl service = (RegistryServiceImpl) 157 connection.getRegistryService(); 158 159 BusinessQueryManager bqm = service.getBusinessQueryManager(); 160 BusinessLifeCycleManager lcm = service.getBusinessLifeCycleManager(); 161 DeclarativeQueryManager dqm = service.getDeclarativeQueryManager(); 162 163 SoapMessenger sm = service.getSoapMessenger(); 164 165 StringBuffer sb = InputStreamToStringBuffer( 166 new FileInputStream(new File(reqFileName))); 167 168 HashMap attachMap = attachListToAttachMap(attachList); 169 170 BulkResponse br = sm.sendSoapRequest(sb.toString(), attachMap, false); 171 outResponse(br); 172 } 173 174 public static HashMap attachListToAttachMap(ArrayList attachList) 175 { 176 HashMap attachMap = new HashMap(); 177 for (Iterator it = attachList.iterator(); it.hasNext(); ) { 178 AttachmentInfo ai = (AttachmentInfo)it.next(); 179 DataSource ds = new FileDataSource(ai.fileName); 180 DataHandler dh = new DataHandler(ds); 181 attachMap.put(ai.id, dh); 182 // System.out.println("+put id=" + ai.id + 183 // " ds.mimeType=" + ds.getContentType() + 184 // " dh=" + dh); 185 } 186 return attachMap; 187 } 188 189 public static StringBuffer InputStreamToStringBuffer(InputStream is) 190 throws IOException 191 { 192 int buflen = 1024; 193 char[] chars = new char[buflen+1]; 194 StringBuffer strBuf = new StringBuffer(); 195 196 BufferedReader br = new BufferedReader(new InputStreamReader(is)); 197 198 int charsRead = 0; 199 while ((charsRead = br.read(chars, 0, buflen)) != -1) { 200 strBuf.append(chars, 0, charsRead); 201 } 202 203 return strBuf; 204 } 205 206 private static class AttachmentInfo { 207 public AttachmentInfo(String fileName, String mimeType, String id) { 208 this.id = id; 209 this.fileName = fileName; 210 this.mimeType = mimeType; 211 } 212 213 String id = null; 214 String fileName = null; 215 String mimeType = null; 216 } 217 }

This page was automatically generated by Maven