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 sa...@apache.org on 2006/04/08 14:02:14 UTC
svn commit: r392509 -
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
Author: sanka
Date: Sat Apr 8 05:02:10 2006
New Revision: 392509
URL: http://svn.apache.org/viewcvs?rev=392509&view=rev
Log:
added support for proper serialization of policies
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java?rev=392509&r1=392508&r2=392509&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java Sat Apr 8 05:02:10 2006
@@ -4,15 +4,27 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+
import org.apache.axis2.wsdl.SOAPHeaderMessage;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.ws.java2wsdl.Java2WSDLConstants;
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PolicyReference;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyWriter;
+import org.apache.ws.policy.util.StAXPolicyWriter;
+import org.apache.wsdl.extensions.SOAPHeader;
+
import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
@@ -232,6 +244,7 @@
OMElement operation = fac.createOMElement(OPERATION_LOCAL_NAME, wsdl);
portType.addChild(operation);
operation.addAttribute(ATTRIBUTE_NAME, operationName, null);
+ addPolicy(PolicyInclude.OPERATION_POLICY, axisOperation.getPolicyInclude(), operation, fac);
String MEP = axisOperation.getMessageExchangePattern();
if (WSDLConstants.MEP_URI_IN_ONLY.equals(MEP) ||
@@ -246,6 +259,7 @@
OMElement input = fac.createOMElement(IN_PUT_LOCAL_NAME, wsdl);
input.addAttribute(MESSAGE_LOCAL_NAME, tns.getPrefix() + ":"
+ inaxisMessage.getName() + MESSAGE_SUFFIX, null);
+ addPolicy(PolicyInclude.INPUT_POLICY, inaxisMessage.getPolicyInclude(), input, fac);
operation.addChild(input);
}
}
@@ -262,6 +276,7 @@
OMElement output = fac.createOMElement(OUT_PUT_LOCAL_NAME, wsdl);
output.addAttribute(MESSAGE_LOCAL_NAME, tns.getPrefix() + ":"
+ outAxisMessage.getName() + MESSAGE_SUFFIX, null);
+ addPolicy(PolicyInclude.OUTPUT_POLICY, outAxisMessage.getPolicyInclude(), output, fac);
operation.addChild(output);
}
}
@@ -275,9 +290,13 @@
fault.addAttribute(MESSAGE_LOCAL_NAME, tns.getPrefix() + ":"
+ faultyMessge.getName() + MESSAGE_SUFFIX, null);
fault.addAttribute(ATTRIBUTE_NAME, faultyMessge.getName(), null);
+ // TODO add policies for fault messages
operation.addChild(fault);
}
}
+
+
+
}
}
@@ -290,10 +309,14 @@
defintions.addChild(service);
service.addAttribute(ATTRIBUTE_NAME, axisService.getName(), null);
generateSOAP11Port(fac, service);
- generateSOAP12Port(fac, service);
+ generateSOAP12Port(fac, service);
+
+ addPolicy(PolicyInclude.SERVICE_POLICY, axisService.getPolicyInclude(), service, fac);
+
if (generateHttp) {
generateHTTPPort(fac, service);
}
+
}
private void generateSOAP11Port(OMFactory fac, OMElement service) throws Exception {
@@ -306,7 +329,11 @@
axisService.getName() + BINDING_NAME_SUFFIX, null);
addExtensionElemnet(fac, port, SOAP_ADDRESS, LOCATION,
urlString, soap);
+
+ addPolicy(PolicyInclude.PORT_POLICY, axisService.getPolicyInclude(), service, fac);
}
+
+
}
private void generateHTTPPort(OMFactory fac, OMElement service) throws Exception {
@@ -336,6 +363,8 @@
axisService.getName() + SOAP12BINDING_NAME_SUFFIX, null);
addExtensionElemnet(fac, port, SOAP_ADDRESS, LOCATION,
urlString, soap12);
+
+ addPolicy(PolicyInclude.PORT_POLICY, axisService.getPolicyInclude(), service, fac);
}
}
@@ -348,7 +377,8 @@
defintions.addChild(binding);
binding.addAttribute(ATTRIBUTE_NAME, axisService.getName() + BINDING_NAME_SUFFIX, null);
binding.addAttribute("type", tns.getPrefix() + ":" + axisService.getName() + PORT_TYPE_SUFFIX, null);
-
+ addPolicy(PolicyInclude.BINDING_POLICY, axisService.getPolicyInclude(), binding, fac);
+
//Adding ext elements
addExtensionElemnet(fac, binding, BINDING_LOCAL_NAME,
TRANSPORT, TRANSPORT_URI,
@@ -370,6 +400,8 @@
addExtensionElemnet(fac, operation, OPERATION_LOCAL_NAME,
SOAP_ACTION, soapAction,
STYLE, style, soap);
+ addPolicy(PolicyInclude.BINDING_OPERATION_POLICY, axisOperation.getPolicyInclude(), operation, fac);
+
String MEP = axisOperation.getMessageExchangePattern();
if (WSDLConstants.MEP_URI_IN_ONLY.equals(MEP) ||
@@ -385,6 +417,7 @@
OMElement input = fac.createOMElement(IN_PUT_LOCAL_NAME, wsdl);
addExtensionElemnet(fac, input, SOAP_BODY, SOAP_USE, use, "namespace",
targetNamespace, soap);
+ addPolicy(PolicyInclude.BINDING_INPUT_POLICY, inaxisMessage.getPolicyInclude(), input, fac);
operation.addChild(input);
writeSoapHeaders(inaxisMessage, fac, input, soap);
}
@@ -402,6 +435,7 @@
OMElement output = fac.createOMElement(OUT_PUT_LOCAL_NAME, wsdl);
addExtensionElemnet(fac, output, SOAP_BODY, SOAP_USE, use, "namespace",
targetNamespace, soap);
+ addPolicy(PolicyInclude.BINDING_OUTPUT_POLICY, outAxisMessage.getPolicyInclude(), output, fac);
operation.addChild(output);
writeSoapHeaders(outAxisMessage, fac, output, soap);
}
@@ -416,11 +450,14 @@
addExtensionElemnet(fac, fault, SOAP_BODY, SOAP_USE, use, "namespace",
targetNamespace, soap);
fault.addAttribute(ATTRIBUTE_NAME, faultyMessge.getName(), null);
+ // TODO adding policies for fault messages
operation.addChild(fault);
writeSoapHeaders(faultyMessge, fac, fault, soap);
}
}
}
+
+
}
/**
@@ -432,7 +469,8 @@
defintions.addChild(binding);
binding.addAttribute(ATTRIBUTE_NAME, axisService.getName() + SOAP12BINDING_NAME_SUFFIX, null);
binding.addAttribute("type", tns.getPrefix() + ":" + axisService.getName() + PORT_TYPE_SUFFIX, null);
-
+ addPolicy(PolicyInclude.BINDING_POLICY, axisService.getPolicyInclude(), binding, fac);
+
//Adding ext elements
addExtensionElemnet(fac, binding, BINDING_LOCAL_NAME,
TRANSPORT, TRANSPORT_URI,
@@ -454,6 +492,8 @@
addExtensionElemnet(fac, operation, OPERATION_LOCAL_NAME,
SOAP_ACTION, soapAction,
STYLE, style, soap12);
+ addPolicy(PolicyInclude.BINDING_OPERATION_POLICY, axisOperation.getPolicyInclude(), operation, fac);
+
String MEP = axisOperation.getMessageExchangePattern();
if (WSDLConstants.MEP_URI_IN_ONLY.equals(MEP) ||
@@ -469,6 +509,7 @@
OMElement input = fac.createOMElement(IN_PUT_LOCAL_NAME, wsdl);
addExtensionElemnet(fac, input, SOAP_BODY, SOAP_USE, use, "namespace",
targetNamespace, soap12);
+ addPolicy(PolicyInclude.BINDING_INPUT_POLICY, inaxisMessage.getPolicyInclude(), input, fac);
operation.addChild(input);
writeSoapHeaders(inaxisMessage, fac, input, soap12);
}
@@ -486,6 +527,7 @@
OMElement output = fac.createOMElement(OUT_PUT_LOCAL_NAME, wsdl);
addExtensionElemnet(fac, output, SOAP_BODY, SOAP_USE, use, "namespace",
targetNamespace, soap12);
+ addPolicy(PolicyInclude.BINDING_OUTPUT_POLICY, outAxisMessage.getPolicyInclude(), output, fac);
operation.addChild(output);
writeSoapHeaders(outAxisMessage, fac, output, soap12);
}
@@ -500,6 +542,7 @@
addExtensionElemnet(fac, fault, SOAP_BODY, SOAP_USE, use, "namespace",
targetNamespace, soap12);
fault.addAttribute(ATTRIBUTE_NAME, faultyMessge.getName(), null);
+ // add policies for fault messages
operation.addChild(fault);
writeSoapHeaders(faultyMessge, fac, fault, soap12);
}
@@ -645,5 +688,33 @@
}
return null;
}
-
+
+ private void addPolicy(int type, PolicyInclude policyInclude, OMElement element, OMFactory factory) {
+ ArrayList elementList = policyInclude.getPolicyElements(type);
+ StAXPolicyWriter pwrt = (StAXPolicyWriter) PolicyFactory.getPolicyWriter(PolicyFactory.StAX_POLICY_WRITER);
+
+ for (Iterator iterator = elementList.iterator(); iterator.hasNext();) {
+ Object policyElement = iterator.next();
+
+ if (policyElement instanceof Policy) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ pwrt.writePolicy((Policy) policyElement, baos);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ try {
+ element.addChild(OMXMLBuilderFactory.createStAXOMBuilder(factory, XMLInputFactory.newInstance().createXMLStreamReader(bais)).getDocumentElement());
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ // TODO handle this exception
+ }
+
+
+ } else if (policyElement instanceof PolicyReference) {
+ // TODO need to implement this ..
+ }
+
+ }
+
+ }
}