Hi Bill,
I've completed the ResourceLifetime spec components and added a
convenience method or two. Please
apply the patch and update at your earliest convenience.
Thanks.
-Simeon
Index:
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/wsdl/resource/testresource.wsdl
===================================================================
---
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/wsdl/resource/testresource.wsdl
(revision 292500)
+++
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/wsdl/resource/testresource.wsdl
(working copy)
@@ -1,8 +1,10 @@
<?xml version="1.0"?>
-<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://ws.apache.org/service/testresource"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"
xmlns:wsrpw="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"
xmlns:wsntw="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.wsdl"
xmlns:muws-p2-wsdl="http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.wsdl"
targetNamespace="http://ws.apache.org/service/testresource"
name="TestResource">
+<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://ws.apache.org/service/testresource"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"
xmlns:wsrpw="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"
xmlns:wsntw="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.wsdl"
xmlns:muws-p2-wsdl="http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.wsdl"
xmlns:wsrlw="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl"
xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd"
targetNamespace="http://ws.apache.org/service/testresource"
name="TestResource">
<import
namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"
location="../spec/wsrf/WS-ResourceProperties-1_2-Draft_01.wsdl"/>
<import
namespace="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.wsdl"
location="../spec/wsn/WS-BaseNotification-1_2-Draft_01.wsdl"/>
<import
namespace="http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.wsdl"
location="../spec/wsdm/MUWS-Part2-1_0.wsdl"/>
+ <import
namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.wsdl"
+ location="../spec/wsrf/WS-ResourceLifetime-1_2-Draft_01.wsdl"/>
<types>
<schema elementFormDefault="qualified"
targetNamespace="http://ws.apache.org/service/testresource"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsbf="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-BaseFaults-1.2-draft-01.xsd"
xmlns:wsnt="http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd"
xmlns:muws-p1-xs="http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part1.xsd"
xmlns:muws-p2-xs="http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2.xsd"
xmlns:mows-xs="http://docs.oasis-open.org/wsdm/2004/12/mows/wsdm-mows.xsd">
<xsd:import
namespace="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-BaseFaults-1.2-draft-01.xsd"
schemaLocation="../spec/wsrf/WS-BaseFaults-1_2-Draft_01.xsd"/>
@@ -41,6 +43,8 @@
<element
ref="muws-p2-xs:CurrentTime"/>
<element
ref="muws-p2-xs:OperationalStatus"/>
<element
ref="mows-xs:LastResponseTime"/>
+ <element
ref="wsrl:CurrentTime"/>
+ <element
ref="wsrl:TerminationTime" />
</sequence>
</complexType>
</element>
@@ -111,6 +115,19 @@
<input message="tns:TestOperationRequest"/>
<output message="tns:TestOperationResponse"/>
</operation>
+ <operation name="Destroy">
+ <input message="wsrlw:DestroyRequest"/>
+ <output message="wsrlw:DestroyResponse"/>
+ <fault name="ResourceUnknownFault"
message="wsrlw:ResourceUnknownFault"/>
+ <fault name="ResourceNotDestroyedFault"
message="wsrlw:ResourceNotDestroyedFault"/>
+ </operation>
+ <operation name="SetTerminationTime">
+ <input message="wsrlw:SetTerminationTimeRequest"/>
+ <output message="wsrlw:SetTerminationTimeResponse"/>
+ <fault name="ResourceUnknownFault"
message="wsrlw:ResourceUnknownFault"/>
+ <fault name="UnableToSetTerminationTimeFault"
message="wsrlw:UnableToSetTerminationTimeFault"/>
+ <fault name="TerminationTimeChangeRejectedFault"
message="wsrlw:TerminationTimeChangeRejectedFault"/>
+ </operation>
</portType>
<binding name="TestResourceSoapHttpBinding"
type="tns:TestResourcePortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
@@ -243,6 +260,39 @@
<soap:body use="literal"/>
</output>
</operation>
+ <operation name="Destroy">
+ <soap:operation style="document"/>
+ <input>
+ <soap:body use="literal"/>
+ </input>
+ <output>
+ <soap:body use="literal"/>
+ </output>
+ <fault name="ResourceUnknownFault">
+ <soap:fault name="ResourceUnknownFault"
use="literal"/>
+ </fault>
+ <fault name="ResourceNotDestroyedFault">
+ <soap:fault name="ResourceNotDestroyedFault"
use="literal"/>
+ </fault>
+ </operation>
+ <operation name="SetTerminationTime">
+ <soap:operation style="document"/>
+ <input>
+ <soap:body use="literal"/>
+ </input>
+ <output>
+ <soap:body use="literal"/>
+ </output>
+ <fault name="ResourceUnknownFault">
+ <soap:fault name="ResourceUnknownFault" use="literal"/>
+ </fault>
+ <fault name="UnableToSetTerminationTimeFault">
+ <soap:fault name="UnableToSetTerminationTimeFault"
use="literal"/>
+ </fault>
+ <fault name="TerminationTimeChangeRejectedFault">
+ <soap:fault name="TerminationTimeChangeRejectedFault"
use="literal"/>
+ </fault>
+ </operation>
</binding>
<service name="TestResourceService">
<port name="TestResource"
binding="tns:TestResourceSoapHttpBinding">
Index:
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
===================================================================
---
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
(revision 292500)
+++
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
(working copy)
@@ -22,10 +22,15 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -37,32 +42,59 @@
import org.apache.ws.client.muse.client.impl.stubs.ServiceStub;
import org.apache.ws.client.muse.client.impl.wsrf.InsertOrUpdateRequest;
import org.apache.ws.client.muse.client.impl.wsrf.SetPropertiesRequestImpl;
-import org.apache.ws.client.muse.client.model.SetPropertiesRequest;
+import org.apache.ws.client.muse.client.model.PropertiesList;
import org.apache.ws.muws.v1_0.capability.IdentityCapability;
+import org.apache.ws.service.testresource.TestResourcePropertyQNames;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlDateTime;
+import org.apache.xmlbeans.XmlDocumentProperties;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.apache.xmlbeans.impl.regex.ParseException;
+import org.apache.xmlbeans.impl.soap.Node;
+import org.apache.xmlbeans.impl.soap.SOAPElement;
+import org.apache.xmlbeans.impl.soap.SOAPException;
import org.apache.xmlbeans.impl.values.XmlAnyUriImpl;
import org.apache.xmlbeans.impl.values.XmlBooleanImpl;
+import org.apache.xmlbeans.impl.values.XmlDateTimeImpl;
import org.apache.xmlbeans.impl.values.XmlDoubleImpl;
import org.apache.xmlbeans.impl.values.XmlIntImpl;
import org.apache.xmlbeans.impl.values.XmlStringImpl;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.CurrentTimeDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.DestroyDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.DestroyResponseDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.SetTerminationTimeDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.SetTerminationTimeResponseDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.SetTerminationTimeDocument.SetTerminationTime;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.DestroyDocumentImpl;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.DestroyResponseDocumentImpl;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.SetTerminationTimeResponseDocumentImpl;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.DeleteType;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetMultipleResourcePropertiesDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyDocument;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.InsertType;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesDocument;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesResponseDocument;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesResponseDocument;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesResponseDocument;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateType;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetMultipleResourcePropertiesDocument.GetMultipleResourceProperties;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesDocument.QueryResourceProperties;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesDocument.SetResourceProperties;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.GetMultipleResourcePropertiesDocumentImpl;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.GetMultipleResourcePropertiesResponseDocumentImpl;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.GetResourcePropertyDocumentImpl;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.QueryResourcePropertiesDocumentImpl;
import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.SetResourcePropertiesResponseDocumentImpl;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.QueryResourcePropertiesDocumentImpl.QueryResourcePropertiesImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+import
org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.SetResourcePropertiesResponseDocumentImpl;
import org.xmlsoap.schemas.soap.envelope.impl.FaultImpl;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
@@ -228,6 +260,26 @@
}
/*
+ * Returns a specific property value as an XmlDateTime object.
+ */
+ /* (non-Javadoc)
+ * @see
org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsBoolean(javax.xml.namespace.QName)
+ */
+ public XmlDateTime getPropertyAsDateTime(QName propertyName) throws
FaultException, URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException {
+ LOG.info("getting property value "+propertyName+" from " +
this.epr.getAddress());
+ XmlObject[] parts = rs.getResourceProperty(propertyName);
+ for (int i = 0; i < parts.length; i++) {
+ XmlObject xmlObject = parts[i];
+ if (xmlObject instanceof XmlDateTimeImpl) {
+ XmlDateTimeImpl childElement =
(XmlDateTimeImpl) xmlObject;
+ return childElement;
+ }
+ }
+ throw new UnexpectedServerResponseException(
+ "Server returned either an unrecognizable response or no
boolean type was returned as a response.");
+ }
+
+ /*
* Returns a specific property value as a bolean.
*/
/* (non-Javadoc)
@@ -272,7 +324,7 @@
cursor.setTextValue("/");
cursor.dispose();
- XmlObject parts =
rs.sendRequest(queryDocument,"http://queryresourcepropertydocument","M");
+ XmlObject parts =
rs.sendRequest(queryDocument,"http://queryresourcepropertydocument");
if(!(parts instanceof
QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse))
throw new UnexpectedServerResponseException("Expected
QueryResourcePropertiesResponseDocument but received
"+parts.getClass().getName());
@@ -280,7 +332,6 @@
cursor=response.newCursor();
cursor.toChild(0);
cursor.toFirstChild();
- XmlAnyUriImpl obj = (XmlAnyUriImpl)cursor.getObject();
Vector infoList = new Vector(20);
QName propName=cursor.getName();
infoList.add(propName);
@@ -310,7 +361,7 @@
}
//Now send the request
- XmlObject parts =
rs.sendRequest(gmpDoc,"http://getmultipleresourcepropertydocument","M");
+ XmlObject parts =
rs.sendRequest(gmpDoc,"http://getmultipleresourcepropertydocument");
if(!(parts instanceof
GetMultipleResourcePropertiesResponseDocumentImpl.GetMultipleResourcePropertiesResponseImpl))
throw new UnexpectedServerResponseException("Expected
GetMultipleResourcePropertiesResponseDocumentImpl but received
"+parts.getClass().getName());
@@ -412,7 +463,7 @@
cursor.setTextValue(xpathExp);
cursor.dispose();
- XmlObject parts =
rs.sendRequest(queryDocument,"http://queryresourcepropertydocument","M");
+ XmlObject parts =
rs.sendRequest(queryDocument,"http://queryresourcepropertydocument");
if(parts instanceof FaultImpl)
throw new FaultException(parts.toString());
if(!(parts instanceof
QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse))
@@ -452,6 +503,15 @@
return success;
}
+ public void updateProperty(QName property, XmlObject update) throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ String xmlText;
+ XmlOptions opts = new XmlOptions();
+ opts.setSaveOuter();
+ opts.setSavePrettyPrint();
+ xmlText=update.xmlText(opts);
+ updateProperty(property,xmlText);
+ }
+
public void updateProperty(QName property, double newValue) throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException{
String[] updates = {String.valueOf(newValue)};
updateProperty(property, updates);
@@ -514,7 +574,7 @@
/* updateProperties takes a SetPropertiesRequest instance which defines
* Insert, Update and Delete requests and the order in which they were
made.
*/
- public XmlObject setProperties(SetPropertiesRequest modificationList)
throws URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ public XmlObject setProperties(PropertiesList modificationList) throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
//build the SetResourceProperties document
SetResourcePropertiesDocument setPropsDocument =
@@ -561,7 +621,7 @@
validateXmlBean(setPropsDocument);
- XmlObject parts =
rs.sendRequest(setPropsDocument,"http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceProperties/SetResourceProperties","M");
+ XmlObject parts =
rs.sendRequest(setPropsDocument,"http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceProperties/SetResourceProperties");
if(parts instanceof FaultImpl)
throw new FaultException(parts.toString());
if(!(parts instanceof
SetResourcePropertiesResponseDocumentImpl.SetResourcePropertiesResponseImpl))
@@ -661,7 +721,157 @@
}
//helper method to create SetPropertiesRequest instance
- public SetPropertiesRequest createNewSetPropertiesRequest(){
+ public PropertiesList createNewSetPropertiesRequest(){
return new SetPropertiesRequestImpl();
}
+
+ /**
+ * This method causes the immediate destruction of this stateful
WS-Resource.
+ * <b>Note:</b> this operation may not be supported by this resource.
+ * A resource must implement Destroy for this method to work.
+ * @return
+ * @throws FaultException
+ * @throws UnexpectedServerResponseException
+ * @throws XmlException
+ * @throws IOException
+ * @throws URISyntaxException
+ * @throws FaultException
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws XmlException
+ * @throws UnexpectedServerResponseException
+ */
+ public XmlObject[] destroyResourceImmediately() throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ //build the destroy document
+ DestroyDocument destroyDocument =
DestroyDocument.Factory.newInstance();
+ destroyDocument.addNewDestroy();
+
+ XmlObject parts =
rs.sendRequest(destroyDocument,"http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/Destroy");
+ if(parts instanceof FaultImpl)
+ throw new FaultException(parts.toString());
+ if(!(parts instanceof DestroyResponseDocument.DestroyResponse))
+ throw new UnexpectedServerResponseException("Expected
DestroyResponseDocument but received "+parts.getClass().getName());
+
+ //cast to response
+ DestroyResponseDocument.DestroyResponse
response=(DestroyResponseDocument.DestroyResponse)parts;
+
+ //navigate the document to retrieve all the properties
+ XmlCursor cursor = null;
+ cursor=response.newCursor();
+ cursor.toChild(0);
+ cursor.toFirstChild();
+
+ //store all encountered responses
+ Vector infoList = new Vector(20);
+ XmlObject propValue=cursor.getObject();
+ infoList.add(propValue);
+
+ //for numerous response components
+ while(cursor.toNextSibling()){
+ propValue=cursor.getObject();
+ infoList.add(propValue);
+ }
+ cursor.dispose();
+
+ //build the response
+ return (XmlObject[]) infoList.toArray(new XmlObject[0]);
+
+ }
+
+ public String getCurrentTimeAsString(QName requestedProperty) throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ String timeOnResource = "";
+
+ XmlDateTime time = getCurrentTime(requestedProperty);
+ timeOnResource = time.getStringValue();
+
+ return timeOnResource;
+ }
+
+ public XmlDateTime getCurrentTime(QName requestedProperty) throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ //retrieve as XMLDateTime
+ XmlDateTime time = getPropertyAsDateTime(requestedProperty);
+ return time;
+ }
+
+ public String getTerminationTimeAsString(QName requestedProperty)
throws URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ String timeOnResource = "";
+ XmlDateTime time = getCurrentTime(requestedProperty);
+ timeOnResource = time.getStringValue();
+ return timeOnResource;
+ }
+
+ public XmlDateTime getTerminationTime(QName requestedProperty) throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ //retrieve as XMLDateTime
+ XmlDateTime time = getPropertyAsDateTime(requestedProperty);
+ return time;
+ }
+
+ /**This is a convenience method that allows the user to simply specify
+ * the number of milliseconds from whatever time exists on the server,
after
+ * which to schedule termination for this resource.
+ * The specification does not attempt to guarantee client-server time
synchronization.
+ * This method simply queries the CurrentTime and then adds the number
of milliseconds
+ * entered to the scheduledTerminationTime.
+ * When using this method or any other destroy or scheduled destruction
methods consider
+ * transport latency times for the destruction request/response
interchange.
+ * @return XMLObject[]
+ * @throws FaultException
+ * @throws UnexpectedServerResponseException
+ * @throws XmlException
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public XmlObject[] scheduleTerminationInNMilliSeconds(long timeFromNow)
throws URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException{
+ XmlObject[] response = null;
+ XmlDateTime currentServerTime =
getCurrentTime(TestResourcePropertyQNames.CURRENTTIME2);
+ long current =
currentServerTime.getCalendarValue().getTimeInMillis();
+ //build new XmlDateTime to schedule TimeOfDeath(TOD)
+ XmlDateTime tod = XmlDateTime.Factory.newInstance();
+ Calendar instance = Calendar.getInstance();
+ instance.setTimeInMillis(current+timeFromNow);
+ tod.setCalendarValue(instance);
+
+ //issue the Scheduled death request
+ response = setTerminationTime(tod);
+
+ return response;
+ }
+
+ public XmlObject[] setTerminationTime(XmlDateTime instanceOfTime)
throws URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException {
+ //build the SetTerminationTime document
+ SetTerminationTimeDocument terminationScheduleDocument =
SetTerminationTimeDocument.Factory.newInstance();
+ SetTerminationTime tTime =
terminationScheduleDocument.addNewSetTerminationTime();
+
tTime.setRequestedTerminationTime(instanceOfTime.getCalendarValue());
+
+ XmlObject parts =
rs.sendRequest(terminationScheduleDocument,"http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/SetTerminationTime");
+ if(parts instanceof FaultImpl)
+ throw new FaultException(parts.toString());
+ if(!(parts instanceof
SetTerminationTimeResponseDocumentImpl.SetTerminationTimeResponseImpl))
+ throw new UnexpectedServerResponseException("Expected
SetTerminationTimeResponseDocumentImpl but received
"+parts.getClass().getName());
+
+ //cast to response
+
SetTerminationTimeResponseDocumentImpl.SetTerminationTimeResponseImpl response=
+
(SetTerminationTimeResponseDocumentImpl.SetTerminationTimeResponseImpl)parts;
+
+ //navigate the document to retrieve all the properties
+ XmlCursor cursor = null;
+ cursor=response.newCursor();
+ cursor.toChild(0);
+ cursor.toFirstChild();
+
+ //store all encountered responses
+ Vector infoList = new Vector(20);
+ XmlObject propValue=cursor.getObject();
+ infoList.add(propValue);
+
+ //for numerous response components
+ while(cursor.toNextSibling()){
+ propValue=cursor.getObject();
+ infoList.add(propValue);
+ }
+ cursor.dispose();
+
+ //build the response
+ return (XmlObject[]) infoList.toArray(new XmlObject[0]);
+ }
}
Index:
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
===================================================================
---
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
(revision 292500)
+++
C:/Eclipse/eclipse_3.1/workspace/muse-client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
(working copy)
@@ -4,18 +4,22 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.Calendar;
import javax.xml.namespace.QName;
import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
import
org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
-import org.apache.ws.client.muse.client.model.SetPropertiesRequest;
+import org.apache.ws.client.muse.client.model.PropertiesList;
import
org.apache.ws.resource.properties.faults.InvalidResourcePropertyQNameFaultException;
import
org.apache.ws.muws.v1_0.impl.advertiser.ResourceAdvertiserPropertyQNames;
import org.apache.ws.service.testresource.TestResourcePropertyQNames;
import org.apache.ws.util.test.axis.MuseClientTestCase;
+import org.apache.xmlbeans.XmlDate;
+import org.apache.xmlbeans.XmlDateTime;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.impl.values.XmlDateTimeImpl;
public class ManageableResourceImplTest extends MuseClientTestCase {
private static String id="0001";
@@ -36,6 +40,9 @@
protected void tearDown() throws Exception {
super.tearDown();
+ this.testAddress = null;
+ this.eprTxt = null;
+ this.testImpl = null;
}
/**
* Objective: Request a list of property qnames and make sure it is
@@ -264,7 +271,7 @@
//now carry out update, delete and insert in one call.
//verify that those values were successfully changed.
//temp check that messages built properly
- SetPropertiesRequest tmpRequest = null;
+ PropertiesList tmpRequest = null;
//retrieve current property value
double newVal =
testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE);
//initialize the SetPropertiesRequest instance
@@ -373,7 +380,7 @@
newValue = (propValue - .1);
String
namePropValue=testImpl.getPropertyAsString(TestResourcePropertyQNames.NAME);
String newValue2 = namePropValue+"-modified";
- SetPropertiesRequest setRequest2 =
+ PropertiesList setRequest2 =
testImpl.createNewSetPropertiesRequest();
String[] priceUpdate = {String.valueOf(newValue)};
setRequest2.addUpdateRequest(TestResourcePropertyQNames.PRICE,priceUpdate);
@@ -397,7 +404,7 @@
int currentTestMetricCnt = existingNodes.length;
//insert a new TestMetric into the document
//create it
- SetPropertiesRequest tmpRequest =
+ PropertiesList tmpRequest =
testImpl.createNewSetPropertiesRequest();
double tstMetVal = 3.4;
String[] total = {""+tstMetVal};
@@ -429,7 +436,7 @@
public void testDeleteProperty() throws FaultException,
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException{
//create the setProperties request document
- SetPropertiesRequest tmpRequest = null;
+ PropertiesList tmpRequest = null;
XmlObject[] resourceProps = null;
double newValue = -1;
// DELETE: BEGIN
@@ -449,18 +456,68 @@
// DELETE: END
}
- public void testResourceLifetime() throws FaultException,
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException{
+ public void AtestResourceLifetimeImmediateDestroy() throws FaultException,
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException{
//Test immediate destroy capability
//make simple call to ensure that resource does exist
+ String
propValue=String.valueOf(testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE));
+ assertNotNull(propValue);
+ assertTrue(propValue.length()>0);
+
//call for immediate destroy on it
- //testImpl.destroyResourceImmediately();
+ testImpl.destroyResourceImmediately();
//check to see whether destroy worked
- //now create a new resource and then set scheduled death
- //wait for time to pass ..
- //verify that it's dead.
-
+ try{
+
propValue=String.valueOf(testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE));
+ fail("Resource was not successfully destroyed!");
+ }catch(FaultException exc){
+ }
}
+ public void testResourceLifetimeScheduledDestroy() throws
URISyntaxException, IOException, XmlException,
UnexpectedServerResponseException, FaultException{
+ //Before scheduling destruction .. test out CurrentTime and
TerminationTime resource props
+ //query current time
+ String currentTime =
testImpl.getCurrentTimeAsString(TestResourcePropertyQNames.CURRENTTIME2);
+ assertNotNull(currentTime);
+ assertTrue("Current time not
returned!",(currentTime.trim().length()>0));
+ //query TerminationTime to see that it is not set yet.
+ String terminationTime =
testImpl.getTerminationTimeAsString(TestResourcePropertyQNames.TERMINATIONTIME);
+ assertNull(terminationTime);
+
+ //Build timed death request and send it
+ XmlDateTime curTime =
testImpl.getCurrentTime(TestResourcePropertyQNames.CURRENTTIME2);
+ long secondsFromNow = 20;
+ //set Time of Death
+ long current = curTime.getCalendarValue().getTimeInMillis();
+
curTime.getCalendarValue().setTimeInMillis(current+(secondsFromNow*1000));
+ //build new XmlDateTime to schedule TOD
+ XmlDateTime tod = XmlDateTime.Factory.newInstance();
+ Calendar instance = Calendar.getInstance();
+ instance.setTimeInMillis(current+(secondsFromNow*1000));
+ tod.setCalendarValue(instance);
+
+ //issue the Scheduled death request
+ XmlObject[] response = testImpl.setTerminationTime(tod);
+
+ //check that normal requests still work
+
testImpl.getCurrentTimeAsString(TestResourcePropertyQNames.CURRENTTIME2);
+
+ //wait for time to pass ..
+ Thread unit_test_thread=Thread.currentThread();
+ synchronized (unit_test_thread) {
+ try {
+ //Set sufficient time for destroy to
occur. Add 1 minute buffer
+
unit_test_thread.wait((secondsFromNow+60)*1000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ // verify that it's dead.
+ try{
+
testImpl.getCurrentTimeAsString(TestResourcePropertyQNames.CURRENTTIME2);
+ fail("Resource was not successfully destroyed after set
time!");
+ }catch(FaultException fex){
+ }
+ }
// TODO Calling Operations on Resources
// TODO Next try the create and destroys.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]