antelder 2002/10/15 01:13:15
Modified: java/src/org/apache/wsif/providers/soap/apacheaxis
WSIFOperation_ApacheAxis.java
Log:
No changes just format the code - so the changes in the next commit are obvious.
Revision Changes Path
1.25 +1054
-1001xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java
Index: WSIFOperation_ApacheAxis.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- WSIFOperation_ApacheAxis.java 26 Sep 2002 09:56:32 -0000 1.24
+++ WSIFOperation_ApacheAxis.java 15 Oct 2002 08:13:15 -0000 1.25
@@ -106,1006 +106,1059 @@
* @author Ant Elder <[EMAIL PROTECTED]>
*/
public class WSIFOperation_ApacheAxis
- extends WSIFDefaultOperation
- implements WSIFOperation, Serializable {
- transient protected WSIFPort_ApacheAxis portInstance;
- transient protected Operation operation;
- transient protected Definition definition;
- transient protected List partNames;
- transient protected String names[];
- transient protected Class types[];
- transient protected String inputEncodingStyle;
- transient protected String inputNamespace;
- transient protected String actionUri;
- transient protected Class returnType = null;
- transient protected HashMap outParams;
-
- // for async operation
- transient protected boolean asyncOperation;
- transient protected WSIFCorrelationId asyncRequestID;
-
- // everything other than what is needed to process async response should be
transient
- protected WSIFResponseHandler responseHandler;
- protected String returnName = null;
- protected String outputEncodingStyle;
- protected WSIFDynamicTypeMap typeMap;
- protected ArrayList wsdlOutParams;
-
- public WSIFOperation_ApacheAxis(
- WSIFPort_ApacheAxis wsifport_apacheaxis,
- Operation operation1,
- WSIFDynamicTypeMap wsifdynamictypemap)
- throws WSIFException {
- Trc.entry(this, wsifport_apacheaxis, operation1, wsifdynamictypemap);
-
- inputEncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/";
- outputEncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/";
- typeMap = wsifdynamictypemap;
- setDynamicWSIFPort(wsifport_apacheaxis);
- setOperation(operation1);
- setDefinition(wsifport_apacheaxis.getDefinition());
- if (Trc.ON)
- Trc.exit(deep());
- }
-
- /**
- * Create a new copy of this object. This is not a clone, since
- * it does not copy the referenced objects as well.
- */
- public WSIFOperation_ApacheAxis copy() throws WSIFException {
- Trc.entry(this);
-
- WSIFOperation_ApacheAxis op =
- new WSIFOperation_ApacheAxis(portInstance, operation, typeMap);
-
- op.setSoapActionURI(getSoapActionURI());
- op.setInputNamespace(getInputNamespace());
- op.setInputEncodingStyle(getInputEncodingStyle());
- op.setOutputEncodingStyle(getOutputEncodingStyle());
- op.setPartNames(getPartNames());
- op.setReturnName(getReturnName());
- op.setAsyncOperation(isAsyncOperation());
- op.setResponseHandler(getResponseHandler());
- op.setInputJmsProperties(getInputJmsProperties());
- op.setOutputJmsProperties(getOutputJmsProperties());
- op.setInputJmsPropertyValues(getInputJmsPropertyValues());
-
- if (Trc.ON)
- Trc.exit(op.deep());
- return op;
- }
-
- public Definition getDefinition() {
- Trc.entry(this);
- Trc.exit(definition);
- return definition;
- }
-
- public WSIFPort_ApacheAxis getDynamicWSIFPort() {
- Trc.entry(this);
- Trc.exit(portInstance);
- return portInstance;
- }
-
- public String getInputEncodingStyle() {
- Trc.entry(this);
- Trc.exit(inputEncodingStyle);
- return inputEncodingStyle;
- }
-
- public String getInputNamespace() {
- Trc.entry(this);
- Trc.exit(inputNamespace);
- return inputNamespace;
- }
-
- public String getName() {
- Trc.entry(this);
- String s = operation.getName();
- Trc.exit(s);
- return s;
- }
-
- public Operation getOperation() {
- Trc.entry(this);
- Trc.exit(operation);
- return operation;
- }
-
- public String getOutputEncodingStyle() {
- Trc.entry(this);
- Trc.exit(outputEncodingStyle);
- return outputEncodingStyle;
- }
-
- public List getPartNames() {
- Trc.entry(this);
- Trc.exit(partNames);
- return partNames;
- }
-
- public String getReturnName() {
- Trc.entry(this);
- Trc.exit(returnName);
- return returnName;
- }
-
- public String getSoapActionURI() {
- Trc.entry(this);
- Trc.exit(actionUri);
- return actionUri;
- }
-
- public Transport getTransport() {
- Trc.entry(this);
- Transport t = portInstance.getAxisTransport();
- Trc.exit(t);
- return t;
- }
-
- public WSIFCorrelationId getAsyncRequestID() {
- Trc.entry(this);
- Trc.exit(asyncRequestID);
- return asyncRequestID;
- }
-
- private HashMap getResponseMsgParams() {
- return outParams;
- }
-
- /**
- * Tests if the currently executing request is an asynchronous request.
- *
- * @return true if the current request is a asynchronous request,
- * otherwise false
- */
- public boolean isAsyncOperation() {
- Trc.entry(this);
- Trc.exit(asyncOperation);
- return asyncOperation;
- }
-
- // package visable as it's used by WSIFJmsTransport
- void setAsyncRequestID(WSIFCorrelationId asyncRequestID) {
- Trc.entry(this, asyncRequestID);
- this.asyncRequestID = asyncRequestID;
- Trc.exit();
- }
-
- public void executeInputOnlyOperation(WSIFMessage wsifmessage)
- throws WSIFException {
- Trc.entry(this, wsifmessage);
- setAsyncOperation(false);
- invokeRequestResponseOperation(wsifmessage, null, null);
- Trc.exit();
- return;
- }
-
- /**
- * Performs a request response operation asynchronously.
- *
- * @param input input message to send to the operation
- * @return the correlation ID or the request. The correlation ID
- * is used to associate the request with the WSIFOperation.
- * @exception WSIFException if something goes wrong.
- * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage)
- */
- public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage input)
- throws WSIFException {
- Trc.entry(this, input);
- WSIFCorrelationId id = executeRequestResponseAsync(input, null);
- Trc.exit(id);
- return id;
-
- }
-
- /**
- * Performs a request response operation asynchronously.
- *
- * @param input input message to send to the operation
- * @param handler the response handler that will be notified
- * when the asynchronous response becomes available.
- * @return the correlation ID or the request. The correlation ID
- * is used to associate the request with the WSIFOperation.
- * @exception WSIFException if something goes wrong.
- * @see
WSIFOperation#executeRequestResponseAsync(WSIFMessage,WSIFResponseHandler)
- */
- public WSIFCorrelationId executeRequestResponseAsync(
- WSIFMessage input,
- WSIFResponseHandler handler)
- throws WSIFException {
-
- Trc.entry(this, input, handler);
- close();
-
- if (!portInstance.supportsAsync()) {
- throw new WSIFException("asynchronous operations not available");
- }
-
- setAsyncOperation(true);
- setResponseHandler(handler);
- WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
- transport.setWsifOperation(this);
- transport.setAsyncOperation("true");
-
- invokeRequestResponseOperation(input, null, null);
-
- transport.setAsyncOperation("false");
- WSIFCorrelationId id = getAsyncRequestID();
- Trc.exit(id);
- return id;
-
- }
-
- /**
- * fireAsyncResponse is called by an AsyncListener when a response
- * has been received for a previous executeRequestResponseAsync call.
- * It passes the response to the executeAsyncResponse method of the
- * associated WSIFResponseHandler.
- * @see WSIFOperation#fireAsyncResponse(Object)
- * @param response an Object representing the response. The response
- * should be a JMS TextMessage containging the XML response.
- */
- public void fireAsyncResponse(Object response) throws WSIFException {
- Trc.entry(this, response);
-
- Object result = deserialiseResponseObject(response);
-
- WSIFMessage outMsg = createOutputMessage();
- WSIFMessage faultMsg = createFaultMessage();
- buildResponseMessages(result, outMsg, faultMsg);
-
- getResponseHandler().executeAsyncResponse(outMsg, faultMsg);
-
- Trc.exit(outMsg);
- }
-
- /**
- * Processes the response to an asynchronous request.
- * This is called for when the asynchronous operation was
- * initiated without a WSIFResponseHandler, that is, by calling
- * the executeRequestResponseAsync(WSIFMessage input) method.
- *
- * @param response an Object representing the response.
- * @param output an empty message which will be filled in if
- * the operation invocation succeeds. If it does not
- * succeed, the contents of this message are undefined.
- * (This is a return value of this method.)
- * @param fault an empty message which will be filled in if
- * the operation invocation fails. If it succeeds, the
- * contents of this message are undefined. (This is a
- * return value of this method.)
- *
- * @return true or false indicating whether a fault message was
- * generated or not. The truth value indicates whether
- * the output or fault message has useful information.
- *
- */
- public boolean processAsyncResponse(
- Object response,
- WSIFMessage output,
- WSIFMessage fault)
- throws WSIFException {
- Trc.entry(this, response, output, fault);
-
- Object result = deserialiseResponseObject(response);
- boolean ok = buildResponseMessages(result, output, fault);
-
- Trc.exit( ok );
- return ok;
- }
-
- /**
- * This deserialises and unmarshalls the response message.
- * This is copied, with minor changes, from the 2nd half
- * of the Apache Axis Call class invoke method.
- */
- private Object deserialiseResponseObject(Object msg) throws WSIFException {
- if (msg == null) {
- throw new WSIFException("null response to async send");
- }
- if (!(msg instanceof TextMessage)) {
- throw new WSIFException("response not a javax.jms.TextMessage");
- }
-
- try {
- TextMessage m = (TextMessage) msg;
- Message responseMessage = new Message(m.getText());
- responseMessage.setMessageType(Message.RESPONSE);
-
- Service service = new Service();
- MessageContext msgContext = new MessageContext(service.getEngine());
- msgContext.setResponseMessage(responseMessage);
-
- // This registerTypeMapping code is duplicated in prepare
- TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry();
- org.apache.axis.encoding.TypeMapping tm =
- (org.apache.axis.encoding.TypeMapping)
tmr.getTypeMapping(outputEncodingStyle);
- Class objClass;
- String namespaceURI, localPart;
- WSIFDynamicTypeMapping wsifdynamictypemapping;
- for (Iterator iterator = typeMap.iterator(); iterator.hasNext();) {
- wsifdynamictypemapping = (WSIFDynamicTypeMapping) iterator.next();
- objClass = wsifdynamictypemapping.getJavaType();
- namespaceURI =
wsifdynamictypemapping.getXmlType().getNamespaceURI();
-
- // Filter out XSD and SOAP-ENC types from those we explicitly map.
- // Axis already knows how to deal with these; using the
BeanSerializer
- // would be wrong anyway as they represent simple types and not
beans.
- if( namespaceURI != null
- && !namespaceURI.equals(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
- && !namespaceURI.equals(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
- && !namespaceURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)
- && !namespaceURI.equals(WSIFConstants.NS_URI_SOAP_ENC)) {
- localPart = wsifdynamictypemapping.getXmlType().getLocalPart();
- QName qn = new QName(namespaceURI, localPart);
- BeanSerializerFactory bsf = new BeanSerializerFactory(objClass,
qn);
- BeanDeserializerFactory bdf = new
BeanDeserializerFactory(objClass, qn);
- tm.register(objClass, qn, bsf, bdf);
- }
- }
-
- Message resMsg = msgContext.getResponseMessage();
- SOAPEnvelope resEnv = resMsg.getSOAPEnvelope();
-
- Object b = resEnv.getFirstBody();
- if (b instanceof SOAPFaultElement) {
- return new AxisFault(b.toString());
- }
-
- // RPCElement body = (RPCElement)resEnv.getFirstBody();
- RPCElement body = (RPCElement) b;
-
- Object result = null;
- HashMap outParams;
- Vector resArgs = body.getParams();
-
- if (resArgs != null && resArgs.size() > 0) {
- RPCParam param = (RPCParam) resArgs.get(0);
- result = param.getValue();
-
- if (resArgs.size() > 1) {
- outParams = new HashMap();
- for (int i = 1; i < resArgs.size(); i++) {
- RPCParam p = (RPCParam)resArgs.get( i );
- outParams.put( p.getName(), p.getValue() );
- }
- setResponseMsgParams( outParams );
- }
- }
- return result;
- } catch (Exception ex) {
- Trc.exception(ex);
- throw new WSIFException(ex.getMessage());
- }
-
- }
-
- /**
- * Extracts the output or fault message parts from the axis response.
- */
- private boolean buildResponseMessages(
- Object resp,
- WSIFMessage outMsg,
- WSIFMessage faultMsg)
- throws WSIFException {
-
- boolean respOK;
-
- if (resp instanceof AxisFault) {
- respOK = false;
- if (faultMsg != null) {
- AxisFault f = (AxisFault) resp;
- faultMsg.setName(WSIFConstants.SOAP_FAULT_MSG_NAME);
- faultMsg.setObjectPart(WSIFConstants.SOAP_FAULT_OBJECT, f);
- }
- } else {
- respOK = true;
- populateOutMsgReturnPart( resp, outMsg );
- populateOutMsgParts( outMsg );
- }
-
- return respOK;
- }
-
- /**
- * Populate the outMessage with the response return value.
- */
- private void populateOutMsgReturnPart(Object resp, WSIFMessage outMsg)
- throws WSIFException{
- if (outMsg != null ) {
- if ( returnName != null ) {
- if ( resp == null ) {
- throw new WSIFException(
- "return value not found in response message" );
- } else if ( returnType != null // will be null for async responses
- && !returnType.isPrimitive()
- && !(returnType.isAssignableFrom( resp.getClass() )) ) {
- throw new WSIFException(
- "return value "
- + resp
- + " has unexpected type "
- + resp.getClass()
- + " instead of "
- + returnType);
- }
- outMsg.setObjectPart( returnName, resp );
- }
- }
- }
-
- /**
- * Populate the outMessage with the expected parts.
- * (this only does the out parameters not the return part)
- */
- private void populateOutMsgParts(WSIFMessage outMsg)
- throws WSIFException{
- if ( outMsg != null ) {
- HashMap respParms = getResponseMsgParams();
- ArrayList wsdlOutParams = getWSDLOutParams();
- if ( respParms != null ) {
- String name;
- Object value;
- for (Iterator i = respParms.keySet().iterator(); i.hasNext(); ) {
- name = (String) i.next();
- value = respParms.get( name );
- outMsg.setObjectPart( name, value );
- wsdlOutParams.remove( name );
- }
- }
- // init any other parts to null
- for (Iterator i=wsdlOutParams.iterator(); i.hasNext(); ) {
- outMsg.setObjectPart( (String) i.next(), null );
- }
- }
- }
-
- public boolean executeRequestResponseOperation(
- WSIFMessage wsifmessage,
- WSIFMessage wsifmessage1,
- WSIFMessage wsifmessage2)
- throws WSIFException {
-
- Trc.entry(this, wsifmessage, wsifmessage1, wsifmessage2);
- close();
- setAsyncOperation(false);
-
- boolean succ =
- invokeRequestResponseOperation(wsifmessage, wsifmessage1, wsifmessage2);
- Trc.exit(succ);
- return succ;
- }
-
- public boolean invokeRequestResponseOperation(
- WSIFMessage wsifmessage,
- WSIFMessage wsifmessage1,
- WSIFMessage wsifmessage2)
- throws WSIFException {
- Trc.entry(this, wsifmessage, wsifmessage1, wsifmessage2);
-
- Call call = portInstance.getCall();
- Transport axistransport = getTransport();
-
- WSIFJMSDestination dest = null;
- if (axistransport != null) {
- call.setTransport(axistransport);
- if (axistransport instanceof WSIFJmsTransport) {
- dest = ((WSIFJmsTransport) axistransport).getDestination();
- dest.setAsyncMode(isAsyncOperation());
- }
- }
-
- if (names == null)
- prepare(call);
-
- if (inJmsPropVals!=null && !inJmsPropVals.isEmpty())
- dest.setProperties(inJmsPropVals);
-
- setDestinationContext( dest ); // TODO WSDL props override context???
-
- ArrayList objects = new ArrayList();
- for (int i = 0; i < names.length; i++) {
- Object obj;
- try {
- obj = wsifmessage.getObjectPart(names[i]);
- } catch (WSIFException ex) {
- Trc.exception(ex);
- obj = null;
- }
- if (obj != null) {
- if (types[i] == null)
- throw new WSIFException("Cannot map type " + names[i]);
-
- if (!isPrimitiveOf(obj.getClass(), types[i])
- && !types[i].isAssignableFrom(obj.getClass())) {
- throw new WSIFException(
- "value "
- + obj
- + " has unexpected type "
- + obj.getClass()
- + " instead of "
- + types[i]);
- }
- }
-
- if (inJmsProps.containsKey(names[i]) && dest != null)
- dest.setProperty((String) (inJmsProps.get(names[i])), obj);
- else
- objects.add(obj);
- }
-
- setCallContext(call);
- call.setSOAPActionURI( getSoapActionURI() );
-
- Object response;
- boolean respOK = true;
- try {
- String name = operation.getName();
- Object[] objs = objects.toArray();
- Trc.event(
- this,
- "Invoking operation ",
- name,
- " input namespace ",
- getInputNamespace(),
- " parameters ",
- objs,
- " call object ",
- call);
-
- response = call.invoke(getInputNamespace(), name, objs);
- } catch (AxisFault e) {
- Trc.exception(e);
- response = e;
- respOK = false;
- }
-
- Trc.event(this,"Returned from operation, response ",response);
- // setJMSOutPropsInContext( dest ); TODO doesn't work yet
-
- if ( !isAsyncOperation() && returnType != null) {
- Map callParams = call.getOutputParams();
- if ( callParams != null ) {
- HashMap outParams = new HashMap();
- QName qn;
- for (Iterator i= callParams.keySet().iterator(); i.hasNext(); ) {
- qn = (QName) i.next();
- outParams.put( qn.getLocalPart(), callParams.get( qn ) );
- }
- setResponseMsgParams( outParams );
- }
- respOK = buildResponseMessages(response, wsifmessage1, wsifmessage2);
- }
-
- Trc.exit(respOK);
- return respOK;
- }
-
- private void prepare(Call call) throws WSIFException {
-
- // This registerTypeMapping code is duplicated in deserialiseResponseObject
- TypeMappingRegistry registry =
- call.getMessageContext().getTypeMappingRegistry();
- Class objClass;
- String namespaceURI, localPart;
- WSIFDynamicTypeMapping wsifdynamictypemapping;
- for (Iterator iterator = typeMap.iterator(); iterator.hasNext();) {
- wsifdynamictypemapping = (WSIFDynamicTypeMapping) iterator.next();
- objClass = wsifdynamictypemapping.getJavaType();
- namespaceURI = wsifdynamictypemapping.getXmlType().getNamespaceURI();
-
- // Filter out XSD and SOAP-ENC types from those we explicitly map.
- // Axis already knows how to deal with these; using the BeanSerializer
- // would be wrong anyway as they represent simple types and not beans.
- if( namespaceURI != null
- && !namespaceURI.equals(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
- && !namespaceURI.equals(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
- && !namespaceURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)
- && !namespaceURI.equals(WSIFConstants.NS_URI_SOAP_ENC)) {
- localPart = wsifdynamictypemapping.getXmlType().getLocalPart();
- QName qn = new QName(namespaceURI, localPart);
- BeanSerializerFactory bsf = new BeanSerializerFactory(objClass, qn);
- BeanDeserializerFactory bdf = new BeanDeserializerFactory(objClass,
qn);
- call.registerTypeMapping(objClass, qn, bsf, bdf);
- }
- }
-
- Input input = operation.getInput();
- if (input != null) {
- Object obj;
- if (partNames != null) {
- obj = new Vector();
- Part part1;
- for (Iterator iterator1 = partNames.iterator();
- iterator1.hasNext();
- ((List) (obj)).add(part1)) {
- String s = (String) iterator1.next();
- part1 = input.getMessage().getPart(s);
- if (part1 == null)
- throw new WSIFException(
- "no input part named " + s + " for binding operation "
+ getName());
- }
-
- } else {
- obj = input.getMessage().getOrderedParts(null);
- }
- int i = ((List) (obj)).size();
- names = new String[i];
- types = new Class[i];
- for (int j = 0; j < i; j++) {
- Part part2 = (Part) ((List) (obj)).get(j);
- names[j] = part2.getName();
- QName qname1 = part2.getTypeName();
- if (qname1 == null)
- throw new WSIFException("part " + names[j] + " must have type
name declared");
-
- javax.xml.rpc.encoding.TypeMapping tm =
-
registry.getTypeMapping("http://schemas.xmlsoap.org/soap/encoding/");
- if (tm instanceof org.apache.axis.encoding.TypeMapping) {
- types[j] = ((org.apache.axis.encoding.TypeMapping) tm)
- .getClassForQName(
- new
QName(qname1.getNamespaceURI(),qname1.getLocalPart()));
- }
- }
-
- } else {
- names = new String[0];
- types = new Class[0];
- }
- Output output = operation.getOutput();
- if (output != null) {
- Part part = null;
- if (returnName != null) {
- part = output.getMessage().getPart(returnName);
- if (part == null)
- throw new WSIFException(
- "no output part named " + returnName + " for bining
operation " + getName());
- } else {
- List list = output.getMessage().getOrderedParts(null);
- if (list.size() > 0) {
- part = (Part) list.get(0);
- returnName = part.getName();
- }
- }
- if (part != null) {
- QName qname = part.getTypeName();
- javax.xml.rpc.encoding.TypeMapping tm =
-
registry.getTypeMapping("http://schemas.xmlsoap.org/soap/encoding/");
- if (tm instanceof org.apache.axis.encoding.TypeMapping) {
- returnType =
- ((org.apache.axis.encoding.TypeMapping)
tm).getClassForQName(
- new
QName(qname.getNamespaceURI(),qname.getLocalPart()));
- }
- }
- // setup any output paramter part names defined in the WSDL
- List list = output.getMessage().getOrderedParts(null);
- if ( list.size() > 1 ) {
- wsdlOutParams = new ArrayList();
- for (int i=1; i<list.size(); i++) {
- part = (Part) list.get( i );
- wsdlOutParams.add( part.getName() );
- }
- setWSDLOutParams( wsdlOutParams );
- }
- }
- }
-
- /**
- * Sets the response handler that will be used to
- * process the response to an asynchronous request.
- * @param responseHandler the responseHandler to use
- */
- private void setResponseHandler(WSIFResponseHandler responseHandler) {
- this.responseHandler = responseHandler;
- }
-
- /**
- * Gets the response handler that will be used to
- * process the response to a asynchronous request.
- * @return the current response handler.
- * package visable as its used by the transport
- */
- WSIFResponseHandler getResponseHandler() {
- return responseHandler;
- }
-
- private ArrayList getWSDLOutParams() {
- if ( wsdlOutParams == null ) {
- wsdlOutParams = new ArrayList();
- }
- return wsdlOutParams;
- }
-
- private void setWSDLOutParams(ArrayList al) {
- wsdlOutParams = al;
- }
-
- public void setDefinition(Definition definition1) {
- Trc.entry(this, definition1);
- definition = definition1;
- Trc.exit();
- }
-
- public void setDynamicWSIFPort(WSIFPort_ApacheAxis wsifport_apacheaxis) {
- Trc.entry(this, wsifport_apacheaxis);
- portInstance = wsifport_apacheaxis;
- Trc.exit();
- }
-
- public void setInputEncodingStyle(String s) {
- Trc.entry(this, s);
- inputEncodingStyle = s;
- Trc.exit();
- }
-
- public void setInputNamespace(String s) {
- Trc.entry(this, s);
- inputNamespace = s;
- Trc.exit();
- }
-
- public void setOperation(Operation operation1) {
- Trc.entry(this, operation1);
- operation = operation1;
- Trc.exit();
- }
-
- public void setOutputEncodingStyle(String s) {
- Trc.entry(this, s);
- outputEncodingStyle = s;
- Trc.exit();
- }
-
- public void setPartNames(List list) {
- Trc.entry(this, list);
- partNames = list;
- Trc.exit();
- }
-
- public void setReturnName(String s) {
- Trc.entry(this, s);
- returnName = s;
- Trc.exit();
- }
-
- public void setSoapActionURI(String s) {
- Trc.entry(this, s);
- actionUri = s;
- Trc.exit();
- }
-
- private void setResponseMsgParams(HashMap hm) {
- outParams = hm;
- }
-
- /**
- * Sets if the currently executing request is an asynchronous request.
- *
- * @param b true if the current request is a asynchronous request,
- * otherwise false
- */
- private void setAsyncOperation(boolean b) {
- asyncOperation = b;
- }
-
- /**
- * Gets the target namespace URI of this WSIFOperation
- *
- * @return the target namespace URI
- */
- public String getTargetNamespaceURI() {
- Trc.entry(this);
- Definition d = getDefinition();
- String s = (d == null) ? "" : d.getTargetNamespace();
- Trc.exit(s);
- return s;
- }
-
- /**
- * Creates a new input WSIFMessage. This overrides the
- * WSIFDefaultOperation method to enable the use of
- * compiled WSIFMessages by using a WSIFMessageFactory
- * to create the message.
- *
- * @param name the name of the message
- * @return a WSIFMessage instance
- * @see WSIFOperation#createInputMessage(String)
- */
-// defect 131672 and disable compiled msg support for now
-// public WSIFMessage createInputMessage(String name) {
-// Tr.entry(this, name);
-// Definition d = getDefinition();
-// String ns = (d == null) ? "" : d.getTargetNamespace();
-// WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
-// WSIFMessage msg = mf.createMessage(ns, name + "Message");
-// if (msg != null)
-// msg.setName(name);
-// Tr.exit(msg);
-// return msg;
-// }
-
- /**
- * Creates a new output WSIFMessage. This overrides the
- * WSIFDefaultOperation method to enable the use of
- * compiled WSIFMessages by using a WSIFMessageFactory
- * to create the message.
- *
- * @param name the name of the message
- * @return a WSIFMessage instance
- * @see WSIFOperation#createInputMessage(String)
- */
-// defect 131672 and disable compiled msg support for now
-// public WSIFMessage createOutputMessage(String name) {
-// Tr.entry(this, name);
-// Definition d = getDefinition();
-// String ns = (d == null) ? "" : d.getTargetNamespace();
-// WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
-// WSIFMessage msg = mf.createMessage(ns, name + "Message");
-// if (msg != null)
-// msg.setName(name);
-// Tr.exit(msg);
-// return msg;
-// }
-
- /**
- * This sets up the output JMS property values in the context
- */
- private void setJMSOutPropsInContext(WSIFJMSDestination dest) throws
WSIFException {
- if ( dest == null ) {
- return;
- }
- HashMap props = dest.getProperties();
- if ( props != null ) {
- if ( context == null ) {
- context = new WSIFDefaultMessage();
- }
- context.setParts( props );
- }
- }
-
- /**
- * This sets up any context JMS property values in the Destination
- */
- private void setDestinationContext(WSIFJMSDestination dest) {
- if ( context == null
- || dest == null ) {
- return;
- }
- String partName;
- HashMap jmsProps = new HashMap();
- for (Iterator i = context.getPartNames(); i.hasNext(); ) {
- partName = (String)i.next();
- if ( partName.startsWith( WSIFConstants.CONTEXT_JMS_PREFIX ) ) {
- try {
- jmsProps.put( partName.substring(
WSIFConstants.CONTEXT_JMS_PREFIX.length() ),
- context.getObjectPart( partName ) );
- } catch (WSIFException ex) {
- Trc.ignoredException(ex);
- }
- }
- }
- if ( jmsProps.size() > 0 ) {
- dest.setProperties( jmsProps );
- }
- }
-
- /**
- * This sets up the context headers in the axis
- * Call object prior to invoke method being issued.
- */
- private void setCallContext(Call call) {
- Object o;
- String name;
- if (context == null) {
- return;
- }
- name = WSIFConstants.CONTEXT_HTTP_USER;
- try {
- o = context.getObjectPart( name );
- if ( o instanceof String ) {
- addHTTPHeader( call, name, (String)o );
- }
- } catch (WSIFException ex) {
- Trc.ignoredException(ex);
- }
-
- name = WSIFConstants.CONTEXT_HTTP_PSWD;
- try {
- o = context.getObjectPart( name );
- if ( o instanceof String ) {
- addHTTPHeader( call, name, (String)o );
- }
- } catch (WSIFException ex) {
- Trc.ignoredException(ex);
- }
-
- try {
- name = WSIFConstants.CONTEXT_SOAP_HEADERS;
- o = context.getObjectPart( name );
- if ( o instanceof List ) {
- addSOAPHeader( call, name, (List)o );
- }
- } catch (WSIFException ex) {
- Trc.ignoredException(ex);
- }
- }
-
- /**
- * Sets the SOAP headers in the message context.
- */
- private void addSOAPHeader(Call call, String name, List soapHeaders) {
- for (Iterator i = soapHeaders.iterator(); i.hasNext();) {
- Object o = i.next();
- if (o instanceof Element) {
- call.addHeader(new SOAPHeaderElement((Element) o));
- }
- }
- }
-
- /**
- * Sets the HTTP header value in the message context.
- * How these are used depends on the underlying transport,
- * eg. org.apache.axis.transport.http.HTTPSender
- * will use the 'user.id' and 'user.password' headers
- * for HTTP basic authentication..
- */
- private void addHTTPHeader(Call call, String name, String value) {
- if (name.equals(WSIFConstants.CONTEXT_HTTP_USER)) {
- call.setProperty(Call.USERNAME_PROPERTY, value);
- } else if (name.equals(WSIFConstants.CONTEXT_HTTP_PSWD)) {
- call.setProperty(Call.PASSWORD_PROPERTY, value);
- }
- }
-
- /**
- * Returns true if primitive is the equivalent primitive class of clazz.
- * Why doesn't java provide this function?
- */
- private static boolean isPrimitiveOf(Class clazz, Class primitive) {
- if ((primitive.equals(boolean.class) &&
Boolean.class.isAssignableFrom(clazz))
- || (primitive.equals(char.class) &&
Character.class.isAssignableFrom(clazz))
- || (primitive.equals(byte.class) && Byte.class.isAssignableFrom(clazz))
- || (primitive.equals(short.class) &&
Short.class.isAssignableFrom(clazz))
- || (primitive.equals(int.class) &&
Integer.class.isAssignableFrom(clazz))
- || (primitive.equals(long.class) && Long.class.isAssignableFrom(clazz))
- || (primitive.equals(float.class) &&
Float.class.isAssignableFrom(clazz))
- || (primitive.equals(double.class) &&
Double.class.isAssignableFrom(clazz)))
- return true;
- else
- return false;
- }
-
- public String deep() {
- String buff = "";
- try {
- buff = new String(super.toString() + ":\n");
-
- buff += "portInstance:" + portInstance;
- buff += " operation:" + Trc.brief(operation);
- buff += " definition:" + Trc.brief(definition);
- buff += " partNames:" + partNames;
- buff += " names:" + names;
- buff += " types:" + types;
- buff += " inputEncodingStyle:" + inputEncodingStyle;
- buff += " inputNamespace:" + inputNamespace;
- buff += " actionUri:" + actionUri;
- buff += " inJmsProps:" + inJmsProps;
- buff += " outJmsProps:" + outJmsProps;
- buff += " inJmsPropVals:" + inJmsPropVals;
- buff += " context:" + context;
- buff += " returnType:" + returnType;
- buff += " asyncOperation:" + asyncOperation;
- buff += " asyncRequestID:" + asyncRequestID;
- buff += " responseHandler:" + responseHandler;
- buff += " returnName:" + returnName;
- buff += " wsdlOutParams:" + wsdlOutParams;
- buff += " outParams:" + outParams;
- buff += " outputEncodingStyle:" + outputEncodingStyle;
- buff += " typeMap:" + typeMap;
- } catch (Exception e) {
- Trc.exceptionInTrace(e);
- }
+ extends WSIFDefaultOperation
+ implements WSIFOperation, Serializable {
+ transient protected WSIFPort_ApacheAxis portInstance;
+ transient protected Operation operation;
+ transient protected Definition definition;
+ transient protected List partNames;
+ transient protected String names[];
+ transient protected Class types[];
+ transient protected String inputEncodingStyle;
+ transient protected String inputNamespace;
+ transient protected String actionUri;
+ transient protected Class returnType = null;
+ transient protected HashMap outParams;
+
+ // for async operation
+ transient protected boolean asyncOperation;
+ transient protected WSIFCorrelationId asyncRequestID;
+
+ // everything other than what is needed to process async response should be
transient
+ protected WSIFResponseHandler responseHandler;
+ protected String returnName = null;
+ protected String outputEncodingStyle;
+ protected WSIFDynamicTypeMap typeMap;
+ protected ArrayList wsdlOutParams;
+
+ public WSIFOperation_ApacheAxis(
+ WSIFPort_ApacheAxis wsifport_apacheaxis,
+ Operation operation1,
+ WSIFDynamicTypeMap wsifdynamictypemap)
+ throws WSIFException {
+ Trc.entry(this, wsifport_apacheaxis, operation1, wsifdynamictypemap);
+
+ inputEncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/";
+ outputEncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/";
+ typeMap = wsifdynamictypemap;
+ setDynamicWSIFPort(wsifport_apacheaxis);
+ setOperation(operation1);
+ setDefinition(wsifport_apacheaxis.getDefinition());
+ if (Trc.ON)
+ Trc.exit(deep());
+ }
+
+ /**
+ * Create a new copy of this object. This is not a clone, since
+ * it does not copy the referenced objects as well.
+ */
+ public WSIFOperation_ApacheAxis copy() throws WSIFException {
+ Trc.entry(this);
+
+ WSIFOperation_ApacheAxis op =
+ new WSIFOperation_ApacheAxis(portInstance, operation, typeMap);
+
+ op.setSoapActionURI(getSoapActionURI());
+ op.setInputNamespace(getInputNamespace());
+ op.setInputEncodingStyle(getInputEncodingStyle());
+ op.setOutputEncodingStyle(getOutputEncodingStyle());
+ op.setPartNames(getPartNames());
+ op.setReturnName(getReturnName());
+ op.setAsyncOperation(isAsyncOperation());
+ op.setResponseHandler(getResponseHandler());
+ op.setInputJmsProperties(getInputJmsProperties());
+ op.setOutputJmsProperties(getOutputJmsProperties());
+ op.setInputJmsPropertyValues(getInputJmsPropertyValues());
+
+ if (Trc.ON)
+ Trc.exit(op.deep());
+ return op;
+ }
+
+ public Definition getDefinition() {
+ Trc.entry(this);
+ Trc.exit(definition);
+ return definition;
+ }
+
+ public WSIFPort_ApacheAxis getDynamicWSIFPort() {
+ Trc.entry(this);
+ Trc.exit(portInstance);
+ return portInstance;
+ }
+
+ public String getInputEncodingStyle() {
+ Trc.entry(this);
+ Trc.exit(inputEncodingStyle);
+ return inputEncodingStyle;
+ }
+
+ public String getInputNamespace() {
+ Trc.entry(this);
+ Trc.exit(inputNamespace);
+ return inputNamespace;
+ }
+
+ public String getName() {
+ Trc.entry(this);
+ String s = operation.getName();
+ Trc.exit(s);
+ return s;
+ }
+
+ public Operation getOperation() {
+ Trc.entry(this);
+ Trc.exit(operation);
+ return operation;
+ }
+
+ public String getOutputEncodingStyle() {
+ Trc.entry(this);
+ Trc.exit(outputEncodingStyle);
+ return outputEncodingStyle;
+ }
+
+ public List getPartNames() {
+ Trc.entry(this);
+ Trc.exit(partNames);
+ return partNames;
+ }
+
+ public String getReturnName() {
+ Trc.entry(this);
+ Trc.exit(returnName);
+ return returnName;
+ }
+
+ public String getSoapActionURI() {
+ Trc.entry(this);
+ Trc.exit(actionUri);
+ return actionUri;
+ }
+
+ public Transport getTransport() {
+ Trc.entry(this);
+ Transport t = portInstance.getAxisTransport();
+ Trc.exit(t);
+ return t;
+ }
+
+ public WSIFCorrelationId getAsyncRequestID() {
+ Trc.entry(this);
+ Trc.exit(asyncRequestID);
+ return asyncRequestID;
+ }
+
+ private HashMap getResponseMsgParams() {
+ return outParams;
+ }
+
+ /**
+ * Tests if the currently executing request is an asynchronous request.
+ *
+ * @return true if the current request is a asynchronous request,
+ * otherwise false
+ */
+ public boolean isAsyncOperation() {
+ Trc.entry(this);
+ Trc.exit(asyncOperation);
+ return asyncOperation;
+ }
+
+ // package visable as it's used by WSIFJmsTransport
+ void setAsyncRequestID(WSIFCorrelationId asyncRequestID) {
+ Trc.entry(this, asyncRequestID);
+ this.asyncRequestID = asyncRequestID;
+ Trc.exit();
+ }
+
+ public void executeInputOnlyOperation(WSIFMessage wsifmessage)
+ throws WSIFException {
+ Trc.entry(this, wsifmessage);
+ setAsyncOperation(false);
+ invokeRequestResponseOperation(wsifmessage, null, null);
+ Trc.exit();
+ return;
+ }
+
+ /**
+ * Performs a request response operation asynchronously.
+ *
+ * @param input input message to send to the operation
+ * @return the correlation ID or the request. The correlation ID
+ * is used to associate the request with the WSIFOperation.
+ * @exception WSIFException if something goes wrong.
+ * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage)
+ */
+ public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage input)
+ throws WSIFException {
+ Trc.entry(this, input);
+ WSIFCorrelationId id = executeRequestResponseAsync(input, null);
+ Trc.exit(id);
+ return id;
+
+ }
+
+ /**
+ * Performs a request response operation asynchronously.
+ *
+ * @param input input message to send to the operation
+ * @param handler the response handler that will be notified
+ * when the asynchronous response becomes available.
+ * @return the correlation ID or the request. The correlation ID
+ * is used to associate the request with the WSIFOperation.
+ * @exception WSIFException if something goes wrong.
+ * @see
WSIFOperation#executeRequestResponseAsync(WSIFMessage,WSIFResponseHandler)
+ */
+ public WSIFCorrelationId executeRequestResponseAsync(
+ WSIFMessage input,
+ WSIFResponseHandler handler)
+ throws WSIFException {
+
+ Trc.entry(this, input, handler);
+ close();
+
+ if (!portInstance.supportsAsync()) {
+ throw new WSIFException("asynchronous operations not
available");
+ }
+
+ setAsyncOperation(true);
+ setResponseHandler(handler);
+ WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
+ transport.setWsifOperation(this);
+ transport.setAsyncOperation("true");
+
+ invokeRequestResponseOperation(input, null, null);
+
+ transport.setAsyncOperation("false");
+ WSIFCorrelationId id = getAsyncRequestID();
+ Trc.exit(id);
+ return id;
+
+ }
+
+ /**
+ * fireAsyncResponse is called by an AsyncListener when a response
+ * has been received for a previous executeRequestResponseAsync call.
+ * It passes the response to the executeAsyncResponse method of the
+ * associated WSIFResponseHandler.
+ * @see WSIFOperation#fireAsyncResponse(Object)
+ * @param response an Object representing the response. The response
+ * should be a JMS TextMessage containging the XML response.
+ */
+ public void fireAsyncResponse(Object response) throws WSIFException {
+ Trc.entry(this, response);
+
+ Object result = deserialiseResponseObject(response);
+
+ WSIFMessage outMsg = createOutputMessage();
+ WSIFMessage faultMsg = createFaultMessage();
+ buildResponseMessages(result, outMsg, faultMsg);
+
+ getResponseHandler().executeAsyncResponse(outMsg, faultMsg);
+
+ Trc.exit(outMsg);
+ }
+
+ /**
+ * Processes the response to an asynchronous request.
+ * This is called for when the asynchronous operation was
+ * initiated without a WSIFResponseHandler, that is, by calling
+ * the executeRequestResponseAsync(WSIFMessage input) method.
+ *
+ * @param response an Object representing the response.
+ * @param output an empty message which will be filled in if
+ * the operation invocation succeeds. If it does not
+ * succeed, the contents of this message are undefined.
+ * (This is a return value of this method.)
+ * @param fault an empty message which will be filled in if
+ * the operation invocation fails. If it succeeds, the
+ * contents of this message are undefined. (This is a
+ * return value of this method.)
+ *
+ * @return true or false indicating whether a fault message was
+ * generated or not. The truth value indicates whether
+ * the output or fault message has useful information.
+ *
+ */
+ public boolean processAsyncResponse(
+ Object response,
+ WSIFMessage output,
+ WSIFMessage fault)
+ throws WSIFException {
+ Trc.entry(this, response, output, fault);
+
+ Object result = deserialiseResponseObject(response);
+ boolean ok = buildResponseMessages(result, output, fault);
+
+ Trc.exit(ok);
+ return ok;
+ }
+
+ /**
+ * This deserialises and unmarshalls the response message.
+ * This is copied, with minor changes, from the 2nd half
+ * of the Apache Axis Call class invoke method.
+ */
+ private Object deserialiseResponseObject(Object msg) throws WSIFException {
+ if (msg == null) {
+ throw new WSIFException("null response to async send");
+ }
+ if (!(msg instanceof TextMessage)) {
+ throw new WSIFException("response not a
javax.jms.TextMessage");
+ }
+
+ try {
+ TextMessage m = (TextMessage) msg;
+ Message responseMessage = new Message(m.getText());
+ responseMessage.setMessageType(Message.RESPONSE);
+
+ Service service = new Service();
+ MessageContext msgContext = new
MessageContext(service.getEngine());
+ msgContext.setResponseMessage(responseMessage);
+
+ // This registerTypeMapping code is duplicated in prepare
+ TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry();
+ org.apache.axis.encoding.TypeMapping tm =
+ (org.apache.axis.encoding.TypeMapping)
tmr.getTypeMapping(
+ outputEncodingStyle);
+ Class objClass;
+ String namespaceURI, localPart;
+ WSIFDynamicTypeMapping wsifdynamictypemapping;
+ for (Iterator iterator = typeMap.iterator();
iterator.hasNext();) {
+ wsifdynamictypemapping =
+ (WSIFDynamicTypeMapping) iterator.next();
+ objClass = wsifdynamictypemapping.getJavaType();
+ namespaceURI =
+
wsifdynamictypemapping.getXmlType().getNamespaceURI();
+
+ // Filter out XSD and SOAP-ENC types from those we
explicitly map.
+ // Axis already knows how to deal with these; using
the BeanSerializer
+ // would be wrong anyway as they represent simple
types and not beans.
+ if (namespaceURI != null
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_SOAP_ENC)) {
+ localPart =
+
wsifdynamictypemapping.getXmlType().getLocalPart();
+ QName qn = new QName(namespaceURI, localPart);
+ BeanSerializerFactory bsf =
+ new BeanSerializerFactory(objClass,
qn);
+ BeanDeserializerFactory bdf =
+ new BeanDeserializerFactory(objClass,
qn);
+ tm.register(objClass, qn, bsf, bdf);
+ }
+ }
+
+ Message resMsg = msgContext.getResponseMessage();
+ SOAPEnvelope resEnv = resMsg.getSOAPEnvelope();
+
+ Object b = resEnv.getFirstBody();
+ if (b instanceof SOAPFaultElement) {
+ return new AxisFault(b.toString());
+ }
+
+ // RPCElement body = (RPCElement)resEnv.getFirstBody();
+ RPCElement body = (RPCElement) b;
+
+ Object result = null;
+ HashMap outParams;
+ Vector resArgs = body.getParams();
+
+ if (resArgs != null && resArgs.size() > 0) {
+ RPCParam param = (RPCParam) resArgs.get(0);
+ result = param.getValue();
+
+ if (resArgs.size() > 1) {
+ outParams = new HashMap();
+ for (int i = 1; i < resArgs.size(); i++) {
+ RPCParam p = (RPCParam) resArgs.get(i);
+ outParams.put(p.getName(),
p.getValue());
+ }
+ setResponseMsgParams(outParams);
+ }
+ }
+ return result;
+ } catch (Exception ex) {
+ Trc.exception(ex);
+ throw new WSIFException(ex.getMessage());
+ }
+
+ }
+
+ /**
+ * Extracts the output or fault message parts from the axis response.
+ */
+ private boolean buildResponseMessages(
+ Object resp,
+ WSIFMessage outMsg,
+ WSIFMessage faultMsg)
+ throws WSIFException {
+
+ boolean respOK;
+
+ if (resp instanceof AxisFault) {
+ respOK = false;
+ if (faultMsg != null) {
+ AxisFault f = (AxisFault) resp;
+ faultMsg.setName(WSIFConstants.SOAP_FAULT_MSG_NAME);
+
faultMsg.setObjectPart(WSIFConstants.SOAP_FAULT_OBJECT, f);
+ }
+ } else {
+ respOK = true;
+ populateOutMsgReturnPart(resp, outMsg);
+ populateOutMsgParts(outMsg);
+ }
+
+ return respOK;
+ }
+
+ /**
+ * Populate the outMessage with the response return value.
+ */
+ private void populateOutMsgReturnPart(Object resp, WSIFMessage outMsg)
+ throws WSIFException {
+ if (outMsg != null) {
+ if (returnName != null) {
+ if (resp == null) {
+ throw new WSIFException("return value not
found in response message");
+ } else if (
+ returnType != null // will be null for async
responses
+ && !returnType.isPrimitive()
+ &&
!(returnType.isAssignableFrom(resp.getClass()))) {
+ throw new WSIFException(
+ "return value "
+ + resp
+ + " has unexpected type "
+ + resp.getClass()
+ + " instead of "
+ + returnType);
+ }
+ outMsg.setObjectPart(returnName, resp);
+ }
+ }
+ }
+
+ /**
+ * Populate the outMessage with the expected parts.
+ * (this only does the out parameters not the return part)
+ */
+ private void populateOutMsgParts(WSIFMessage outMsg) throws WSIFException {
+ if (outMsg != null) {
+ HashMap respParms = getResponseMsgParams();
+ ArrayList wsdlOutParams = getWSDLOutParams();
+ if (respParms != null) {
+ String name;
+ Object value;
+ for (Iterator i = respParms.keySet().iterator();
+ i.hasNext();
+ ) {
+ name = (String) i.next();
+ value = respParms.get(name);
+ outMsg.setObjectPart(name, value);
+ wsdlOutParams.remove(name);
+ }
+ }
+ // init any other parts to null
+ for (Iterator i = wsdlOutParams.iterator(); i.hasNext();) {
+ outMsg.setObjectPart((String) i.next(), null);
+ }
+ }
+ }
+
+ public boolean executeRequestResponseOperation(
+ WSIFMessage wsifmessage,
+ WSIFMessage wsifmessage1,
+ WSIFMessage wsifmessage2)
+ throws WSIFException {
+
+ Trc.entry(this, wsifmessage, wsifmessage1, wsifmessage2);
+ close();
+ setAsyncOperation(false);
+
+ boolean succ =
+ invokeRequestResponseOperation(
+ wsifmessage,
+ wsifmessage1,
+ wsifmessage2);
+ Trc.exit(succ);
+ return succ;
+ }
+
+ public boolean invokeRequestResponseOperation(
+ WSIFMessage wsifmessage,
+ WSIFMessage wsifmessage1,
+ WSIFMessage wsifmessage2)
+ throws WSIFException {
+ Trc.entry(this, wsifmessage, wsifmessage1, wsifmessage2);
+
+ Call call = portInstance.getCall();
+ Transport axistransport = getTransport();
+
+ WSIFJMSDestination dest = null;
+ if (axistransport != null) {
+ call.setTransport(axistransport);
+ if (axistransport instanceof WSIFJmsTransport) {
+ dest = ((WSIFJmsTransport)
axistransport).getDestination();
+ dest.setAsyncMode(isAsyncOperation());
+ }
+ }
+
+ if (names == null)
+ prepare(call);
+
+ if (inJmsPropVals != null && !inJmsPropVals.isEmpty())
+ dest.setProperties(inJmsPropVals);
+
+ setDestinationContext(dest); // TODO WSDL props override context???
+
+ ArrayList objects = new ArrayList();
+ for (int i = 0; i < names.length; i++) {
+ Object obj;
+ try {
+ obj = wsifmessage.getObjectPart(names[i]);
+ } catch (WSIFException ex) {
+ Trc.exception(ex);
+ obj = null;
+ }
+ if (obj != null) {
+ if (types[i] == null)
+ throw new WSIFException("Cannot map type " +
names[i]);
+
+ if (!isPrimitiveOf(obj.getClass(), types[i])
+ && !types[i].isAssignableFrom(obj.getClass()))
{
+ throw new WSIFException(
+ "value "
+ + obj
+ + " has unexpected type "
+ + obj.getClass()
+ + " instead of "
+ + types[i]);
+ }
+ }
+
+ if (inJmsProps.containsKey(names[i]) && dest != null)
+ dest.setProperty((String) (inJmsProps.get(names[i])),
obj);
+ else
+ objects.add(obj);
+ }
+
+ setCallContext(call);
+ call.setSOAPActionURI(getSoapActionURI());
+
+ Object response;
+ boolean respOK = true;
+ try {
+ String name = operation.getName();
+ Object[] objs = objects.toArray();
+ Trc.event(
+ this,
+ "Invoking operation ",
+ name,
+ " input namespace ",
+ getInputNamespace(),
+ " parameters ",
+ objs,
+ " call object ",
+ call);
+
+ response = call.invoke(getInputNamespace(), name, objs);
+ } catch (AxisFault e) {
+ Trc.exception(e);
+ response = e;
+ respOK = false;
+ }
+
+ Trc.event(this, "Returned from operation, response ", response);
+ // setJMSOutPropsInContext( dest ); TODO doesn't work yet
+
+ if (!isAsyncOperation() && returnType != null) {
+ Map callParams = call.getOutputParams();
+ if (callParams != null) {
+ HashMap outParams = new HashMap();
+ QName qn;
+ for (Iterator i = callParams.keySet().iterator();
+ i.hasNext();
+ ) {
+ qn = (QName) i.next();
+ outParams.put(qn.getLocalPart(),
callParams.get(qn));
+ }
+ setResponseMsgParams(outParams);
+ }
+ respOK =
+ buildResponseMessages(response, wsifmessage1,
wsifmessage2);
+ }
+
+ Trc.exit(respOK);
+ return respOK;
+ }
+
+ private void prepare(Call call) throws WSIFException {
+
+ // This registerTypeMapping code is duplicated in
deserialiseResponseObject
+ TypeMappingRegistry registry =
+ call.getMessageContext().getTypeMappingRegistry();
+ Class objClass;
+ String namespaceURI, localPart;
+ WSIFDynamicTypeMapping wsifdynamictypemapping;
+ for (Iterator iterator = typeMap.iterator(); iterator.hasNext();) {
+ wsifdynamictypemapping = (WSIFDynamicTypeMapping)
iterator.next();
+ objClass = wsifdynamictypemapping.getJavaType();
+ namespaceURI =
+ wsifdynamictypemapping.getXmlType().getNamespaceURI();
+
+ // Filter out XSD and SOAP-ENC types from those we explicitly
map.
+ // Axis already knows how to deal with these; using the
BeanSerializer
+ // would be wrong anyway as they represent simple types and
not beans.
+ if (namespaceURI != null
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)
+ &&
!namespaceURI.equals(WSIFConstants.NS_URI_SOAP_ENC)) {
+ localPart =
wsifdynamictypemapping.getXmlType().getLocalPart();
+ QName qn = new QName(namespaceURI, localPart);
+ BeanSerializerFactory bsf =
+ new BeanSerializerFactory(objClass, qn);
+ BeanDeserializerFactory bdf =
+ new BeanDeserializerFactory(objClass, qn);
+ call.registerTypeMapping(objClass, qn, bsf, bdf);
+ }
+ }
+
+ Input input = operation.getInput();
+ if (input != null) {
+ Object obj;
+ if (partNames != null) {
+ obj = new Vector();
+ Part part1;
+ for (Iterator iterator1 = partNames.iterator();
+ iterator1.hasNext();
+ ((List) (obj)).add(part1)) {
+ String s = (String) iterator1.next();
+ part1 = input.getMessage().getPart(s);
+ if (part1 == null)
+ throw new WSIFException(
+ "no input part named "
+ + s
+ + " for binding
operation "
+ + getName());
+ }
+
+ } else {
+ obj = input.getMessage().getOrderedParts(null);
+ }
+ int i = ((List) (obj)).size();
+ names = new String[i];
+ types = new Class[i];
+ for (int j = 0; j < i; j++) {
+ Part part2 = (Part) ((List) (obj)).get(j);
+ names[j] = part2.getName();
+ QName qname1 = part2.getTypeName();
+ if (qname1 == null)
+ throw new WSIFException(
+ "part " + names[j] + " must have type
name declared");
+
+ javax.xml.rpc.encoding.TypeMapping tm =
+ registry.getTypeMapping(
+
"http://schemas.xmlsoap.org/soap/encoding/");
+ if (tm instanceof
org.apache.axis.encoding.TypeMapping) {
+ types[j] =
+ (
+ (
+ org
+ .apache
+ .axis
+ .encoding
+ .TypeMapping)
tm)
+
.getClassForQName(
+ new QName(
+
qname1.getNamespaceURI(),
+
qname1.getLocalPart()));
+ }
+ }
+
+ } else {
+ names = new String[0];
+ types = new Class[0];
+ }
+ Output output = operation.getOutput();
+ if (output != null) {
+ Part part = null;
+ if (returnName != null) {
+ part = output.getMessage().getPart(returnName);
+ if (part == null)
+ throw new WSIFException(
+ "no output part named "
+ + returnName
+ + " for bining operation "
+ + getName());
+ } else {
+ List list = output.getMessage().getOrderedParts(null);
+ if (list.size() > 0) {
+ part = (Part) list.get(0);
+ returnName = part.getName();
+ }
+ }
+ if (part != null) {
+ QName qname = part.getTypeName();
+ javax.xml.rpc.encoding.TypeMapping tm =
+ registry.getTypeMapping(
+
"http://schemas.xmlsoap.org/soap/encoding/");
+ if (tm instanceof
org.apache.axis.encoding.TypeMapping) {
+ returnType =
+ (
+ (
+ org
+ .apache
+ .axis
+ .encoding
+ .TypeMapping)
tm)
+
.getClassForQName(
+ new QName(
+
qname.getNamespaceURI(),
+ qname.getLocalPart()));
+ }
+ }
+ // setup any output paramter part names defined in the WSDL
+ List list = output.getMessage().getOrderedParts(null);
+ if (list.size() > 1) {
+ wsdlOutParams = new ArrayList();
+ for (int i = 1; i < list.size(); i++) {
+ part = (Part) list.get(i);
+ wsdlOutParams.add(part.getName());
+ }
+ setWSDLOutParams(wsdlOutParams);
+ }
+ }
+ }
+
+ /**
+ * Sets the response handler that will be used to
+ * process the response to an asynchronous request.
+ * @param responseHandler the responseHandler to use
+ */
+ private void setResponseHandler(WSIFResponseHandler responseHandler) {
+ this.responseHandler = responseHandler;
+ }
+
+ /**
+ * Gets the response handler that will be used to
+ * process the response to a asynchronous request.
+ * @return the current response handler.
+ * package visable as its used by the transport
+ */
+ WSIFResponseHandler getResponseHandler() {
+ return responseHandler;
+ }
+
+ private ArrayList getWSDLOutParams() {
+ if (wsdlOutParams == null) {
+ wsdlOutParams = new ArrayList();
+ }
+ return wsdlOutParams;
+ }
+
+ private void setWSDLOutParams(ArrayList al) {
+ wsdlOutParams = al;
+ }
+
+ public void setDefinition(Definition definition1) {
+ Trc.entry(this, definition1);
+ definition = definition1;
+ Trc.exit();
+ }
+
+ public void setDynamicWSIFPort(WSIFPort_ApacheAxis wsifport_apacheaxis) {
+ Trc.entry(this, wsifport_apacheaxis);
+ portInstance = wsifport_apacheaxis;
+ Trc.exit();
+ }
+
+ public void setInputEncodingStyle(String s) {
+ Trc.entry(this, s);
+ inputEncodingStyle = s;
+ Trc.exit();
+ }
+
+ public void setInputNamespace(String s) {
+ Trc.entry(this, s);
+ inputNamespace = s;
+ Trc.exit();
+ }
+
+ public void setOperation(Operation operation1) {
+ Trc.entry(this, operation1);
+ operation = operation1;
+ Trc.exit();
+ }
+
+ public void setOutputEncodingStyle(String s) {
+ Trc.entry(this, s);
+ outputEncodingStyle = s;
+ Trc.exit();
+ }
+
+ public void setPartNames(List list) {
+ Trc.entry(this, list);
+ partNames = list;
+ Trc.exit();
+ }
+
+ public void setReturnName(String s) {
+ Trc.entry(this, s);
+ returnName = s;
+ Trc.exit();
+ }
+
+ public void setSoapActionURI(String s) {
+ Trc.entry(this, s);
+ actionUri = s;
+ Trc.exit();
+ }
+
+ private void setResponseMsgParams(HashMap hm) {
+ outParams = hm;
+ }
+
+ /**
+ * Sets if the currently executing request is an asynchronous request.
+ *
+ * @param b true if the current request is a asynchronous request,
+ * otherwise false
+ */
+ private void setAsyncOperation(boolean b) {
+ asyncOperation = b;
+ }
+
+ /**
+ * Gets the target namespace URI of this WSIFOperation
+ *
+ * @return the target namespace URI
+ */
+ public String getTargetNamespaceURI() {
+ Trc.entry(this);
+ Definition d = getDefinition();
+ String s = (d == null) ? "" : d.getTargetNamespace();
+ Trc.exit(s);
+ return s;
+ }
+
+ /**
+ * Creates a new input WSIFMessage. This overrides the
+ * WSIFDefaultOperation method to enable the use of
+ * compiled WSIFMessages by using a WSIFMessageFactory
+ * to create the message.
+ *
+ * @param name the name of the message
+ * @return a WSIFMessage instance
+ * @see WSIFOperation#createInputMessage(String)
+ */
+ // defect 131672 and disable compiled msg support for now
+ // public WSIFMessage createInputMessage(String name) {
+ // Tr.entry(this, name);
+ // Definition d = getDefinition();
+ // String ns = (d == null) ? "" : d.getTargetNamespace();
+ // WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
+ // WSIFMessage msg = mf.createMessage(ns, name + "Message");
+ // if (msg != null)
+ // msg.setName(name);
+ // Tr.exit(msg);
+ // return msg;
+ // }
+
+ /**
+ * Creates a new output WSIFMessage. This overrides the
+ * WSIFDefaultOperation method to enable the use of
+ * compiled WSIFMessages by using a WSIFMessageFactory
+ * to create the message.
+ *
+ * @param name the name of the message
+ * @return a WSIFMessage instance
+ * @see WSIFOperation#createInputMessage(String)
+ */
+ // defect 131672 and disable compiled msg support for now
+ // public WSIFMessage createOutputMessage(String name) {
+ // Tr.entry(this, name);
+ // Definition d = getDefinition();
+ // String ns = (d == null) ? "" : d.getTargetNamespace();
+ // WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
+ // WSIFMessage msg = mf.createMessage(ns, name + "Message");
+ // if (msg != null)
+ // msg.setName(name);
+ // Tr.exit(msg);
+ // return msg;
+ // }
+
+ /**
+ * This sets up the output JMS property values in the context
+ */
+ private void setJMSOutPropsInContext(WSIFJMSDestination dest)
+ throws WSIFException {
+ if (dest == null) {
+ return;
+ }
+ HashMap props = dest.getProperties();
+ if (props != null) {
+ if (context == null) {
+ context = new WSIFDefaultMessage();
+ }
+ context.setParts(props);
+ }
+ }
+
+ /**
+ * This sets up any context JMS property values in the Destination
+ */
+ private void setDestinationContext(WSIFJMSDestination dest) {
+ if (context == null || dest == null) {
+ return;
+ }
+ String partName;
+ HashMap jmsProps = new HashMap();
+ for (Iterator i = context.getPartNames(); i.hasNext();) {
+ partName = (String) i.next();
+ if (partName.startsWith(WSIFConstants.CONTEXT_JMS_PREFIX)) {
+ try {
+ jmsProps.put(
+ partName.substring(
+
WSIFConstants.CONTEXT_JMS_PREFIX.length()),
+ context.getObjectPart(partName));
+ } catch (WSIFException ex) {
+ Trc.ignoredException(ex);
+ }
+ }
+ }
+ if (jmsProps.size() > 0) {
+ dest.setProperties(jmsProps);
+ }
+ }
+
+ /**
+ * This sets up the context headers in the axis
+ * Call object prior to invoke method being issued.
+ */
+ private void setCallContext(Call call) {
+ Object o;
+ String name;
+ if (context == null) {
+ return;
+ }
+ name = WSIFConstants.CONTEXT_HTTP_USER;
+ try {
+ o = context.getObjectPart(name);
+ if (o instanceof String) {
+ addHTTPHeader(call, name, (String) o);
+ }
+ } catch (WSIFException ex) {
+ Trc.ignoredException(ex);
+ }
+
+ name = WSIFConstants.CONTEXT_HTTP_PSWD;
+ try {
+ o = context.getObjectPart(name);
+ if (o instanceof String) {
+ addHTTPHeader(call, name, (String) o);
+ }
+ } catch (WSIFException ex) {
+ Trc.ignoredException(ex);
+ }
+
+ try {
+ name = WSIFConstants.CONTEXT_SOAP_HEADERS;
+ o = context.getObjectPart(name);
+ if (o instanceof List) {
+ addSOAPHeader(call, name, (List) o);
+ }
+ } catch (WSIFException ex) {
+ Trc.ignoredException(ex);
+ }
+ }
+
+ /**
+ * Sets the SOAP headers in the message context.
+ */
+ private void addSOAPHeader(Call call, String name, List soapHeaders) {
+ for (Iterator i = soapHeaders.iterator(); i.hasNext();) {
+ Object o = i.next();
+ if (o instanceof Element) {
+ call.addHeader(new SOAPHeaderElement((Element) o));
+ }
+ }
+ }
+
+ /**
+ * Sets the HTTP header value in the message context.
+ * How these are used depends on the underlying transport,
+ * eg. org.apache.axis.transport.http.HTTPSender
+ * will use the 'user.id' and 'user.password' headers
+ * for HTTP basic authentication..
+ */
+ private void addHTTPHeader(Call call, String name, String value) {
+ if (name.equals(WSIFConstants.CONTEXT_HTTP_USER)) {
+ call.setProperty(Call.USERNAME_PROPERTY, value);
+ } else if (name.equals(WSIFConstants.CONTEXT_HTTP_PSWD)) {
+ call.setProperty(Call.PASSWORD_PROPERTY, value);
+ }
+ }
+
+ /**
+ * Returns true if primitive is the equivalent primitive class of clazz.
+ * Why doesn't java provide this function?
+ */
+ private static boolean isPrimitiveOf(Class clazz, Class primitive) {
+ if ((primitive.equals(boolean.class)
+ && Boolean.class.isAssignableFrom(clazz))
+ || (primitive.equals(char.class)
+ && Character.class.isAssignableFrom(clazz))
+ || (primitive.equals(byte.class)
+ && Byte.class.isAssignableFrom(clazz))
+ || (primitive.equals(short.class)
+ && Short.class.isAssignableFrom(clazz))
+ || (primitive.equals(int.class)
+ && Integer.class.isAssignableFrom(clazz))
+ || (primitive.equals(long.class)
+ && Long.class.isAssignableFrom(clazz))
+ || (primitive.equals(float.class)
+ && Float.class.isAssignableFrom(clazz))
+ || (primitive.equals(double.class)
+ && Double.class.isAssignableFrom(clazz)))
+ return true;
+ else
+ return false;
+ }
+
+ public String deep() {
+ String buff = "";
+ try {
+ buff = new String(super.toString() + ":\n");
+
+ buff += "portInstance:" + portInstance;
+ buff += " operation:" + Trc.brief(operation);
+ buff += " definition:" + Trc.brief(definition);
+ buff += " partNames:" + partNames;
+ buff += " names:" + names;
+ buff += " types:" + types;
+ buff += " inputEncodingStyle:" + inputEncodingStyle;
+ buff += " inputNamespace:" + inputNamespace;
+ buff += " actionUri:" + actionUri;
+ buff += " inJmsProps:" + inJmsProps;
+ buff += " outJmsProps:" + outJmsProps;
+ buff += " inJmsPropVals:" + inJmsPropVals;
+ buff += " context:" + context;
+ buff += " returnType:" + returnType;
+ buff += " asyncOperation:" + asyncOperation;
+ buff += " asyncRequestID:" + asyncRequestID;
+ buff += " responseHandler:" + responseHandler;
+ buff += " returnName:" + returnName;
+ buff += " wsdlOutParams:" + wsdlOutParams;
+ buff += " outParams:" + outParams;
+ buff += " outputEncodingStyle:" + outputEncodingStyle;
+ buff += " typeMap:" + typeMap;
+ } catch (Exception e) {
+ Trc.exceptionInTrace(e);
+ }
- return buff;
- }
+ return buff;
+ }
}