You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2006/09/05 20:25:22 UTC
svn commit: r440428 [5/5] - in /webservices/muse/trunk/modules: ./ preview/
preview/muse-wsrt-api/ preview/muse-wsrt-api/specs/
preview/muse-wsrt-api/src/ preview/muse-wsrt-api/src/org/
preview/muse-wsrt-api/src/org/apache/ preview/muse-wsrt-api/src/or...
Added: webservices/muse/trunk/modules/preview/muse-wsrt-impl/src/org/apache/muse/ws/resource/transfer/remote/WsrtResourceClient.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/preview/muse-wsrt-impl/src/org/apache/muse/ws/resource/transfer/remote/WsrtResourceClient.java?view=auto&rev=440428
==============================================================================
--- webservices/muse/trunk/modules/preview/muse-wsrt-impl/src/org/apache/muse/ws/resource/transfer/remote/WsrtResourceClient.java (added)
+++ webservices/muse/trunk/modules/preview/muse-wsrt-impl/src/org/apache/muse/ws/resource/transfer/remote/WsrtResourceClient.java Tue Sep 5 11:25:18 2006
@@ -0,0 +1,308 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.resource.transfer.remote;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.Environment;
+import org.apache.muse.util.xml.XPathUtils;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.WsaConstants;
+import org.apache.muse.ws.addressing.soap.SoapClient;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.resource.transfer.Expression;
+import org.apache.muse.ws.resource.transfer.ExpressionFactory;
+import org.apache.muse.ws.resource.transfer.Fragment;
+import org.apache.muse.ws.resource.transfer.OperationResult;
+import org.apache.muse.ws.resource.transfer.WsrtConstants;
+import org.apache.muse.ws.resource.transfer.create.Metadata;
+import org.apache.muse.ws.resource.transfer.impl.SimpleExpressionFactory;
+import org.apache.muse.ws.resource.transfer.impl.SimpleOperationResult;
+
+/**
+ * This is the WS-RT CLient API provided by Muse for invoking WS-RT operations
+ * on a WS-RT Web service. To use this API first create an instance by passing
+ * in EPR of resource and then invoke operations as needed. <br>
+ *
+ * Eg: <br>
+ * EndpointReference epr = new EndpointReference(new
+ * URI("http://localhost:8080/services/myservice")); <br>
+ * QName param = new QName(WsaConstants.MUSE_ADDRESSING_URI,"ResourceId" ,
+ * "ns1"); <br>
+ * epr.addParameter(param, "MuseResource-1");<br>
+ * <br>
+ * WsrtResourceClient client = new WsrtResourceClient(epr); <br>
+ * Element resp = client.get(); <br>
+ *
+ * @author Mohammad Fakhar
+ *
+ */
+
+public class WsrtResourceClient extends AbstractWsrtResourceClient
+{
+
+ public WsrtResourceClient(EndpointReference destination)
+ {
+ super(destination);
+ }
+
+ public WsrtResourceClient(EndpointReference destination, EndpointReference source)
+ {
+ super(destination, source);
+ }
+
+ public WsrtResourceClient(EndpointReference destination, EndpointReference source, Environment environment)
+ {
+ super(destination, source, environment);
+ }
+
+ public WsrtResourceClient(EndpointReference destination, EndpointReference source, SoapClient soapClient)
+ {
+ super(destination, source, soapClient);
+ }
+
+ /**
+ * Sends a WS-Transfer create request to resource with resource property
+ * document passed in and returns EPR of newly created resource
+ *
+ */
+ public EndpointReference create(Element resource) throws SoapFault
+ {
+ URI action = URI.create(WsrtConstants.CREATE_URI);
+ Element[] response = invokeWSRTOperation(action, resource, false);
+
+ return extractEPR(response);
+ }
+
+ /**
+ * Sends a WS-RT create request to resource with fragments passed in and
+ * returns EPR of newly created resource
+ *
+ */
+ public EndpointReference create(String dialect, Fragment[] fragments) throws SoapFault
+ {
+ return create(dialect, fragments, null);
+ }
+
+ /**
+ * Sends a WS-RT create request to resource with fragments and metadata
+ * passed in and returns EPR of newly created resource
+ *
+ */
+ public EndpointReference create(String dialect, Fragment[] fragments, Metadata metadata) throws SoapFault
+ {
+ Document factory = XmlUtils.EMPTY_DOC;
+ Element request = XmlUtils.createElement(factory, WsrtConstants.CREATE_QNAME);
+ request.setAttribute(WsrtConstants.DIALECT_ATTR_NAME, dialect);
+
+ URI action = URI.create(WsrtConstants.CREATE_URI);
+
+ if (metadata != null)
+ {
+ request.appendChild(metadata.toXML(factory));
+ }
+
+ for (int i = 0; i < fragments.length; i++)
+ {
+ Element fragXML = fragments[i].toXML(factory);
+ request.appendChild(fragXML);
+ }
+
+ Element[] response = invokeWSRTOperation(action, request, true);
+
+ return extractEPR(response);
+ }
+
+ /**
+ * Sends a WS-Transfer Get request to resource and returns the resource
+ * representation
+ *
+ */
+ public Element get() throws SoapFault
+ {
+
+ URI action = URI.create(WsrtConstants.GET_URI);
+ Element[] response = invokeWSRTOperation(action, null, false);
+ return response.length == 0 ? null : response[0];
+ }
+
+ /**
+ * Sends a WS-RT Get request to resource with WS-RT Expressions and returns
+ * the expression values
+ *
+ */
+ public OperationResult[] get(String dialect, Expression[] expressions) throws SoapFault
+ {
+ Document doc = XmlUtils.EMPTY_DOC;
+ Element request = XmlUtils.createElement(doc, WsrtConstants.GET_QNAME);
+ request.setAttribute(WsrtConstants.DIALECT_ATTR_NAME, dialect);
+
+ URI action = URI.create(WsrtConstants.GET_URI);
+
+ for (int i = 0; i < expressions.length; i++)
+ {
+ Element exprXML = expressions[i].toXML(doc);
+ request.appendChild(exprXML);
+ }
+
+ Element[] response = invokeWSRTOperation(action, request, true);
+
+ return extractResults(response);
+ }
+
+ /**
+ * Sends a WS-RT Get request to resource with WS-RT XPath dialect
+ * Expressions and returns the expression values
+ *
+ */
+ public OperationResult[] getWithXPaths(String[] xpaths) throws SoapFault
+ {
+ ExpressionFactory factory = new SimpleExpressionFactory();
+ Expression[] expressions = new Expression[xpaths.length];
+
+ for (int i = 0; i < xpaths.length; i++)
+ expressions[i] = factory.createXPathExpression(xpaths[i]);
+
+ return get(XPathUtils.NAMESPACE_URI, expressions);
+ }
+
+ /**
+ * Sends a WS-RT Get request to resource with WS-RT QName dialect
+ * Expressions and returns the expression values
+ *
+ */
+ public OperationResult[] getWithProps(QName[] props) throws SoapFault
+ {
+ ExpressionFactory factory = new SimpleExpressionFactory();
+ Expression[] expressions = new Expression[props.length];
+
+ for (int i = 0; i < props.length; i++)
+ expressions[i] = factory.createQNameExpression(props[i]);
+
+ return get(WsrtConstants.QNAME_DIALECT, expressions);
+ }
+
+ /**
+ * Sends a WS-Transfer request to resource with resource property document
+ * and if the document is not accepted verbatim by engine, the final
+ * representation is returned.
+ *
+ */
+ public Element[] put(Element resource) throws SoapFault
+ {
+ URI action = URI.create(WsrtConstants.PUT_URI);
+ Element[] response = invokeWSRTOperation(action, resource, false);
+
+ return response;
+ }
+
+ /**
+ * Sends a WS-RT request to resource with WS-RT Fragments
+ *
+ */
+ public void put(String dialect, Fragment[] fragments) throws SoapFault
+ {
+ Element request = XmlUtils.createElement(WsrtConstants.PUT_QNAME);
+ request.setAttribute(WsrtConstants.DIALECT_ATTR_NAME, dialect);
+
+ URI action = URI.create(WsrtConstants.PUT_URI);
+
+ for (int i = 0; i < fragments.length; i++)
+ {
+ Element fragXML = fragments[i].toXML(request.getOwnerDocument());
+ request.appendChild(fragXML);
+ }
+
+ invokeWSRTOperation(action, request, true);
+ }
+
+ /**
+ * Sends a WS-Transfer delete request to resource
+ *
+ */
+
+ public void delete() throws SoapFault
+ {
+ URI action = URI.create(WsrtConstants.DELETE_URI);
+
+ invokeWSRTOperation(action, null, false);
+ }
+
+ protected EndpointReference extractEPR(Element[] createResponse) throws SoapFault
+ {
+ for (int i = 0; i < createResponse.length; i++)
+ {
+ Element element = createResponse[i];
+ QName name = new QName(element.getNamespaceURI(), element.getLocalName());
+
+ if (name.equals(WsrtConstants.RESOURCE_CREATED_QNAME))
+ {
+ Document doc = XmlUtils.EMPTY_DOC;
+
+ Element[] eprChildren = XmlUtils.getAllElements(element);
+ Element eprXML = XmlUtils.createElement(doc, WsaConstants.EPR_QNAME);
+
+ for (int j = 0; j < eprChildren.length; j++)
+ {
+ eprXML.appendChild(doc.importNode(eprChildren[j], true));
+ }
+
+ return new EndpointReference(eprXML);
+ }
+ }
+
+ return null;
+
+ }
+
+ protected OperationResult[] extractResults(Element[] getResponse)
+ {
+ if (getResponse == null || getResponse.length == 0)
+ return null;
+ List results = new ArrayList();
+ Element getResultXML = getResponse[0];
+ QName qname = new QName(getResultXML.getNamespaceURI(), getResultXML.getLocalName(),
+ getResultXML.getPrefix());
+
+ if (!qname.equals(WsrtConstants.GET_RESPONSE_QNAME))
+ throw new RuntimeException("Unrecognized element " + qname + " in WSRT get response");
+
+ Element[] resultsXML = XmlUtils.getElements(getResultXML, WsrtConstants.RESULT_QNAME);
+
+ for (int i = 0; i < resultsXML.length; i++)
+ {
+ OperationResult result = new SimpleOperationResult(resultsXML[i]);
+ results.add(result);
+ }
+
+ OperationResult[] resultsArr = new OperationResult[results.size()];
+ for (int i = 0; i < results.size(); i++)
+ resultsArr[i] = (OperationResult)results.get(i);
+
+ return resultsArr;
+ }
+
+}
Added: webservices/muse/trunk/modules/preview/pom.xml
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/preview/pom.xml?view=auto&rev=440428
==============================================================================
--- webservices/muse/trunk/modules/preview/pom.xml (added)
+++ webservices/muse/trunk/modules/preview/pom.xml Tue Sep 5 11:25:18 2006
@@ -0,0 +1,19 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>preview</artifactId>
+ <groupId>muse</groupId>
+ <name>Apache Muse - Preview Modules</name>
+ <parent>
+ <groupId>muse</groupId>
+ <artifactId>build-all</artifactId>
+ <version>2.0.0</version>
+ </parent>
+ <packaging>pom</packaging>
+ <version>2.0.0</version>
+ <modules>
+ <module>muse-wsrt-api</module>
+ <module>muse-wsrt-impl</module>
+ </modules>
+</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org