You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by sa...@apache.org on 2005/11/27 12:46:43 UTC
svn commit: r349213 - in /webservices/commons/trunk/policy/interop: ./ ibm/
ibm/src/ ibm/src/META-INF/ ibm/src/org/ ibm/src/org/apache/
ibm/src/org/apache/ws/ ibm/src/org/apache/ws/policy/
ibm/src/org/apache/ws/policy/interop/
Author: sanka
Date: Sun Nov 27 03:46:26 2005
New Revision: 349213
URL: http://svn.apache.org/viewcvs?rev=349213&view=rev
Log:
Implementation of a policy interop service endpoint and a simple client (see http://wsi.alphaworks.ibm.com:8080/wspolicy/index.html)
Added:
webservices/commons/trunk/policy/interop/
webservices/commons/trunk/policy/interop/ibm/
webservices/commons/trunk/policy/interop/ibm/src/
webservices/commons/trunk/policy/interop/ibm/src/META-INF/
webservices/commons/trunk/policy/interop/ibm/src/META-INF/services.xml
webservices/commons/trunk/policy/interop/ibm/src/org/
webservices/commons/trunk/policy/interop/ibm/src/org/apache/
webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/
webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/
webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/
webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyClient.java
webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java
Added: webservices/commons/trunk/policy/interop/ibm/src/META-INF/services.xml
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/interop/ibm/src/META-INF/services.xml?rev=349213&view=auto
==============================================================================
--- webservices/commons/trunk/policy/interop/ibm/src/META-INF/services.xml (added)
+++ webservices/commons/trunk/policy/interop/ibm/src/META-INF/services.xml Sun Nov 27 03:46:26 2005
@@ -0,0 +1,18 @@
+<service name="PolicyService">
+ <description>
+ Policy Service
+ </description>
+ <parameter name="ServiceClass" locked="false">org.apache.ws.policy.interop.SimplePolicyService</parameter>
+ <operation name="normalize">
+ <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+ <parameter name="wsamapping" locked="xsd:false">http://example.com/ws/2004/09/policy/Normalize/Request</parameter>
+ </operation>
+ <operation name="intersect">
+ <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+ <parameter name="wsamapping" locked="xsd:false">http://example.com/ws/2004/09/policy/Intersect/Request</parameter>
+ </operation>
+ <operation name="merge">
+ <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+ <parameter name="wsamapping" locked="xsd:false">http://example.com/ws/2004/09/policy/Merge/Request</parameter>
+ </operation>
+</service>
\ No newline at end of file
Added: webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyClient.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyClient.java?rev=349213&view=auto
==============================================================================
--- webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyClient.java (added)
+++ webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyClient.java Sun Nov 27 03:46:26 2005
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.policy.interop;
+
+import java.io.FileInputStream;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Call;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.axis2.soap.SOAPEnvelope;
+
+/**
+ * @author Sanka Samaranayake (sanka@apache.org)
+ */
+public class SimplePolicyClient {
+ public static void main(String[] args) throws Exception {
+ Call call = new Call();
+ call.setWsaAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Request");
+ call.setTo(new EndpointReference("http://localhost:8080/axis2/services/PolicyService"));
+
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP, false);
+
+ FileInputStream fis = new FileInputStream(
+ "/home/sanka/policy-docs/primitive.xml");
+ XMLStreamReader xmlr = XMLInputFactory.newInstance()
+ .createXMLStreamReader(fis);
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(
+ OMAbstractFactory.getOMFactory(), xmlr);
+
+ OMElement arg = builder.getDocumentElement();
+
+ SOAPEnvelope env = OMAbstractFactory.getSOAP11Factory()
+ .getDefaultEnvelope();
+
+ // adding arg1
+ env.getBody().addChild(arg);
+
+ //env.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out));
+
+// fis = new FileInputStream("/home/sanka/policy-docs/policy2.xml");
+// xmlr = XMLInputFactory.newInstance().createXMLStreamReader(fis);
+// builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory
+// .getOMFactory(), xmlr);
+// arg = builder.getDocumentElement();
+//
+// adding arg2
+// env.getBody().addChild(arg);
+
+ OMElement resutl = call.invokeBlocking("foo", env);
+ StringWriter sw = new StringWriter();
+ resutl.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(
+ System.out));
+ sw.flush();
+ System.out.println(sw.toString());
+
+ }
+
+}
Added: webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java?rev=349213&view=auto
==============================================================================
--- webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java (added)
+++ webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java Sun Nov 27 03:46:26 2005
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.policy.interop;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.axis2.soap.SOAPBody;
+import org.apache.ws.policy.model.Policy;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyReader;
+import org.apache.ws.policy.util.PolicyWriter;
+
+
+/**
+ * @author Sanka Samaranayake (sanka@apache.org)
+ */
+public class SimplePolicyService {
+ private MessageContext msgCtx = null;
+
+ public void init(MessageContext msgCtx) {
+ this.msgCtx = msgCtx;
+ }
+
+ public OMElement normalize() {
+ Iterator iterator = getArgs().iterator();
+ OMElement element = (OMElement) iterator.next();
+
+ Policy argOne = getReader().readPolicy(getInputStream(element));
+ Policy normalized = (Policy) argOne.normalize();
+ return getOMElement(normalized);
+ }
+
+ public OMElement merge() {
+ Iterator iterator = getArgs().iterator();
+ System.out.println("inside merge");
+
+ OMElement element = (OMElement) iterator.next();
+ OMElement element2 = (OMElement) iterator.next();
+
+ Policy argOne = getReader().readPolicy(getInputStream(element));
+ Policy argTwo = getReader().readPolicy(getInputStream(element2));
+
+ Policy merged = (Policy) argOne.merge(argTwo);
+ return getOMElement(merged);
+
+ }
+
+ public OMElement intersect() {
+ Iterator iterator = getArgs().iterator();
+ OMElement element = (OMElement) iterator.next();
+ OMElement element2 = (OMElement) iterator.next();
+
+ Policy argOne = getReader().readPolicy(getInputStream(element));
+ Policy argTwo = getReader().readPolicy(getInputStream(element2));
+
+ Policy intersected = (Policy) argOne.intersect(argTwo);
+ return getOMElement(intersected);
+ }
+
+ private ArrayList getArgs() {
+ ArrayList argList = new ArrayList();
+
+ SOAPBody body = msgCtx.getEnvelope().getBody();
+ Iterator iterator = body.getChildElements();
+ OMElement child;
+
+ while (iterator.hasNext()) {
+ child = getWholeElement((OMElement) iterator.next());
+ argList.add(child);
+ }
+
+ return argList;
+ }
+
+ private PolicyReader getReader() {
+ return PolicyFactory.getInstance().getPolicyReader();
+ }
+
+ private PolicyWriter getWriter() {
+ return PolicyFactory.getInstance().getPolicyWriter();
+ }
+
+ private OMElement getWholeElement(OMElement element) {
+ element.build();
+ element.detach();
+ return element;
+ }
+
+ private InputStream getInputStream(OMElement element) {
+ try {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ element.serialize(XMLOutputFactory.newInstance()
+ .createXMLStreamWriter(baos));
+ return new ByteArrayInputStream(baos.toByteArray());
+
+ } catch (XMLStreamException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+
+ private OMElement getOMElement(Policy policy) {
+ try {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ getWriter().writePolicy(policy, baos);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos
+ .toByteArray());
+ XMLStreamReader reader = XMLInputFactory.newInstance()
+ .createXMLStreamReader(bais);
+ OMXMLParserWrapper wrapper = OMXMLBuilderFactory
+ .createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
+ reader);
+
+ return wrapper.getDocumentElement();
+
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}