You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ow...@apache.org on 2002/06/19 16:24:44 UTC
cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apachesoap WSIFPort_ApacheSOAP.java WSIFOperation_ApacheSOAP.java
owenb 2002/06/19 07:24:42
Modified: java/src/org/apache/wsif/providers/soap/apachesoap
WSIFPort_ApacheSOAP.java
WSIFOperation_ApacheSOAP.java
Log:
Moved the creation of mappings in the SOAPMappingRegistry from the WSIFOperation_ApacheSOAP
to WSIFPort_ApacheSOAP so that it occurs only once for all operations created from a single instance
of WSIFPort_ApacheSOAP.
Changed getDynamicWSIFOperation on WSIFPort_ApahceSOAP so that it returns a copy of an
operation if it has already been created rather than returning the original reference.
Fixed the deserialization of WSIFOperation_ApacheSOAP objects when invoking operations
asynchronously so that it can handle JROM parts if necessary.
Revision Changes Path
1.4 +202 -30 xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apachesoap/WSIFPort_ApacheSOAP.java
Index: WSIFPort_ApacheSOAP.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apachesoap/WSIFPort_ApacheSOAP.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WSIFPort_ApacheSOAP.java 12 Jun 2002 10:27:25 -0000 1.3
+++ WSIFPort_ApacheSOAP.java 19 Jun 2002 14:24:42 -0000 1.4
@@ -76,19 +76,24 @@
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPHeader;
import javax.wsdl.extensions.soap.SOAPOperation;
+
import org.apache.soap.Constants;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.Base64Serializer;
+import org.apache.soap.encoding.soapenc.BeanSerializer;
import org.apache.soap.encoding.soapenc.DateSerializer;
import org.apache.soap.rpc.Call;
import org.apache.soap.transport.SOAPTransport;
import org.apache.soap.transport.http.SOAPHTTPConnection;
+import org.apache.soap.util.xml.Deserializer;
+import org.apache.soap.util.xml.Serializer;
import org.apache.wsif.WSIFException;
-import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.base.WSIFDefaultPort;
+import org.apache.wsif.base.WSIFServiceImpl;
import org.apache.wsif.logging.Tr;
import org.apache.wsif.providers.WSIFDynamicTypeMap;
+import org.apache.wsif.providers.WSIFDynamicTypeMapping;
import org.apache.wsif.wsdl.extensions.jms.JMSAddress;
import org.apache.wsif.wsdl.extensions.jms.JMSProperty;
import org.apache.wsif.wsdl.extensions.jms.JMSPropertyValue;
@@ -117,6 +122,7 @@
protected String partSerializerName = null;
private static final boolean DEBUG = false; //for internal use only
private WSIFDynamicTypeMap wsifTypeMap = null;
+ private HashMap localTypeMap = new HashMap();
private List jmsAddressPropVals = null;
/**
@@ -152,11 +158,13 @@
if (sa != null && ja != null)
throw new WSIFException(
- "Both soap:address and jms:address cannot be specified for port " + port);
+ "Both soap:address and jms:address cannot be specified for port "
+ + port);
if (sa == null && ja == null)
throw new WSIFException(
- "Either soap:address or jms:address must be specified for port " + port);
+ "Either soap:address or jms:address must be specified for port "
+ + port);
if (ja != null) {
// Port jms:address binding element
@@ -164,13 +172,16 @@
st = new SOAPJMSConnection(ja);
} else {
// Port soap:address bindng element
- st = new SOAPHTTPConnection(); // call.getSOAPTransport() is null...
+ st = new SOAPHTTPConnection();
+ // call.getSOAPTransport() is null...
String s = sa.getLocationURI();
try {
url = new URL(s);
} catch (MalformedURLException meu) {
- throw new WSIFException("could not set SOAP address to " + s, meu);
+ throw new WSIFException(
+ "could not set SOAP address to " + s,
+ meu);
}
if (url == null) {
throw new WSIFException(
@@ -190,12 +201,21 @@
style = "document"; //it is default style value as of WSDL 1.1
String transport = soapBinding.getTransportURI();
- if ((ja != null && !"http://schemas.xmlsoap.org/soap/jms".equals(transport))
- || (sa != null && !"http://schemas.xmlsoap.org/soap/http".equals(transport))) {
+ if ((ja != null
+ && !"http://schemas.xmlsoap.org/soap/jms".equals(transport))
+ || (sa != null
+ && !"http://schemas.xmlsoap.org/soap/http".equals(
+ transport))) {
throw new WSIFException(
- "unsupported transport " + transport + " for " + soapBinding);
+ "unsupported transport "
+ + transport
+ + " for "
+ + soapBinding);
}
}
+
+ // Prepare mappings for use by all operations created from this port.
+ prepareTypeMappings();
if (Tr.ON)
Tr.exit(deep());
@@ -300,18 +320,133 @@
Tr.exit();
}
- public JROMSOAPMappingRegistry getJROMSOAPMappingRegistry() {
+ protected JROMSOAPMappingRegistry getJROMSOAPMappingRegistry() {
Tr.entry(this);
- if (jromSMR == null)
- jromSMR = new JROMSOAPMappingRegistry(smr);
Tr.exit(jromSMR);
return jromSMR;
}
+
+ protected HashMap getLocalTypeMap() {
+ return localTypeMap;
+ }
- public void setJROMSOAPMappingRegistry(JROMSOAPMappingRegistry jsmr) {
- Tr.entry(this, jsmr);
- jromSMR = jsmr;
- Tr.exit();
+ private void prepareTypeMappings() {
+ boolean jromAvailable = WSIFServiceImpl.getJROMAvailability();
+ if (jromAvailable) {
+ this.jromSMR = new JROMSOAPMappingRegistry(this.smr);
+ } else {
+ this.jromSMR = null;
+ }
+ prepareTypeMappings(
+ this.smr,
+ this.jromSMR,
+ this.wsifTypeMap,
+ partSerializerName,
+ localTypeMap);
+ }
+
+ static void prepareTypeMappings(
+ SOAPMappingRegistry theSMR,
+ JROMSOAPMappingRegistry theJROMSMR,
+ WSIFDynamicTypeMap theTypeMap,
+ String thePartSerializerName,
+ HashMap theLocalTypeMap) {
+
+ BeanSerializer beanSer = new BeanSerializer();
+ PartSerializer partSer = null;
+ if (thePartSerializerName != null)
+ try {
+ partSer =
+ (PartSerializer) Class
+ .forName(
+ thePartSerializerName,
+ true,
+ Thread.currentThread().getContextClassLoader())
+ .newInstance();
+ } catch (Throwable ignored) {
+ }
+
+ Serializer literalSerializer = partSer;
+ Deserializer literalDeserializer = partSer;
+ String literalEncoding = "literal";
+ Serializer soapSerializer = beanSer;
+ Deserializer soapDeserializer = beanSer;
+ String soapEncoding = Constants.NS_URI_SOAP_ENC;
+
+ boolean jromAvailable = WSIFServiceImpl.getJROMAvailability();
+
+ JROMSerializer jromSer = null;
+
+ // Only deal with JROM if it's available
+ if (jromAvailable) {
+ if (theJROMSMR == null) {
+ theJROMSMR = new JROMSOAPMappingRegistry(theSMR);
+ }
+ jromSer = new JROMSerializer();
+ }
+
+ // initialize ApacheSOAP specific mappings here
+ for (Iterator i = theTypeMap.iterator(); i.hasNext();) {
+ WSIFDynamicTypeMapping mapping = (WSIFDynamicTypeMapping) i.next();
+
+ Class javaClass = mapping.getJavaType();
+ org.apache.soap.util.xml.QName typeName =
+ new org.apache.soap.util.xml.QName(
+ mapping.getXmlType().getNamespaceURI(),
+ mapping.getXmlType().getLocalPart());
+
+ // Add mappings to a local hashmap for use in preparation of the operation
+ theLocalTypeMap.put(typeName, javaClass);
+
+ if (jromAvailable) {
+ // JROM SOAP mapping registry should return a JROMSerializer for all
+ // type mappings
+ theJROMSMR.mapTypes(
+ soapEncoding,
+ typeName,
+ javaClass,
+ jromSer,
+ jromSer);
+ theJROMSMR.mapTypes(
+ literalEncoding,
+ typeName,
+ javaClass,
+ jromSer,
+ jromSer);
+ }
+
+ Serializer ser = null;
+ // Set up SOAP encoding mappings
+ try {
+ ser = theSMR.querySerializer(javaClass, soapEncoding);
+ } catch (IllegalArgumentException iae) {
+ }
+ // Only add a mapping if a serializer does not already exist
+ if (ser == null) {
+ theSMR.mapTypes(
+ soapEncoding,
+ typeName,
+ javaClass,
+ soapSerializer,
+ soapDeserializer);
+ }
+
+ // Set up literal encoding mappings
+ try {
+ ser = null;
+ ser = theSMR.querySerializer(javaClass, soapEncoding);
+ } catch (IllegalArgumentException iae) {
+ }
+ // Only add a mapping if a serializer does not already exist
+ if (ser == null) {
+ theSMR.mapTypes(
+ literalEncoding,
+ typeName,
+ javaClass,
+ literalSerializer,
+ literalDeserializer);
+ }
+ }
}
public URL getEndPoint() {
@@ -411,19 +546,32 @@
throws WSIFException {
Tr.entry(this, name, inputName, outputName);
- WSIFOperation_ApacheSOAP operation =
+ WSIFOperation_ApacheSOAP tempOp =
(WSIFOperation_ApacheSOAP) operationInstances.get(
getKey(name, inputName, outputName));
+ WSIFOperation_ApacheSOAP operation = null;
+ if (tempOp != null) {
+ operation = tempOp.copy();
+ }
+
if (operation == null) {
BindingOperation bop =
- port.getBinding().getBindingOperation(name, inputName, outputName);
+ port.getBinding().getBindingOperation(
+ name,
+ inputName,
+ outputName);
if (bop != null) {
- operation = new WSIFOperation_ApacheSOAP(this, bop.getOperation(), wsifTypeMap);
+ operation =
+ new WSIFOperation_ApacheSOAP(
+ this,
+ bop.getOperation(),
+ wsifTypeMap);
if (operation == null) {
throw new WSIFException(
- "Operation not found from binding operation: " + bop.getName());
+ "Operation not found from binding operation: "
+ + bop.getName());
}
operation.setStyle(this.style);
@@ -452,18 +600,26 @@
operation.setSoapActionURI(soapActionURI);
if (DEBUG)
System.err.println(
- "setting actionURI " + soapActionURI + " for op " + operation.getName());
+ "setting actionURI "
+ + soapActionURI
+ + " for op "
+ + operation.getName());
String opStyle = soapOperation.getStyle();
// try to get soap:body for input message
BindingInput binpt = bop.getBindingInput();
SOAPBody soapInputBody =
- (SOAPBody) getExtElem(binpt, SOAPBody.class, binpt.getExtensibilityElements());
+ (SOAPBody) getExtElem(binpt,
+ SOAPBody.class,
+ binpt.getExtensibilityElements());
if (soapInputBody != null) {
String namespaceURI = soapInputBody.getNamespaceURI();
if (DEBUG)
System.err.println(
- "setting namespace " + namespaceURI + " for op " + operation.getName());
+ "setting namespace "
+ + namespaceURI
+ + " for op "
+ + operation.getName());
operation.setInputNamespace(namespaceURI);
String use = soapInputBody.getUse();
operation.setInputUse(use);
@@ -472,7 +628,8 @@
if (encodingStyles != null) {
if (encodingStyles.size() == 0) {
}
- operation.setInputEncodingStyle((String) encodingStyles.get(0));
+ operation.setInputEncodingStyle(
+ (String) encodingStyles.get(0));
// quietly ignore if encodingStyles.size() > 1 ...
}
List parts = soapInputBody.getParts();
@@ -485,11 +642,15 @@
SOAPHeader.class,
binpt.getExtensibilityElements());
if (soapHeader != null) {
- throw new WSIFException("not supported input soap:header " + soapHeader);
+ throw new WSIFException(
+ "not supported input soap:header " + soapHeader);
}
List inJmsProps =
- getExtElems(binpt, JMSProperty.class, binpt.getExtensibilityElements());
+ getExtElems(
+ binpt,
+ JMSProperty.class,
+ binpt.getExtensibilityElements());
if (inJmsProps != null && inJmsProps.size() > 0) {
if (st instanceof SOAPJMSConnection)
operation.setInputJmsProperties(inJmsProps);
@@ -508,7 +669,7 @@
else
throw new WSIFException("jms:propertyValue found in non-jms binding");
}
-
+
// try to get soap:body for output message
BindingOutput boutpt = bop.getBindingOutput();
if (boutpt != null) {
@@ -534,11 +695,15 @@
SOAPHeader.class,
boutpt.getExtensibilityElements());
if (soapHeader != null) {
- throw new WSIFException("not supported output soap:header " + soapHeader);
+ throw new WSIFException(
+ "not supported output soap:header " + soapHeader);
}
List outJmsProps =
- getExtElems(boutpt, JMSProperty.class, boutpt.getExtensibilityElements());
+ getExtElems(
+ boutpt,
+ JMSProperty.class,
+ boutpt.getExtensibilityElements());
if (outJmsProps != null && outJmsProps.size() > 0) {
if (st instanceof SOAPJMSConnection)
operation.setOutputJmsProperties(outJmsProps);
@@ -610,14 +775,21 @@
if (operationInstances == null) {
buff += " operationInstances: null";
} else {
- buff += " operationInstances: size:" + operationInstances.size();
+ buff += " operationInstances: size:"
+ + operationInstances.size();
Iterator it = operationInstances.keySet().iterator();
int i = 0;
while (it.hasNext()) {
String key = (String) it.next();
WSIFOperation_ApacheSOAP woas =
(WSIFOperation_ApacheSOAP) operationInstances.get(key);
- buff += "\noperationInstances[" + i + "]:" + key + " " + woas.getName() + " ";
+ buff += "\noperationInstances["
+ + i
+ + "]:"
+ + key
+ + " "
+ + woas.getName()
+ + " ";
i++;
}
}
1.7 +33 -82 xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apachesoap/WSIFOperation_ApacheSOAP.java
Index: WSIFOperation_ApacheSOAP.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apachesoap/WSIFOperation_ApacheSOAP.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WSIFOperation_ApacheSOAP.java 14 Jun 2002 14:28:03 -0000 1.6
+++ WSIFOperation_ApacheSOAP.java 19 Jun 2002 14:24:42 -0000 1.7
@@ -150,6 +150,7 @@
protected String inputUse = null;
protected String outputUse = null;
protected String partSerializerName = null;
+ protected boolean usingJROM = false;
/**
* Create Apache SOAP operation instance that encapsultes all necessary
@@ -265,14 +266,12 @@
void prepare(WSIFMessage inputMessage, WSIFMessage outputMessage)
throws WSIFException {
Tr.entry(this, inputMessage, outputMessage);
- HashMap mapOfUserTypes = new HashMap();
+ HashMap mapOfUserTypes = portInstance.getLocalTypeMap();
SOAPMappingRegistry smr = portInstance.getSOAPMappingRegistry();
- boolean jromAvailable = WSIFServiceImpl.getJROMAvailability();
- boolean usingJROM =
+ usingJROM =
(WSIFConstants.JROM_REPR_STYLE.equals(inputMessage.getRepresentationStyle()))
? true
: false;
- setupTypeMappings(mapOfUserTypes, smr, jromAvailable, usingJROM);
// first determine list of arguments
Input input = operation.getInput();
@@ -369,78 +368,21 @@
private void setupTypeMappings(
HashMap mapOfUserTypes,
SOAPMappingRegistry smr,
- boolean jromAvailable,
- boolean usingJROM)
- throws WSIFException {
- BeanSerializer beanSer = new BeanSerializer();
- PartSerializer partSer = null;
- if (partSerializerName != null)
- try {
- partSer =
- (PartSerializer) Class
- .forName(
- partSerializerName,
- true,
- Thread.currentThread().getContextClassLoader())
- .newInstance();
- } catch (Throwable ignored) {
- }
-
- Serializer serializer = null;
- Deserializer deserializer = null;
- String encoding = null;
-
- if ("literal".equals(inputUse) && "literal".equals(outputUse)) {
- serializer = partSer;
- deserializer = partSer;
- encoding = "literal";
- } else // soap encoding
- {
- serializer = beanSer;
- deserializer = beanSer;
- encoding = Constants.NS_URI_SOAP_ENC;
- }
-
- if (usingJROM && !jromAvailable) {
- // This should not happen unless the representation style has been
- // explicitly set incorrectly!
- throw new WSIFException("Message contains JROM parts but JROM classes cannot be found");
- }
-
- JROMSerializer jromSer = null;
- JROMSOAPMappingRegistry jromSMR = null;
-
- if (jromAvailable) {
- jromSMR = portInstance.getJROMSOAPMappingRegistry();
- jromSer = new JROMSerializer();
- }
-
- // initialize ApacheSOAP specific mappings here
- for (Iterator i = typeMap.iterator(); i.hasNext();) {
- WSIFDynamicTypeMapping mapping = (WSIFDynamicTypeMapping) i.next();
-
- Class javaClass = mapping.getJavaType();
- org.apache.soap.util.xml.QName typeName =
- new org.apache.soap.util.xml.QName(
- mapping.getXmlType().getNamespaceURI(),
- mapping.getXmlType().getLocalPart());
- mapOfUserTypes.put(typeName, mapping.getJavaType());
-
- if (jromAvailable) {
- // JROM SOAP mapping registry should return a JROMSerializer for all
- // type mappings
- jromSMR.mapTypes(encoding, typeName, javaClass, jromSer, jromSer);
- }
-
- Serializer ser;
- try {
- ser = smr.querySerializer(javaClass, encoding);
- if (ser != null)
- continue;
- } catch (IllegalArgumentException ignored) {
- }
-
- smr.mapTypes(encoding, typeName, javaClass, serializer, deserializer);
+ JROMSOAPMappingRegistry jromSMR)
+ throws WSIFException {
+
+ // Mappings are set in the WSIFPort_ApacheSOAP which created this operation.
+ // However, if this operation was deserialized for an async response then
+ // we will have no reference to a WSIFPort and so we need to explicitly
+ // create the mappings again.
+ if (portInstance == null) {
+ HashMap tempMap = new HashMap();
+ WSIFPort_ApacheSOAP.prepareTypeMappings(
+ smr,
+ jromSMR,
+ typeMap,
+ partSerializerName,
+ tempMap);
}
}
@@ -484,7 +426,7 @@
if (!prepared)
prepare(input, output);
- boolean usingJROM =
+ usingJROM =
(WSIFConstants.JROM_REPR_STYLE.equals(input.getRepresentationStyle()))
? true
: false;
@@ -921,9 +863,13 @@
//TODO need to sort out smr and JROM stuff <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//SOAPMappingRegistry smr = portInstance.getSOAPMappingRegistry();
SOAPMappingRegistry smr = WSIFPort_ApacheSOAP.createSOAPMappingRegistry();
- boolean usingJROM = false;
- boolean jromAvailable = false;
- setupTypeMappings(mapOfUserTypes, smr, jromAvailable, usingJROM);
+ JROMSOAPMappingRegistry jromSMR = null;
+
+ boolean jromAvailable = WSIFServiceImpl.getJROMAvailability();
+ if (jromAvailable) {
+ jromSMR = new JROMSOAPMappingRegistry(smr);
+ }
+ setupTypeMappings(mapOfUserTypes, smr, jromSMR);
try {
@@ -949,9 +895,14 @@
// Unmarshall the response envelope.
Envelope respEnv = Envelope.unmarshall(payload, respCtx);
-
+
+ Response resp = null;
+ if (usingJROM) {
+ resp = Response.extractFromEnvelope(respEnv, jromSMR, respCtx);
+ } else {
// Extract the response from the response envelope.
- Response resp = Response.extractFromEnvelope(respEnv, smr, respCtx);
+ resp = Response.extractFromEnvelope(respEnv, smr, respCtx);
+ }
return resp;