1 16 17 package org.apache.axis.providers.java; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.MessageContext; 21 import org.apache.axis.handlers.soap.SOAPService; 22 import org.apache.axis.description.OperationDesc; 23 import org.apache.axis.description.ServiceDesc; 24 import org.apache.axis.i18n.Messages; 25 import org.apache.axis.message.SOAPBodyElement; 26 import org.apache.axis.message.SOAPEnvelope; 27 import org.apache.axis.message.MessageElement; 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 import javax.xml.namespace.QName ; 31 import java.lang.reflect.Method ; 32 import java.util.Vector ; 33 34 50 public class MsgProvider extends JavaProvider { 51 64 public void processMessage (MessageContext msgContext, 65 SOAPEnvelope reqEnv, 66 SOAPEnvelope resEnv, 67 Object obj) 68 throws Exception 69 { 70 OperationDesc operation = msgContext.getOperation(); 71 SOAPService service = msgContext.getService(); 72 ServiceDesc serviceDesc = service.getServiceDescription(); 73 QName opQName = null; 74 75 if (operation == null) { 76 Vector bodyElements = reqEnv.getBodyElements(); 77 if(bodyElements.size() > 0) { 78 MessageElement element = (MessageElement) bodyElements.get(0); 79 if (element != null) { 80 opQName = new QName (element.getNamespaceURI(), 81 element.getLocalName()); 82 operation = serviceDesc.getOperationByElementQName(opQName); 83 } 84 } 85 } 86 87 if (operation == null) { 88 throw new AxisFault(Messages.getMessage("noOperationForQName", 89 opQName == null ? "null" : opQName.toString())); 90 } 91 92 Method method = operation.getMethod(); 93 94 int methodType = operation.getMessageOperationStyle(); 95 96 if (methodType != OperationDesc.MSG_METHOD_SOAPENVELOPE) { 97 Vector bodies = reqEnv.getBodyElements(); 99 Object argObjects[] = new Object [1]; 100 101 switch (methodType) { 102 case OperationDesc.MSG_METHOD_BODYARRAY: 104 SOAPBodyElement [] bodyElements = 105 new SOAPBodyElement[bodies.size()]; 106 bodies.toArray(bodyElements); 107 argObjects[0] = bodyElements; 108 SOAPBodyElement [] bodyResult = 109 (SOAPBodyElement [])method.invoke(obj, argObjects); 110 if (bodyResult != null) { 111 for (int i = 0; i < bodyResult.length; i++) { 112 SOAPBodyElement bodyElement = bodyResult[i]; 113 resEnv.addBodyElement(bodyElement); 114 } 115 } 116 return; 117 118 case OperationDesc.MSG_METHOD_ELEMENTARRAY: 120 Element [] elements = new Element [bodies.size()]; 121 for (int i = 0; i < elements.length; i++) { 122 SOAPBodyElement body = (SOAPBodyElement)bodies.get(i); 123 elements[i] = body.getAsDOM(); 124 } 125 argObjects[0] = elements; 126 Element[] elemResult = 127 (Element[]) method.invoke( obj, argObjects ); 128 if (elemResult != null) { 129 for ( int i = 0 ; i < elemResult.length ; i++ ) { 130 if(elemResult[i] != null) 131 resEnv.addBodyElement( 132 new SOAPBodyElement(elemResult[i])); 133 } 134 } 135 return; 136 137 case OperationDesc.MSG_METHOD_DOCUMENT: 139 Document doc = ((SOAPBodyElement)bodies.get(0)).getAsDocument(); 140 argObjects[0] = doc; 141 Document resultDoc = 142 (Document ) method.invoke( obj, argObjects ); 143 if (resultDoc != null) { 144 resEnv.addBodyElement(new SOAPBodyElement( 145 resultDoc.getDocumentElement())); 146 } 147 return; 148 } 149 } else { 150 Object argObjects[] = new Object [2]; 151 152 argObjects[0] = reqEnv; 154 argObjects[1] = resEnv; 155 method.invoke(obj, argObjects); 156 return; 157 } 158 159 throw new AxisFault(Messages.getMessage("badMsgMethodStyle")); 161 } 162 }; 163 | Popular Tags |