You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by wi...@apache.org on 2005/08/30 15:26:44 UTC

svn commit: r264777 - in /webservices/muse/trunk/src/examples/client/src/java: ./ org/apache/ws/client/muse/client/impl/ org/apache/ws/client/muse/client/impl/exceptions/ org/apache/ws/client/muse/client/impl/stubs/

Author: wire
Date: Tue Aug 30 06:26:39 2005
New Revision: 264777

URL: http://svn.apache.org/viewcvs?rev=264777&view=rev
Log:
First Redesigned Implementations of Client (new)

Added:
    webservices/muse/trunk/src/examples/client/src/java/log4j.properties
    webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
    webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/
    webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/UnexpectedServerResponseException.java
    webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/FaultException.java
    webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ResourceStub.java
    webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ServiceStub.java

Added: webservices/muse/trunk/src/examples/client/src/java/log4j.properties
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/log4j.properties?rev=264777&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/log4j.properties (added)
+++ webservices/muse/trunk/src/examples/client/src/java/log4j.properties Tue Aug 30 06:26:39 2005
@@ -0,0 +1,92 @@
+
+#------------------------------------#
+#  Syntax for log-level definitions  #
+#------------------------------------#
+#
+#    log4j.<logger_name>=<priority_level>, <appender_name> [,<appender_name>...]
+#
+#       -or-
+#
+#    log4j.<logger_name>=INHERITED
+#
+# NOTE: Appenders are defined at the end of this configuration file.
+#
+#-------------------------------------------------------------------------------#
+#  Root logger's log-level (affects all classes within the JVM that use Log4J)  #
+#-------------------------------------------------------------------------------#
+#
+log4j.rootCategory=DEBUG, STDOUT
+log4j.additivity.rootCategory=false
+
+#--------------------------------------------------#
+#  Log-levels for specific Java packages           #
+#  Syntax: log4j.category.<full_package_name>=...  #
+#--------------------------------------------------#
+#
+#  Log-levels for Project
+#
+log4j.category.org.apache.ws=DEBUG
+
+#
+#  Log-levels for Apache packages...
+#
+log4j.category.org.apache=WARN
+org.apache.commons.i18n=INFO
+log4j.category.org.apache.axis=INFO
+log4j.category.org.apache.axis.transport.http.SimpleAxisServer=DEBUG
+log4j.category.org.apache.axis.wsdl.toJava.JavaGeneratorFactory=WARN
+
+#-------------------------------------------#
+#  Log appenders and their output patterns  #
+#-------------------------------------------#
+# STDOUT_MSG_ONLY - a console appender that prints the message itself and nothing else
+#
+log4j.appender.STDOUT_MSG_ONLY=org.apache.log4j.ConsoleAppender
+log4j.appender.STDOUT_MSG_ONLY.layout=org.apache.log4j.PatternLayout
+log4j.appender.STDOUT_MSG_ONLY.layout.ConversionPattern=%m%n
+
+#
+# STDOUT_TERSE - a terse console appender
+#
+log4j.appender.STDOUT_TERSE=org.apache.log4j.ConsoleAppender
+log4j.appender.STDOUT_TERSE.layout=org.apache.log4j.PatternLayout
+log4j.appender.STDOUT_TERSE.layout.ConversionPattern=* %5p %c{1}: %m%n
+
+# STDOUT - a console appender with average verbosity 
+#
+log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
+log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
+log4j.appender.STDOUT.layout.ConversionPattern=--> %d{MM-dd-yy HH:mm:ss} %5p [%t] %c{1}: %m%n
+
+# STDOUT_VERBOSE - a verbose console appender; WARNING: this will slow things down considerably!
+#
+log4j.appender.STDOUT_VERBOSE=org.apache.log4j.ConsoleAppender
+log4j.appender.STDOUT_VERBOSE.layout=org.apache.log4j.PatternLayout
+log4j.appender.STDOUT_VERBOSE.layout.ConversionPattern=--> %d{yyyy-MMM-dd HH:mm:ss.SSS} %5p [%t] %c.%M(%F:%L): %m%n
+
+# ROLL_FILE_TERSE - rolling file appender that writes the logs to the file system using terse messages
+#
+log4j.appender.ROLL_FILE_TERSE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLL_FILE_TERSE.File=%SBA_HOME%/sba-log.txt
+log4j.appender.ROLL_FILE_TERSE.MaxFileSize=512KB
+log4j.appender.ROLL_FILE_TERSE.MaxBackupIndex=1
+log4j.appender.ROLL_FILE_TERSE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLL_FILE_TERSE.layout.ConversionPattern=*|%5p|%c{1}|%m%n
+
+# ROLL_FILE - rolling file appender that writes the logs to the file system with average verbosity
+#
+log4j.appender.ROLL_FILE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLL_FILE.File=%SBA_HOME%/sba-log.txt
+log4j.appender.ROLL_FILE.MaxFileSize=512KB
+log4j.appender.ROLL_FILE.MaxBackupIndex=1
+log4j.appender.ROLL_FILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLL_FILE.layout.ConversionPattern=-->|%d{yyyyMMdd|HH:mm:ss}|%p|%t|%c{1}|%m%n
+
+# ROLL_FILE_VERBOSE - rolling file appender that writes verbose messages the logs to the file system; WARNING this is slow!
+#
+log4j.appender.ROLL_FILE_VERBOSE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLL_FILE_VERBOSE.File=%SBA_HOME%/sba-log.txt
+log4j.appender.ROLL_FILE_VERBOSE.MaxFileSize=512KB
+log4j.appender.ROLL_FILE_VERBOSE.MaxBackupIndex=1
+log4j.appender.ROLL_FILE_VERBOSE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLL_FILE_VERBOSE.layout.ConversionPattern=-->|%d{yyyyMMMdd|HH:mm:ss.SSS}|%5p|%t|%c|%M(%F:%L)|%m%n

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java?rev=264777&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java Tue Aug 30 06:26:39 2005
@@ -0,0 +1,145 @@
+/*=============================================================================*
+ *  Copyright 2004 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.client.muse.client.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.addressing.EndpointReference;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.ws.client.muse.client.impl.stubs.FaultException;
+import org.apache.ws.client.muse.client.impl.stubs.ResourceStub;
+import org.apache.ws.client.muse.client.impl.stubs.ServiceStub;
+import org.apache.ws.muws.v1_0.capability.IdentityCapability;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.impl.values.XmlAnyUriImpl;
+import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
+
+public class ManageableResourceImpl {
+
+	private EndpointReference epr;
+
+	private ResourceStub rs;
+
+	private ServiceStub ss;
+
+	private static Log LOG = LogFactory.getLog(ManageableResourceImpl.class);;
+
+	/**
+	 * Creates a ManageableResource from a class that implements
+	 * EndpointReference.
+	 * 
+	 * @param epr
+	 * @throws MalformedURLException
+	 */
+	public ManageableResourceImpl(EndpointReference epr)
+			throws MalformedURLException {
+		super();
+		this.epr = epr;
+		this.rs = new ResourceStub(epr);
+		this.ss = new ServiceStub(new URL(epr.getAddress()));
+	}
+
+	/**
+	 * Creates a MangeableResource from an EPR persisted to a URL.
+	 * 
+	 * @param url
+	 * @throws MalformedURLException
+	 * @throws XmlException
+	 * @throws IOException
+	 */
+	public ManageableResourceImpl(URL url) throws MalformedURLException,
+			XmlException, IOException {
+		this(getEprFromUrl(url));
+	}
+
+	/**
+	 * Creates a MangeableResource from an Sting based text.
+	 * 
+	 * @param url
+	 * @throws MalformedURLException
+	 * @throws XmlException
+	 * @throws IOException
+	 */
+	public ManageableResourceImpl(String txt) throws MalformedURLException,
+			XmlException, IOException {
+		this(getEprFromXmlText(txt));
+	}
+
+	/**
+	 * Returns the Identity of this Manageable Resource
+	 * 
+	 * @return a String representing this resource.
+	 * @throws FaultException
+	 * @throws UnexpectedServerResponseException
+	 * @throws XmlException
+	 * @throws IOException
+	 * @throws URISyntaxException
+	 */
+	public String getId() throws FaultException,
+			UnexpectedServerResponseException, URISyntaxException, IOException,
+			XmlException {
+//		TODO Needs a more informative message
+		LOG.debug("Calling getId for " + this.epr.getAddress()); 
+		XmlObject[] parts = rs
+				.getResourceProperty(IdentityCapability.PROP_NAME_RESOURCE_ID);
+		for (int i = 0; i < parts.length; i++) {
+			XmlObject xmlObject = parts[i];
+			if (xmlObject instanceof XmlAnyUriImpl) {
+				XmlAnyUriImpl childElement = (XmlAnyUriImpl) xmlObject;
+				String value = childElement.getStringValue();
+
+				// Remove any namespace contained in the id.
+				if (value.indexOf(':') > -1) {
+					return value.split(":")[1];
+				}
+				return value;
+			}
+		}
+		throw new UnexpectedServerResponseException(
+				"Server returned either an unrecognizable response or no response at all");
+	}
+
+	public EndpointReference getEpr() {
+		return epr;
+	}
+
+	public static EndpointReference getEprFromUrl(URL url) throws XmlException,
+			IOException {
+		LOG.debug("Connecting to URL for EPR: " + url.toString());
+		EndpointReferenceDocument eprd = (EndpointReferenceDocument) XmlObject.Factory
+				.parse(url);
+		return new XmlBeansEndpointReference(eprd.getEndpointReference());
+	}
+
+	public static EndpointReference getEprFromXmlText(String txt)
+			throws XmlException, IOException {
+		LOG.debug("Parsing text for EPR: " + txt);
+		ByteArrayInputStream stream = new ByteArrayInputStream(txt.getBytes());
+		EndpointReferenceDocument eprd = (EndpointReferenceDocument) XmlObject.Factory
+				.parse(stream);
+		return new XmlBeansEndpointReference(eprd.getEndpointReference());
+	}
+
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/UnexpectedServerResponseException.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/UnexpectedServerResponseException.java?rev=264777&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/UnexpectedServerResponseException.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/UnexpectedServerResponseException.java Tue Aug 30 06:26:39 2005
@@ -0,0 +1,25 @@
+package org.apache.ws.client.muse.client.impl.exceptions;
+
+public class UnexpectedServerResponseException extends Exception {
+
+	public UnexpectedServerResponseException() {
+		super();
+		// TODO Auto-generated constructor stub
+	}
+
+	public UnexpectedServerResponseException(String message) {
+		super(message);
+		// TODO Auto-generated constructor stub
+	}
+
+	public UnexpectedServerResponseException(String message, Throwable cause) {
+		super(message, cause);
+		// TODO Auto-generated constructor stub
+	}
+
+	public UnexpectedServerResponseException(Throwable cause) {
+		super(cause);
+		// TODO Auto-generated constructor stub
+	}
+
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/FaultException.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/FaultException.java?rev=264777&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/FaultException.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/FaultException.java Tue Aug 30 06:26:39 2005
@@ -0,0 +1,27 @@
+/*=============================================================================*
+ *  Copyright 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.client.muse.client.impl.stubs;
+
+public class FaultException extends Exception
+{
+
+    public FaultException( String message )
+    {
+        super( message );
+    }
+
+}
+

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ResourceStub.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ResourceStub.java?rev=264777&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ResourceStub.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ResourceStub.java Tue Aug 30 06:26:39 2005
@@ -0,0 +1,284 @@
+/*=============================================================================*
+ *  Copyright 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.client.muse.client.impl.stubs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Calendar;
+import java.util.Observable;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.message.addressing.Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.XmlObjectWrapper;
+import org.apache.ws.addressing.EndpointReference;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.ws.notification.topics.v2004_06.TopicsConstants;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.ws.util.soap.SoapClient;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeResponseDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.DestroyDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceLifetime12Draft01.impl.DestroyResponseDocumentImpl;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyResponseDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesResponseDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateType;
+import org.xmlsoap.schemas.soap.envelope.Envelope;
+import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
+import org.xmlsoap.schemas.soap.envelope.Header;
+
+/**
+ * A stub for a WSDM Resource.
+ */
+public class ResourceStub extends Observable
+{
+	private static Log LOG=LogFactory.getLog(ResourceStub.class);
+
+
+	static final boolean DEBUG = false;//Boolean.getBoolean( "debug" );
+
+    private EndpointReference m_epr;
+    private EndpointReference m_epr2003;
+    private EndpointReference m_epr2004;
+
+    public static boolean USE_WRAPPED_NOTIFICATIONS = Boolean.valueOf(System.getProperty("wrapped_notifications", "true")).booleanValue();
+
+    public ResourceStub( EndpointReference epr )
+    {
+       XmlBeansEndpointReference xBeansEpr=(XmlBeansEndpointReference)epr;
+       m_epr = epr;
+       XmlObject eprXBean = ((XmlObjectWrapper)m_epr).getXmlObject();
+       if ( eprXBean.schemaType().getName().getNamespaceURI().equals( Constants.NS_URI_ADDRESSING_2003_03 ) )
+       {
+    	   m_epr2003=m_epr;
+    	   m_epr2004=new XmlBeansEndpointReference((org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType)xBeansEpr.getXmlObject(org.apache.ws.addressing.v2004_08_10.AddressingConstants.NSURI_ADDRESSING_SCHEMA));
+    	   
+       } else {
+    	   m_epr2004=m_epr;
+    	   m_epr2003=new XmlBeansEndpointReference((org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType)xBeansEpr.getXmlObject(org.apache.ws.addressing.v2003_03.AddressingConstants.NSURI_ADDRESSING_SCHEMA));    	   
+       }
+    }
+
+    public XmlObject[] getResourceProperty( QName propName ) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException
+    {
+        GetResourcePropertyDocument requestDoc = GetResourcePropertyDocument.Factory.newInstance();
+       
+        requestDoc.setGetResourceProperty( propName );
+        XmlObject response = sendRequest( requestDoc, "http://xyz.com/action/GetResourceProperty","P" );
+        if ( ! ( response instanceof GetResourcePropertyResponseDocument.GetResourcePropertyResponse ) )
+        {
+            throw new FaultException( response.toString() );
+        }
+        return XmlBeanUtils.getChildElements( response );
+    }
+
+    public void updateResourceProperty( XmlObject[] propElems ) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException
+    {
+        SetResourcePropertiesDocument requestDoc = SetResourcePropertiesDocument.Factory.newInstance();
+        SetResourcePropertiesDocument.SetResourceProperties setResourceProperties = requestDoc.addNewSetResourceProperties();
+        UpdateType updateType = setResourceProperties.addNewUpdate();
+        for ( int i = 0; i < propElems.length; i++ )
+        {
+            XmlBeanUtils.addChildElement( updateType, propElems[i] );
+        }
+        XmlObject response = sendRequest( requestDoc, "http://xyz.com/action/SetResourceProperties","U" );
+        if ( ! ( response instanceof SetResourcePropertiesResponseDocument.SetResourcePropertiesResponse ) )
+        {
+            throw new FaultException( response.toString() );
+        }
+    }
+
+    public EndpointReference subscribe( String consumerURL, QName topic,long duration ) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException
+    {
+        SubscribeDocument requestDoc = SubscribeDocument.Factory.newInstance();
+        SubscribeDocument.Subscribe subscribe = requestDoc.addNewSubscribe();
+        subscribe.setUseNotify(USE_WRAPPED_NOTIFICATIONS);
+        Calendar instance = Calendar.getInstance();
+        instance.setTimeInMillis(instance.getTimeInMillis() + duration);
+        subscribe.setInitialTerminationTime( instance );
+        org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType consumerRef = subscribe.addNewConsumerReference();
+        org.xmlsoap.schemas.ws.x2003.x03.addressing.AttributedURI address = consumerRef.addNewAddress();
+        address.setStringValue( consumerURL );
+        TopicExpressionType topicExpr = subscribe.addNewTopicExpression();
+        topicExpr.setDialect( TopicsConstants.TOPIC_EXPR_DIALECT_SIMPLE );
+        XmlBeanUtils.setValueAsQName( topicExpr, topic );
+        XmlObject response = sendRequest( requestDoc, "http://xyz.com/action/Subscribe","S" );
+        if ( ! ( response instanceof SubscribeResponseDocument.SubscribeResponse ) )
+        {
+            throw new FaultException( response.toString() );
+        }
+        SubscribeResponseDocument.SubscribeResponse subscribeResponse = (SubscribeResponseDocument.SubscribeResponse) response;
+        return new XmlBeansEndpointReference( subscribeResponse.getSubscriptionReference() );
+    	
+    }
+
+    public void destroySubscription( ) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException
+    {
+    	DestroyDocument requestDoc = DestroyDocument.Factory.newInstance();
+    	requestDoc.addNewDestroy(); 
+        XmlObject response = sendRequest( requestDoc, "http://xyz.com/action/Destroy","D" );
+        if ( ! ( response instanceof DestroyResponseDocumentImpl.DestroyResponseImpl) )
+        {
+            throw new FaultException( response.toString() );
+        }    	
+    }
+
+    public EndpointReference subscribe( String consumerURL, QName topic ) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException
+    {
+    		return subscribe( consumerURL, topic,7200000);    
+    }
+
+    private EnvelopeDocument createEnvelope()
+    {
+        EnvelopeDocument envelopeDoc = EnvelopeDocument.Factory.newInstance();
+        Envelope envelope = envelopeDoc.addNewEnvelope();
+        envelope.addNewHeader();
+        envelope.addNewBody();
+        return envelopeDoc;
+    }
+
+    public XmlObject sendRequest( XmlObject requestDoc, String action ,String type ) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException
+    {
+    	// Hack for internal network
+    	String addr=m_epr.getAddress();
+    	//addr=addr.replaceAll("192\\.168\\.0\\.20","12.35.246.160");
+
+    	EnvelopeDocument requestEnvelopeDoc = createEnvelope();
+        Envelope requestEnvelope = requestEnvelopeDoc.getEnvelope();
+        addAddressingHeaders( requestEnvelope.getHeader(), action );
+        XmlBeanUtils.addChildElement( requestEnvelope.getBody(), requestDoc );
+            URL endpointURL = new URL( addr );//m_epr.getAddress()
+            URI actionURI = new URI( action );
+            LOG.debug( "Sending request: ---------------------------- \n" + requestEnvelopeDoc ); 
+            String response = SoapClient.sendRequest( endpointURL, requestEnvelopeDoc.newInputStream(), actionURI );            
+            LOG.debug( "---------------------------------------- "); 
+            setChanged();
+            XmlOptions xmlOpts = new XmlOptions().setSaveOuter();
+            xmlOpts.setSavePrettyPrint();
+            
+    		//notifyObservers(new WcmMessage("<?xml version=\"1.0\" encoding=\"UTF8\" ?>"+requestEnvelopeDoc.xmlText(xmlOpts), response,type));            
+            EnvelopeDocument responseEnvelopeDoc = (EnvelopeDocument) XmlObject.Factory.parse( response );
+            LOG.debug( "Received response: -------------------------- \n" + responseEnvelopeDoc ); 
+            LOG.debug( "---------------------------------------- "); 
+            Envelope responseEnvelope = responseEnvelopeDoc.getEnvelope();
+            XmlObject[] responseBodyElems = XmlBeanUtils.getChildElements( responseEnvelope.getBody() );
+            if ( responseBodyElems.length == 0 )
+            {
+                throw new UnexpectedServerResponseException();
+            }
+            else
+            {
+                return responseBodyElems[0];
+            }
+    }
+
+    /**
+     * All resource proerpties request must you 2003 addressing
+     * @param header
+     * @param action
+     */
+    private void addAddressingHeaders( Header header, String action )
+    {
+        XmlObject eprXBean = ((XmlObjectWrapper)m_epr).getXmlObject();
+        XmlObject toElem;
+        XmlObject actionElem;
+        if ( eprXBean.schemaType().getName().getNamespaceURI().equals( Constants.NS_URI_ADDRESSING_2003_03 ) )
+        {
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.ToDocument toDoc = org.xmlsoap.schemas.ws.x2003.x03.addressing.ToDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.AttributedURI attributedURI = toDoc.addNewTo();
+            attributedURI.setStringValue(m_epr.getAddress());
+            toElem = toDoc;
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.ActionDocument actionDoc = org.xmlsoap.schemas.ws.x2003.x03.addressing.ActionDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.AttributedURI actionType = actionDoc.addNewAction();
+            actionType.setStringValue( action );
+            actionElem = actionDoc;
+        }
+        else
+        {
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument toDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI attributedURI = toDoc.addNewTo();
+            attributedURI.setStringValue(m_epr.getAddress());
+            toElem = toDoc;
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument actionDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI actionType = actionDoc.addNewAction();
+            actionType.setStringValue( action );
+            actionElem = actionDoc;
+        }
+        
+        
+        XmlBeanUtils.addChildElement( header, toElem );
+        XmlBeanUtils.addChildElement( header, actionElem );
+        if (m_epr.getReferenceProperties() != null)
+        {
+            XmlObject[] refPropElems = (XmlObject[]) m_epr.getReferenceProperties();
+            for (int i = 0; i < refPropElems.length; i++)
+            {
+                XmlBeanUtils.addChildElement(header, refPropElems[i]);
+            }
+        }
+    }
+
+    private void addAddressingHeadersOld( Header header, String action )
+    {
+        XmlObject eprXBean = ((XmlObjectWrapper)m_epr).getXmlObject();
+        XmlObject toElem;
+        XmlObject actionElem;
+        if ( eprXBean.schemaType().getName().getNamespaceURI().equals( Constants.NS_URI_ADDRESSING_2003_03 ) )
+        {
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.ToDocument toDoc = org.xmlsoap.schemas.ws.x2003.x03.addressing.ToDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.AttributedURI attributedURI = toDoc.addNewTo();
+            attributedURI.setStringValue(m_epr.getAddress());
+            toElem = toDoc;
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.ActionDocument actionDoc = org.xmlsoap.schemas.ws.x2003.x03.addressing.ActionDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.AttributedURI actionType = actionDoc.addNewAction();
+            actionType.setStringValue( action );
+            actionElem = actionDoc;
+        }
+        else
+        {
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument toDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI attributedURI = toDoc.addNewTo();
+            attributedURI.setStringValue(m_epr.getAddress());
+            toElem = toDoc;
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument actionDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI actionType = actionDoc.addNewAction();
+            actionType.setStringValue( action );
+            actionElem = actionDoc;
+        }
+        XmlBeanUtils.addChildElement( header, toElem );
+        XmlBeanUtils.addChildElement( header, actionElem );
+        if (m_epr.getReferenceProperties() != null)
+        {
+            XmlObject[] refPropElems = (XmlObject[]) m_epr.getReferenceProperties();
+            for (int i = 0; i < refPropElems.length; i++)
+            {
+                XmlBeanUtils.addChildElement(header, refPropElems[i]);
+            }
+        }
+    }
+
+}

Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ServiceStub.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ServiceStub.java?rev=264777&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ServiceStub.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ServiceStub.java Tue Aug 30 06:26:39 2005
@@ -0,0 +1,154 @@
+/*=============================================================================*
+ *  Copyright 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.client.muse.client.impl.stubs;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.ws.util.soap.SoapClient;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.oasisOpen.docs.wsdm.x2004.x12.mows.wsdmMows.GetManageabilityReferencesDocument;
+import org.oasisOpen.docs.wsdm.x2004.x12.mows.wsdmMows.GetManageabilityReferencesResponseDocument;
+import org.xmlsoap.schemas.soap.envelope.Envelope;
+import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
+import org.xmlsoap.schemas.soap.envelope.Header;
+import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
+
+import javax.xml.namespace.QName;
+import java.net.URI;
+import java.net.URL;
+import java.util.Observable;
+
+/**
+ * TODO
+ */
+public class ServiceStub extends Observable
+{
+	static Logger LOG = Logger.getLogger(ServiceStub.class.toString());
+    protected URL m_url;
+
+    public ServiceStub( URL url )
+    {
+        m_url = url;
+    }
+
+    protected EndpointReferenceType[] getManageabilityReferences() throws FaultException
+    {
+        GetManageabilityReferencesDocument requestDoc = GetManageabilityReferencesDocument.Factory.newInstance();
+        requestDoc.addNewGetManageabilityReferences();
+        XmlObject response = sendRequest( requestDoc, "http://xyz.com/action/GetManageabilityReferences", m_url);
+        if ( ! ( response instanceof GetManageabilityReferencesResponseDocument.GetManageabilityReferencesResponse ) )
+        {
+            throw new FaultException( response.toString() );
+        }
+        return ((GetManageabilityReferencesResponseDocument.GetManageabilityReferencesResponse)response).getManageabilityEndpointReferenceArray();
+    }
+
+
+
+    protected EnvelopeDocument createEnvelope()
+    {
+        EnvelopeDocument envelopeDoc = EnvelopeDocument.Factory.newInstance();
+        Envelope envelope = envelopeDoc.addNewEnvelope();
+        envelope.addNewHeader();
+        envelope.addNewBody();
+        return envelopeDoc;
+    }
+
+    public XmlObject sendRequest(XmlObject requestDoc, String action, URL url)
+    {
+        EnvelopeDocument requestEnvelopeDoc = createEnvelope();
+        Envelope requestEnvelope = requestEnvelopeDoc.getEnvelope();
+        XmlBeanUtils.addChildElement( requestEnvelope.getBody(), requestDoc );
+        try
+        {
+            URI actionURI = new URI( action );
+            LOG.log(Level.DEBUG,  "Sending request: \n" + requestEnvelopeDoc );
+            
+            
+            setChanged();
+            String response = SoapClient.sendRequest( url, requestEnvelopeDoc.newInputStream(), actionURI );
+            XmlOptions xmlOpts = new XmlOptions().setSaveOuter();
+            xmlOpts.setSavePrettyPrint();            
+            EnvelopeDocument responseEnvelopeDoc = (EnvelopeDocument) XmlObject.Factory.parse( response );
+//    		notifyObservers(new WcmMessage(requestDoc.xmlText(xmlOpts), responseEnvelopeDoc.xmlText(xmlOpts)));
+
+    		LOG.log(Level.DEBUG, "Received response: \n" + responseEnvelopeDoc ); 
+            Envelope responseEnvelope = responseEnvelopeDoc.getEnvelope();
+            XmlObject[] responseBodyElems = XmlBeanUtils.getChildElements( responseEnvelope.getBody() );
+            if ( responseBodyElems.length == 0 )
+            {
+                return null;
+            }
+            else
+            {
+                return responseBodyElems[0];
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+    protected XmlObject sendRequest(EnvelopeDocument requestEnvelope, String action, URL url)
+    {
+
+        try
+        {
+            URI actionURI = new URI( action );
+            LOG.log(Level.DEBUG, "Sending request: \n" + requestEnvelope ); 
+            String response = SoapClient.sendRequest( url, requestEnvelope.newInputStream(), actionURI );
+            EnvelopeDocument responseEnvelopeDoc = (EnvelopeDocument) XmlObject.Factory.parse( response );
+            LOG.log(Level.DEBUG,  "Received response: \n" + responseEnvelopeDoc ); 
+            Envelope responseEnvelope = responseEnvelopeDoc.getEnvelope();
+            XmlObject[] responseBodyElems = XmlBeanUtils.getChildElements( responseEnvelope.getBody() );
+            if ( responseBodyElems.length == 0 )
+            {
+                return null;
+            }
+            else
+            {
+                return responseBodyElems[0];
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+    protected void addAddressingHeader(Header header, String action, String address, QName keyHeaderName, String weatherstationKey1)
+    {
+        XmlObject toElem;
+        XmlObject actionElem;
+        org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument toDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument.Factory.newInstance();
+        org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI attributedURI = toDoc.addNewTo();
+        attributedURI.setStringValue(address);
+        toElem = toDoc;
+        org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument actionDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument.Factory.newInstance();
+        org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI actionType = actionDoc.addNewAction();
+        actionType.setStringValue(action);
+        actionElem = actionDoc;
+
+        XmlBeanUtils.addChildElement(header, toElem);
+        XmlBeanUtils.addChildElement(header, actionElem);
+
+
+        XmlObject resourceKeyHeader = XmlBeanUtils.addChildElement(header, keyHeaderName);
+        XmlBeanUtils.setValue(resourceKeyHeader, weatherstationKey1);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org