1 package org.objectweb.celtix.bus.bindings.soap; 2 3 import java.lang.reflect.Array ; 4 import java.lang.reflect.Method ; 5 6 import javax.xml.namespace.QName ; 7 import javax.xml.ws.Holder; 8 9 public final class SOAPMessageUtil { 10 11 private SOAPMessageUtil() { 12 } 14 15 public static Method getMethod(Class <?> clazz, String methodName) throws Exception { 16 Method [] declMethods = clazz.getDeclaredMethods(); 17 for (Method method : declMethods) { 18 if (method.getName().equals(methodName)) { 19 return method; 20 } 21 } 22 return null; 23 } 24 25 28 public static Object [] getMessageObjects(Method method) throws Exception { 29 int idx = 0; 30 Object [] methodArgs = (Object []) 31 Array.newInstance(Object .class, method.getParameterTypes().length); 32 for (Class <?> cls : method.getParameterTypes()) { 33 if (cls.isAssignableFrom(Holder.class)) { 34 methodArgs[idx] = cls.newInstance(); 35 } 36 idx++; 37 } 38 39 return methodArgs; 40 } 41 42 45 46 public static Object [] getMessageObjects(Method method, Object ... args) throws Exception { 47 assert args.length == method.getParameterTypes().length; 48 int idx = 0; 49 Object [] methodArgs = (Object []) 50 Array.newInstance(Object .class, method.getParameterTypes().length); 51 for (Class <?> cls : method.getParameterTypes()) { 52 if (cls.isAssignableFrom(Holder.class)) { 53 methodArgs[idx] = cls.newInstance(); 54 Holder.class.getField("value").set(methodArgs[idx], args[idx]); 55 } else { 56 methodArgs[idx] = args[idx]; 57 } 58 idx++; 59 } 60 61 return methodArgs; 62 } 63 64 public static String createWrapDocLitSOAPMessage(QName wrapName, QName elName, String data) { 65 StringBuffer str = new StringBuffer (); 66 67 str.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); 68 str.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "); 69 str.append("xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "); 70 str.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); 71 str.append("<SOAP-ENV:Body>"); 72 73 str.append("<ns4:" + wrapName.getLocalPart() + " xmlns:ns4=\"" + wrapName.getNamespaceURI() + "\">"); 74 if (elName != null) { 75 str.append("<ns4:" + elName.getLocalPart() + ">"); 76 str.append(data); 77 str.append("</ns4:" + elName.getLocalPart() + ">"); 78 } 79 str.append("</ns4:" + wrapName.getLocalPart() + ">"); 80 81 str.append("</SOAP-ENV:Body>"); 82 str.append("</SOAP-ENV:Envelope>"); 83 84 return str.toString(); 85 } 86 87 public static String createRPCLitSOAPMessage(QName operation, QName elName, String data) { 88 StringBuffer str = new StringBuffer (); 89 90 str.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); 91 str.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "); 92 str.append("xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "); 93 str.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); 94 str.append("<SOAP-ENV:Body>"); 95 96 str.append("<ns4:" + operation.getLocalPart()); 97 str.append(" xmlns:ns4=\"" + operation.getNamespaceURI() + "\">"); 98 if (elName != null) { 99 str.append("<" + elName.getLocalPart() + ">"); 100 str.append(data); 101 str.append("</" + elName.getLocalPart() + ">"); 102 } 103 str.append("</ns4:" + operation.getLocalPart() + ">"); 104 105 str.append("</SOAP-ENV:Body>"); 106 str.append("</SOAP-ENV:Envelope>"); 107 108 return str.toString(); 109 } 110 111 public static String createBareDocLitSOAPMessage(QName elName, String data) { 112 StringBuffer str = new StringBuffer (); 113 114 str.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); 115 str.append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "); 116 str.append("xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "); 117 str.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); 118 str.append("<SOAP-ENV:Header/>"); 119 str.append("<SOAP-ENV:Body>"); 120 121 str.append("<ns4:" + elName.getLocalPart() + " xmlns:ns4=\"" + elName.getNamespaceURI() + "\">"); 122 str.append(data); 123 str.append("</ns4:" + elName.getLocalPart() + ">"); 124 125 str.append("</SOAP-ENV:Body>"); 126 str.append("</SOAP-ENV:Envelope>"); 127 128 return str.toString(); 129 } 130 } 131 | Popular Tags |