MsgProviderpublic class MsgProvider extends JavaProvider Deal with message-style Java services. For now, these are services
with exactly ONE OperationDesc, pointing to a method which looks like
one of the following:
public Element [] method(Vector v);
(NOTE : This is silly, we should change it to either be Vector/Vector
or Element[]/Element[])
public Document method(Document doc);
public void method(MessageContext mc); |
Methods Summary |
---|
public void | processMessage(org.apache.axis.MessageContext msgContext, org.apache.axis.message.SOAPEnvelope reqEnv, org.apache.axis.message.SOAPEnvelope resEnv, java.lang.Object obj)Process the message. Figure out the method "style" (one of the three
allowed signatures, which has already been determined and cached in
the OperationDesc) and do the actual invocation. Note that we don't
catch exceptions here, preferring to bubble them right up through to
someone who'll catch it above us.
OperationDesc operation = msgContext.getOperation();
SOAPService service = msgContext.getService();
ServiceDesc serviceDesc = service.getServiceDescription();
QName opQName = null;
if (operation == null) {
Vector bodyElements = reqEnv.getBodyElements();
if(bodyElements.size() > 0) {
MessageElement element = (MessageElement) bodyElements.get(0);
if (element != null) {
opQName = new QName(element.getNamespaceURI(),
element.getLocalName());
operation = serviceDesc.getOperationByElementQName(opQName);
}
}
}
if (operation == null) {
throw new AxisFault(Messages.getMessage("noOperationForQName",
opQName == null ? "null" : opQName.toString()));
}
Method method = operation.getMethod();
int methodType = operation.getMessageOperationStyle();
if (methodType != OperationDesc.MSG_METHOD_SOAPENVELOPE) {
// dig out just the body, and pass it on
Vector bodies = reqEnv.getBodyElements();
Object argObjects[] = new Object [1];
switch (methodType) {
// SOAPBodyElement [] / SOAPBodyElement []
case OperationDesc.MSG_METHOD_BODYARRAY:
SOAPBodyElement [] bodyElements =
new SOAPBodyElement[bodies.size()];
bodies.toArray(bodyElements);
argObjects[0] = bodyElements;
SOAPBodyElement [] bodyResult =
(SOAPBodyElement [])method.invoke(obj, argObjects);
if (bodyResult != null) {
for (int i = 0; i < bodyResult.length; i++) {
SOAPBodyElement bodyElement = bodyResult[i];
resEnv.addBodyElement(bodyElement);
}
}
return;
// Element [] / Element []
case OperationDesc.MSG_METHOD_ELEMENTARRAY:
Element [] elements = new Element [bodies.size()];
for (int i = 0; i < elements.length; i++) {
SOAPBodyElement body = (SOAPBodyElement)bodies.get(i);
elements[i] = body.getAsDOM();
}
argObjects[0] = elements;
Element[] elemResult =
(Element[]) method.invoke( obj, argObjects );
if (elemResult != null) {
for ( int i = 0 ; i < elemResult.length ; i++ ) {
if(elemResult[i] != null)
resEnv.addBodyElement(
new SOAPBodyElement(elemResult[i]));
}
}
return;
// Element [] / Element []
case OperationDesc.MSG_METHOD_DOCUMENT:
Document doc = ((SOAPBodyElement)bodies.get(0)).getAsDocument();
argObjects[0] = doc;
Document resultDoc =
(Document) method.invoke( obj, argObjects );
if (resultDoc != null) {
resEnv.addBodyElement(new SOAPBodyElement(
resultDoc.getDocumentElement()));
}
return;
}
} else {
Object argObjects[] = new Object [2];
// SOAPEnvelope / SOAPEnvelope
argObjects[0] = reqEnv;
argObjects[1] = resEnv;
method.invoke(obj, argObjects);
return;
}
// SHOULD NEVER GET HERE...
throw new AxisFault(Messages.getMessage("badMsgMethodStyle"));
|
|