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 wi...@apache.org on 2005/09/19 17:17:03 UTC
svn commit: r290182 - in
/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client:
./ impl/ impl/exceptions/ impl/notification/ impl/stubs/
Author: wire
Date: Mon Sep 19 08:16:51 2005
New Revision: 290182
URL: http://svn.apache.org/viewcvs?rev=290182&view=rev
Log:
Refactoring for support of creation factories and additional classes have been added for notification support.
Added:
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/ManageableResource.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/NotificationConsumer.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/FaultException.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/HttpHeader.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationConsumerImpl.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationImpl.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotifyableResourceImpl.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/QueryImpl.java
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/TopicExpressionImpl.java
Removed:
webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/FaultException.java
Modified:
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/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/org/apache/ws/client/muse/client/ManageableResource.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/ManageableResource.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/ManageableResource.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/ManageableResource.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,175 @@
+package org.apache.ws.client.muse.client;
+
+import java.io.IOException;
+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.addressing.EndpointReference;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+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.impl.notification.NotificationImpl;
+import org.apache.ws.client.muse.client.impl.notification.NotifyableResourceImpl;
+import org.apache.ws.client.muse.client.impl.notification.QueryImpl;
+import org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+
+public interface ManageableResource {
+
+ public static final String MUSE_RESOURCE_VERSION_1_0="MUSE_RESOURCE_VERSION_1_0";
+
+ /***************************** Factories **************************/
+
+ static class Factory {
+ public static ManageableResource create(String version,EndpointReference epr) throws MalformedURLException {
+ if(version==null)
+ version=MUSE_RESOURCE_VERSION_1_0;
+ return new NotifyableResourceImpl(epr);
+ }
+ public static ManageableResource create(String version,URL url) throws MalformedURLException,XmlException, IOException {
+ if(version==null)
+ version=MUSE_RESOURCE_VERSION_1_0;
+ return new NotifyableResourceImpl(url);
+ }
+
+ public static ManageableResource create(String version,String txt) throws MalformedURLException, XmlException, IOException {
+ if(version==null)
+ version=MUSE_RESOURCE_VERSION_1_0;
+ return new NotifyableResourceImpl(txt);
+ }
+ }
+
+ /***************************** Resource Properties **************************/
+
+ /**
+ * Returns the Identity of this Manageable Resource
+ *
+ * @return a String representing this resource.
+ * @throws FaultException
+ * @throws UnexpectedServerResponseException
+ * @throws XmlException
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public abstract String getId() throws FaultException,
+ UnexpectedServerResponseException, URISyntaxException, IOException,
+ XmlException;
+
+ public abstract String getPropertyAsString(QName propertyName)
+ throws FaultException, URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException;
+
+ public abstract EndpointReference getEpr();
+
+ /* Returns a specific property value as a double.
+ *
+ */
+ public abstract double getPropertyAsDouble(QName propertyName)
+ throws FaultException, URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException;
+
+ /*
+ * Returns a specific property value as an integer.
+ */
+ public abstract int getPropertyAsInt(QName propertyName)
+ throws FaultException, URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException;
+
+ /*
+ * Returns a specific property value as a bolean.
+ */
+ public abstract boolean getPropertyAsBoolean(QName propertyName)
+ throws FaultException, URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException;
+
+ /* Returns a specific property value as a untyped property as XMLObject[]. For clients
+ * preferring to parse pure XML.
+ *
+ */
+ public abstract XmlObject[] getProperty(QName propertyName)
+ throws FaultException, URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException;
+
+ /**
+ * Returns a list of QNames of valid wsrf properties for this resource.
+ * <b>Note:</b> this operation may not be supported by this resource.
+ * A resource must implement QueryResourceProperties for this method to work.
+ * @return
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws XmlException
+ * @throws UnexpectedServerResponseException
+ */
+ public abstract QName[] getPropertyQNames() throws URISyntaxException,
+ IOException, XmlException, UnexpectedServerResponseException;
+
+
+ public abstract XmlObject[] getMultipleResourceProperties(
+ QName[] requestedValues) throws URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException;
+
+ /***************************** Notifications **************************/
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#getTopics()
+ */
+ public abstract TopicExpressionImpl[] getTopics() throws FaultException,
+ URISyntaxException, IOException, XmlException,
+ UnexpectedServerResponseException;
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#isFixedTopicSet()
+ */
+ public abstract boolean isFixedTopicSet() throws FaultException,
+ URISyntaxException, IOException, XmlException,
+ UnexpectedServerResponseException;
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#getTopicExpressionDialects()
+ */
+ public abstract String[] getTopicExpressionDialects()
+ throws FaultException, URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException;
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl, org.apache.ws.addressing.XmlBeansEndpointReference)
+ */
+ public abstract ManageableResource subscribe(TopicExpressionImpl topic,
+ XmlBeansEndpointReference consumerReference)
+ throws URISyntaxException, IOException, XmlException,
+ UnexpectedServerResponseException;
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl, org.apache.ws.addressing.XmlBeansEndpointReference, java.util.Calendar, boolean)
+ */
+ public abstract ManageableResource subscribe(TopicExpressionImpl topic,
+ XmlBeansEndpointReference consumerReference,
+ Calendar terminationTime, boolean notify)
+ throws URISyntaxException, IOException, XmlException,
+ UnexpectedServerResponseException;
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl[], org.apache.ws.addressing.XmlBeansEndpointReference, java.util.Calendar, boolean, org.apache.ws.client.muse.client.impl.notification.QueryImpl, org.apache.ws.client.muse.client.impl.notification.QueryImpl, org.apache.xmlbeans.XmlObject)
+ */
+ public abstract ManageableResource subscribe(
+ TopicExpressionImpl[] topics,
+ XmlBeansEndpointReference consumerReference,
+ Calendar terminationTime, boolean useNotify,
+ QueryImpl precondition, QueryImpl selector, XmlObject policy)
+ throws URISyntaxException, IOException, XmlException,
+ UnexpectedServerResponseException;
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#getCurrentMessage(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl)
+ */
+ public abstract NotificationImpl getCurrentMessage(TopicExpressionImpl topic)
+ throws URISyntaxException, IOException, XmlException,
+ UnexpectedServerResponseException;
+
+
+ }
Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/NotificationConsumer.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/NotificationConsumer.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/NotificationConsumer.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/NotificationConsumer.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,30 @@
+package org.apache.ws.client.muse.client;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.UnknownHostException;
+
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.client.muse.client.impl.notification.NotificationConsumerImpl;
+
+public interface NotificationConsumer {
+ public static final String MUSE_CONSUMER_VERSION_1_0="MUSE_CONSUMER_VERSION_1_0";
+
+ static class Factory {
+ public static NotificationConsumer create(String version,int port, int timeout) throws MalformedURLException {
+ if(version==null)
+ version=MUSE_CONSUMER_VERSION_1_0;
+ return new NotificationConsumerImpl( port, timeout);
+ }
+ }
+
+ public abstract void start() throws IOException;
+
+ public abstract void stop();
+
+ public abstract String getRequestUri();
+
+ public abstract XmlBeansEndpointReference getEndpointReference()
+ throws UnknownHostException;
+
+}
\ No newline at end of file
Modified: 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=290182&r1=290181&r2=290182&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java (original)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/ManageableResourceImpl.java Mon Sep 19 08:16:51 2005
@@ -21,20 +21,17 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.ArrayList;
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;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.client.muse.client.ManageableResource;
+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.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;
@@ -42,6 +39,7 @@
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.impl.values.XmlAnyUriImpl;
+import org.apache.xmlbeans.impl.values.XmlBooleanImpl;
import org.apache.xmlbeans.impl.values.XmlDoubleImpl;
import org.apache.xmlbeans.impl.values.XmlIntImpl;
import org.apache.xmlbeans.impl.values.XmlStringImpl;
@@ -54,13 +52,13 @@
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.impl.GetMultipleResourcePropertiesResponseDocumentImpl;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
-public class ManageableResourceImpl {
+public class ManageableResourceImpl {
- private EndpointReference epr;
+ protected EndpointReference epr;
- private ResourceStub rs;
+ protected ResourceStub rs;
- private ServiceStub ss;
+ protected ServiceStub ss;
private static Log LOG = LogFactory.getLog(ManageableResourceImpl.class);
@@ -78,7 +76,7 @@
this.rs = new ResourceStub(epr);
this.ss = new ServiceStub(new URL(epr.getAddress()));
}
-
+
/**
* Creates a MangeableResource from an EPR persisted to a URL.
*
@@ -105,15 +103,8 @@
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
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getId()
*/
public String getId() throws FaultException,
UnexpectedServerResponseException, URISyntaxException, IOException,
@@ -138,6 +129,9 @@
"Server returned either an unrecognizable response or no response at all");
}
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsString(javax.xml.namespace.QName)
+ */
public String getPropertyAsString(QName propertyName) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
LOG.info("getting property value "+propertyName+" from " + this.epr.getAddress());
XmlObject[] parts = rs.getResourceProperty(propertyName);
@@ -153,6 +147,9 @@
"Server returned either an unrecognizable response or no String type was returned as a response.");
}
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getEpr()
+ */
public EndpointReference getEpr() {
return epr;
}
@@ -177,6 +174,9 @@
/* Returns a specific property value as a double.
*
*/
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsDouble(javax.xml.namespace.QName)
+ */
public double getPropertyAsDouble(QName propertyName) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
LOG.info("getting property value "+propertyName+" from " + this.epr.getAddress());
XmlObject[] parts = rs.getResourceProperty(propertyName);
@@ -195,6 +195,9 @@
/*
* Returns a specific property value as an integer.
*/
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsInt(javax.xml.namespace.QName)
+ */
public int getPropertyAsInt(QName propertyName) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
LOG.info("getting property value "+propertyName+" from " + this.epr.getAddress());
XmlObject[] parts = rs.getResourceProperty(propertyName);
@@ -210,24 +213,41 @@
"Server returned either an unrecognizable response or no String type was returned as a response.");
}
+ /*
+ * Returns a specific property value as a bolean.
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyAsBoolean(javax.xml.namespace.QName)
+ */
+ public boolean getPropertyAsBoolean(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 XmlBooleanImpl) {
+ XmlBooleanImpl childElement = (XmlBooleanImpl) xmlObject;
+ boolean value = childElement.getBooleanValue();
+ return value;
+ }
+ }
+ 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 untyped property as XMLObject[]. For clients
* preferring to parse pure XML.
*
*/
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getProperty(javax.xml.namespace.QName)
+ */
public XmlObject[] getProperty(QName propertyName) throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
LOG.info("getting property value "+propertyName+" from " + this.epr.getAddress());
XmlObject[] parts = rs.getResourceProperty(propertyName);
return parts;
}
- /**
- * Returns a list of QNames of valid wsrf properties for this resource.
- * <b>Note:</b> this operation may not be supported by this resource.
- * A resource must implement QueryResourceProperties for this method to work.
- * @return
- * @throws URISyntaxException
- * @throws IOException
- * @throws XmlException
- * @throws UnexpectedServerResponseException
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getPropertyQNames()
*/
public QName[] getPropertyQNames() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
QueryResourcePropertiesDocument queryDocument = QueryResourcePropertiesDocument.Factory.newInstance();
@@ -257,6 +277,9 @@
return (QName[]) infoList.toArray(new QName[0]);
}
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.ManageableResource#getMultipleResourceProperties(javax.xml.namespace.QName[])
+ */
public XmlObject[] getMultipleResourceProperties(QName[] requestedValues) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException {
//Create MultipleResourceProperties document
Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/FaultException.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/FaultException.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/FaultException.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/exceptions/FaultException.java Mon Sep 19 08:16:51 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.exceptions;
+
+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/notification/HttpHeader.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/HttpHeader.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/HttpHeader.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/HttpHeader.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,132 @@
+package org.apache.ws.client.muse.client.impl.notification;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * HttpHeader
+ *
+ * This class is used to parse a String containing the Http Headers pulled from a Socket.
+ *
+ * <p/>
+ * User: SACAM
+ * Date: Jun 13, 2005
+ */
+public class HttpHeader
+{
+ /**
+ * Internal Map to hold the parsed headers
+ */
+ private Map m_headers = new HashMap();
+
+ /**
+ * Header Constants to be used as a reference for header lookups
+ */
+ public static final String ACCEPT = "Accept";
+ public static final String ACCEPT_CHARSET = "Accept-Charset";
+ public static final String ACCEPT_ENCODING = "Accept-Encoding";
+ public static final String ACCEPT_LANGUAGE = "Accept-Language";
+ public static final String AUTHORIZATION = "Authorization";
+ public static final String CACHE_CONTROL = "Cache-Control";
+ public static final String CONNECTION = "Connection";
+ public static final String CONTENT_LENGTH = "Content-Length";
+ public static final String DATE = "Date";
+ public static final String EXPECT = "Expect";
+ public static final String FROM = "From";
+ public static final String HOST = "Host";
+ public static final String IF_MATCH = "If-Match";
+ public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
+ public static final String IF_NONE_MATCH = "If-None-Match";
+ public static final String IF_RANGE = "If-Range";
+ public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
+ public static final String MAX_FORWARDS = "Max-Forwards";
+ public static final String PRAGMA = "Pragma";
+ public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
+ public static final String RANGE = "Range";
+ public static final String REFERER = "Referer";
+ public static final String TE = "TE";
+ public static final String TRAILER = "Trailer";
+ public static final String TRANSFER_ENCODING = "Transfer-Encoding";
+ public static final String UPGRADE = "Upgrade";
+ public static final String USER_AGENT = "User-Agent";
+ public static final String VIA = "Via";
+ public static final String WARNING = "Warning";
+
+
+ public HttpHeader(String headersString)
+ {
+ parseHeaders(headersString);
+ }
+
+ /**
+ * This method tokenizes and parses the incoming header String
+ *
+ * @param headersString
+ */
+ private void parseHeaders(String headersString)
+ {
+ //System.out.println("Entered headers: " + headersString);
+ //parse the header string into a map
+
+ String[] strings = headersString.split("\n");
+ for (int i = 0; i < strings.length; i++)
+ {
+ String header = strings[i];
+ String[] values = header.split(": ");
+ m_headers.put(values[0].trim().toLowerCase(), values[1].trim());
+ }
+
+ //System.out.println("Parsed Headers: " +toString());//debug only
+ }
+
+ /**
+ * Returns the header given a header name.
+ *
+ * @param headerName The name of the header to be retrieved.
+ * @return The header value
+ */
+ public String getHeader(String headerName)
+ {
+ if (m_headers.containsKey(headerName.toLowerCase()))
+ {
+ return (String) m_headers.get(headerName.toLowerCase());
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Overrideen toString() to dump the parsed headers.
+ *
+ * @return The parsed headers.
+ */
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ Iterator iterator = m_headers.keySet().iterator();
+ while (iterator.hasNext())
+ {
+ String key = (String) iterator.next();
+ sb.append(key + " : " + m_headers.get(key));
+ }
+ return sb.toString();
+ }
+ public static void main(String[] args)
+ {
+ HttpHeader header = new HttpHeader("Content-Type: text/xml; charset=utf-8\n" +
+ " Accept: application/soap+xml, application/dime, multipart/related, text/*\n" +
+ " User-Agent: Axis/1.2\n" +
+ " Host: 192.168.2.120:8001\n" +
+ " Cache-Control: no-cache\n" +
+ " Pragma: no-cache\n" +
+ " SOAPAction: \"\"\n" +
+ " Content-Length: 2950\n");
+ String content_length = header.getHeader(HttpHeader.CONTENT_LENGTH);
+ //int i = Integer.parseInt(content_length);
+ System.out.println(content_length);
+ }
+}
Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationConsumerImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationConsumerImpl.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationConsumerImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationConsumerImpl.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,480 @@
+/*=============================================================================*
+ * 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.notification;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.InterruptedIOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Observable;
+import java.util.TimeZone;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.client.muse.client.NotificationConsumer;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.xmlbeans.XmlException;
+
+/**
+ * Creates a Notification Consumer on a tcp/ip port. Accepts notifications and
+ * will deliver notification messages to all of its observers.
+ *
+ * @author wire
+ *
+ */
+public class NotificationConsumerImpl extends Observable implements Runnable, NotificationConsumer {
+ private static final String NOTIFICATION_CONSUMER_PORT_THREAD_PREFIX = "Notification Consumer = Port ";
+
+ static Logger LOG = Logger.getLogger(NotificationConsumerImpl.class.toString());
+
+ private static final String HTTP_SERVER_NAME = "WS-NotificationConsumer/1.0";
+
+ private static final String HTTP_VERSION = "1.0";
+
+ private static final String HTTP_STATUS = "202 Accepted";
+
+ private boolean closeSocketAfterNotification = true;
+
+ private ServerSocket server;
+
+ private String request;
+
+ int port;
+
+ int timeout;
+
+ final Object listenerStarted = new Object();
+
+ private static final DateFormat HTTP_DATE_FORMAT = new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
+
+ private Thread listenerThread;
+
+ private Thread workerThread;
+
+
+ private BufferedReader bufIn;
+
+ private BufferedOutputStream bufOut;
+
+ private Socket sock;
+
+ public boolean ready = false;
+
+ StringBuffer retIncomingMessage;
+
+ private HttpHeader headerData;
+ static {
+ HTTP_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
+ }
+
+ /**
+ *
+ */
+ public NotificationConsumerImpl(int port, int timeout) {
+ super();
+ this.port = port;
+ this.timeout = timeout;
+ this.retIncomingMessage = new StringBuffer();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotificationConsumer#start()
+ */
+ public void start() throws IOException {
+ startWorking();
+ startListening();
+ }
+
+ /**
+ * Establishing the worker thread that notifies observers when
+ * a new notification has been received.
+ *
+ */
+ private void startWorking() {
+ workerThread = new Thread(this, "ObservercWorkervThread for port "
+ + port);
+ workerThread.start();
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotificationConsumer#stop()
+ */
+ public void stop() {
+ stopListening();
+ stopWorking();
+ }
+
+ private void stopWorking() {
+ // Stop the thread waiting for data
+ workerThread.interrupt();
+
+
+ }
+
+ private void startListening() {
+ // start listening and then return when the thread has officially gone
+ // live and the socket is ready to be accepted
+ retIncomingMessage.setLength(0);
+ ready = false;
+ listenerThread = new Thread(this, NOTIFICATION_CONSUMER_PORT_THREAD_PREFIX
+ + port);
+
+
+ synchronized (listenerStarted) {
+ listenerThread.start();
+
+ try {
+ LOG.log(Level.DEBUG, "Waiting for listener to start.");
+
+ listenerStarted.wait();
+ } catch (InterruptedException ignored) {
+ }
+ // return controll to the caller
+ LOG.log(Level.DEBUG,
+ "Have been notified that listener has started.");
+
+ }
+ }
+
+
+ private void stopListening() {
+ // Stop the thread waiting for data
+ listenerThread.interrupt();
+
+ // Close all open streams
+ if (server != null) {
+ try {
+ if (sock != null)
+ synchronized (sock) {
+ sock.notifyAll();
+ }
+ if (bufIn != null)
+ bufIn.close();
+ if (bufOut != null)
+ bufOut.close();
+ if (server != null)
+ server.close();
+ } catch (IOException ignored) {
+ LOG.log(Level.WARN, ignored);
+ }
+ }
+ }
+
+ /*
+ * Entry point for the creation of this class's 2 worker threads.
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ if(Thread.currentThread().getName().startsWith(NOTIFICATION_CONSUMER_PORT_THREAD_PREFIX))
+ listenerServiceLoop();
+ else
+ workerServiceLoop();
+
+ }
+
+ private void workerServiceLoop() {
+ while(true){
+ try {
+ synchronized(retIncomingMessage){
+ retIncomingMessage.wait();
+ LOG.log(Level.INFO,"Processing received notification.");
+
+ try {
+ deliverNotification(retIncomingMessage.toString(),this.headerData);
+ } catch (XmlException e) {
+ LOG.log(Level.ERROR,"Notification caused Parse Exception.",e);
+ continue;
+ } catch (UnexpectedServerResponseException e) {
+ LOG.log(Level.ERROR,e);
+ continue;
+ }
+
+ retIncomingMessage.notify();
+ }
+ } catch (InterruptedException e) {
+ LOG.log(Level.INFO,"Message Worker Thread has terminated.");
+ return;
+ }
+ }
+
+
+ }
+
+ /**
+ * Delivers all notifications
+ * @param notificationText
+ * @param header
+ * @throws XmlException
+ * @throws UnexpectedServerResponseException
+ */
+ private void deliverNotification(String notificationText, HttpHeader header) throws XmlException, UnexpectedServerResponseException {
+ hasChanged();
+ NotificationImpl[] notifications = NotificationImpl.createNotifications(notificationText,header);
+ for (int i = 0; i < notifications.length; i++) {
+ NotificationImpl notification = notifications[i];
+ notifyObservers(notification);
+ }
+ clearChanged();
+ }
+
+ /**
+ * One thread will reside in this method for the entire life of the consumer
+ * It will be responsible for reading socket data and singnaling when it is
+ * ready to be delivered to observers.
+ */
+ private void listenerServiceLoop() {
+ server = null;
+ sock = null;
+ bufIn = null;
+ bufOut = null;
+ byte[] responseBytes = null;
+
+ try {
+ server = new ServerSocket(port);
+ server.setSoTimeout(timeout);
+
+ // let the outer method know that we have started and just about to
+ // block on the accept
+ synchronized (listenerStarted) {
+ listenerStarted.notify();
+ LOG.log(Level.DEBUG,
+ "Calling thread notified that listner is running.");
+ }
+
+ } catch (IOException e) {
+ LOG.log(Level.ERROR, "Error creating listener socket.", e);
+ return;
+ }
+
+ while (true) {
+
+ try {
+ LOG.log(Level.INFO, "Listener Going into accepting state");
+ sock = server.accept();
+
+ bufIn = new BufferedReader(new InputStreamReader(sock
+ .getInputStream()));
+ bufOut = new BufferedOutputStream(sock.getOutputStream());
+
+ // Blocks until Header is read
+ String header = readHeader(bufIn);
+ this.headerData = new HttpHeader(header);
+ // Determine length of HTTP Request
+ String content_length = headerData
+ .getHeader(HttpHeader.CONTENT_LENGTH);
+
+ int size = Integer.parseInt(content_length);
+
+ LOG.log(Level.DEBUG, "Waiting on " + size + " bytes");
+ responseBytes = buildResponse().toString().getBytes();
+
+
+ // Build a buffer that matches the content length
+ int bytes_to_read = size;
+ while (retIncomingMessage.length() < size) {
+ try {
+ synchronized (retIncomingMessage) {
+ char[] buffer = new char[size];
+
+ // blocks
+ int bytes_read = bufIn.read(buffer, 0,
+ bytes_to_read);
+ {
+ retIncomingMessage
+ .append(buffer, 0, bytes_read);
+ }
+ LOG.log(Level.DEBUG, "Read " + bytes_read
+ + " bytes.");
+ bytes_to_read -= bytes_read;
+ }
+ } catch (InterruptedIOException ignored) {
+ LOG.log(Level.DEBUG, "This thread was interrupted.",
+ ignored);
+ }
+ }
+ bufOut.write(responseBytes, 0, responseBytes.length);
+ bufOut.flush();
+ bufIn.close();
+ bufOut.close();
+ LOG.log(Level.DEBUG, "Closed Buffers. Now closing socket...");
+ if (closeSocketAfterNotification) {
+ sock.close();
+ }
+ LOG
+ .log(Level.INFO,
+ "This notification socket has been closed.");
+
+ } catch (InterruptedIOException ignored) {
+ LOG.log(Level.DEBUG, "Timeout occured or listener inerrupted.",
+ ignored);
+ return;
+ } catch (Throwable t) {
+ synchronized (retIncomingMessage) {
+ retIncomingMessage.delete(0, retIncomingMessage.length());
+ retIncomingMessage.append("ERROR: ");
+ retIncomingMessage.append(t);
+ }
+ } finally {
+ synchronized (retIncomingMessage) {
+ // make sure something goes in the message, even if nothing
+ // was received
+ if (retIncomingMessage.length() == 0) {
+ retIncomingMessage
+ .append("ERROR: incoming message was empty");
+ LOG.log(Level.ERROR,
+ "ERROR: incoming message was empty");
+ }
+ LOG.log(Level.DEBUG, "Notfication Received.\n"
+ + retIncomingMessage);
+ LOG.log(Level.DEBUG, "Notifying Listening Application.\n");
+ retIncomingMessage.notify();
+
+ LOG.log(Level.DEBUG,
+ "Waiting for it to empty buffer and notify.....\n");
+ try { // This wait hangs
+ ready = true;
+ retIncomingMessage.wait();
+ LOG.log(Level.DEBUG,
+ "Notifying Listening Application Complete.\n");
+ } catch (InterruptedException e1) {
+ LOG.log(Level.DEBUG, "Notification Worker Exiting");
+ return;
+ }
+ retIncomingMessage.setLength(0);
+ ready = false;
+
+ }
+
+ // if ( server != null )
+ // {
+ // try
+ // {
+ // server.close();
+ // }
+ // catch ( IOException ignored )
+ // {
+ // }
+ // }
+
+ // do this as a fail safe
+ synchronized (listenerStarted) {
+ listenerStarted.notify();
+ }
+ LOG.log(Level.INFO, "Notification Listening restarting.");
+
+ }
+ }
+ }
+
+ /**
+ * @param bufIn2
+ */
+ private String readHeader(BufferedReader streamIn) throws IOException {
+
+ StringBuffer header = new StringBuffer();
+ // blocks
+ request = streamIn.readLine();
+ LOG.log(Level.DEBUG, "Notification URI is " + request);
+ String str = request;
+ while (!str.equals("")) {
+ str = streamIn.readLine();
+ header.append(str);
+ header.append("\n");
+ }
+ LOG.log(Level.DEBUG, "Received HTTP Header:\n" + header.toString());
+
+ return header.toString();
+ }
+
+ /**
+ * Build a one-way HTTP response message that complies to the WS-I Basic
+ * Profile 1.0, section 5.6.10 - see
+ * http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html#refinement16651160
+ *
+ * @return a WS-I-compliant Notify response message
+ */
+ private String buildResponse() {
+ Date timeNow = new Date();
+ Date sameTimeTomorrow = new Date(timeNow.getTime()
+ + (24 * 60 * 60 * 1000));
+ StringBuffer responseBuf = new StringBuffer("HTTP/");
+ responseBuf.append(HTTP_VERSION);
+ responseBuf.append(" ");
+ responseBuf.append(HTTP_STATUS);
+ responseBuf.append("\r\n");
+
+ responseBuf.append("Date: ");
+ responseBuf.append(HTTP_DATE_FORMAT.format(timeNow));
+ responseBuf.append("\r\n");
+
+ responseBuf.append("Server: ");
+ responseBuf.append(HTTP_SERVER_NAME);
+ responseBuf.append("\r\n");
+
+ responseBuf.append("Cache-Control: ");
+ responseBuf.append("max-age=86400");
+ responseBuf.append("\r\n");
+
+ responseBuf.append("Expires: ");
+ responseBuf.append(HTTP_DATE_FORMAT.format(sameTimeTomorrow));
+ responseBuf.append("\r\n");
+
+ return responseBuf.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotificationConsumer#getRequestUri()
+ */
+ public String getRequestUri() {
+ if (request == null)
+ return "";
+ return request.split(" ")[1];
+ }
+
+ public void setCloseSocketAfterNotification(boolean value) {
+ closeSocketAfterNotification = value;
+ }
+
+ public Object getMessageSemaphore() {
+ return listenerStarted;
+ }
+
+ public boolean isReady() {
+ return ready;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotificationConsumer#getEndpointReference()
+ */
+ public XmlBeansEndpointReference getEndpointReference() throws UnknownHostException{
+ InetAddress addr = InetAddress.getLocalHost();
+ return new XmlBeansEndpointReference("http://"+addr.getHostName()+":"+port,org.apache.ws.addressing.v2004_08_10.AddressingConstants.NSURI_ADDRESSING_SCHEMA);
+ }
+}
Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationImpl.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotificationImpl.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,146 @@
+package org.apache.ws.client.muse.client.impl.notification;
+
+import java.util.Calendar;
+import java.util.Vector;
+
+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.util.XmlBeanUtils;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ComponentAddressType;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ComponentType;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.impl.ManagementEventTypeImpl;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotificationMessageHolderType;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotifyDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.GetCurrentMessageResponseDocument.GetCurrentMessageResponse;
+import org.xmlsoap.schemas.soap.envelope.Body;
+import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
+
+public class NotificationImpl {
+ //private String notificationText;
+ private HttpHeader header;
+ private GetCurrentMessageResponse response;
+ private NotificationMessageHolderType message;
+
+ public NotificationImpl(GetCurrentMessageResponse response) {
+ super();
+ this.response=response;
+ }
+
+ public NotificationImpl(NotificationMessageHolderType message,HttpHeader header) {
+ this.message=message;
+ this.header=header;
+ }
+
+ /**
+ * A factory method for this class which is intended to produce an array
+ * of notifications from a raw SOAP Document containing a ws-notif notification.
+ * @param notificationText
+ * @param header
+ * @return
+ * @throws XmlException
+ * @throws UnexpectedServerResponseException
+ */
+ public static NotificationImpl[] createNotifications(String notificationText, HttpHeader header) throws XmlException, UnexpectedServerResponseException{
+ org.xmlsoap.schemas.soap.envelope.Envelope envelope;
+ Body body;
+ XmlObject rawEnvelopeObj = XmlObject.Factory.parse(notificationText);
+ if(!(rawEnvelopeObj instanceof EnvelopeDocument)){
+ throw new UnexpectedServerResponseException("This message is not a SOAP document.");
+ }
+
+ EnvelopeDocument ed = (EnvelopeDocument) rawEnvelopeObj;
+ envelope = ed.getEnvelope();
+ body = envelope.getBody();
+ XmlObject[] children = XmlBeanUtils.getChildElements(body);
+ NotifyDocument.Notify notifyElement = (NotifyDocument.Notify) children[0];
+ NotificationMessageHolderType[] messages = notifyElement.getNotificationMessageArray();
+ Vector notifications=new Vector();
+ for (int i = 0; i < messages.length; i++) {
+ NotificationMessageHolderType message = messages[i];
+ notifications.add(new NotificationImpl(message,header));
+ }
+ return (NotificationImpl[]) notifications.toArray(new NotificationImpl[0]);
+ }
+
+ public void validate(){
+ //validateXmlBean(ed);
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return message.xmlText();
+ }
+ // WS-Notif -------------------------------------------
+ public TopicExpressionImpl getTopic(){
+ TopicExpressionType topic = message.getTopic();
+ if(topic==null)
+ return null;
+ return new TopicExpressionImpl(XmlBeanUtils.getValueAsQName(topic),topic.getDialect());
+ }
+ public EndpointReference getProducerReference(){
+ return new XmlBeansEndpointReference(message.getProducerReference());
+ }
+ public XmlObject getNotificationMessage(){
+ return message.getMessage();
+ }
+ // MUWS ----------------------------------------------
+
+ public ManagementEventTypeImpl getManagementEvent(){
+ ManagementEventTypeImpl manEvt =
+ (ManagementEventTypeImpl) XmlBeanUtils.getChildElements(getNotificationMessage())[0];
+ return manEvt;
+ }
+
+ public String getEventId(){
+ return getManagementEvent().getEventId();
+ }
+
+ public Calendar getReportTime(){
+ return getManagementEvent().getReportTime();
+ }
+
+ public ComponentType getSource(){
+ return getManagementEvent().getSourceComponent();
+ }
+
+ public String getSourceId(){
+ return getSource().getResourceId();
+ }
+
+ // TODO Implementation of this will have to wait until the unit test
+ public EndpointReference[] getSourceEndpointReferences(){
+ ComponentAddressType[] eprArry = getSource().getComponentAddressArray();
+ for (int i = 0; i < eprArry.length; i++) {
+ ComponentAddressType type = eprArry[i];
+
+ }
+ return null;
+
+ }
+ public ComponentType getReporter(){
+ return getManagementEvent().getReporterComponent();
+ }
+ public String getReporterId(){
+ return getReporter().getResourceId();
+ }
+ public String getReporterEndpointReference(){
+ return null;
+
+ }
+ // TODO Implementation of this will have to wait until the unit test
+ public EndpointReference[] getReporterEndpointReferences(){
+ ComponentAddressType[] eprArry = getReporter().getComponentAddressArray();
+ for (int i = 0; i < eprArry.length; i++) {
+ ComponentAddressType type = eprArry[i];
+
+ }
+ return null;
+
+ }
+
+}
Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotifyableResourceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotifyableResourceImpl.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotifyableResourceImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/NotifyableResourceImpl.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,227 @@
+/*=============================================================================*
+ * 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.notification;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Calendar;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.addressing.EndpointReference;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.client.muse.client.ManageableResource;
+import org.apache.ws.client.muse.client.impl.ManageableResourceImpl;
+import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.ws.muws.v1_0.impl.advertiser.ResourceAdvertiserPropertyQNames;
+import org.apache.ws.notification.base.v2004_06.porttype.NotificationProducerPortType;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.impl.values.XmlAnyUriImpl;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.GetCurrentMessageDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.GetCurrentMessageResponseDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.GetCurrentMessageDocument.GetCurrentMessage;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeDocument.Subscribe;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.impl.SubscribeResponseDocumentImpl;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.impl.TopicExpressionTypeImpl;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.impl.SubscribeResponseDocumentImpl.SubscribeResponseImpl;
+// TODO Support Preconditions and selectors and Policies
+// TODO deal with nil=true on subscription durations
+public class NotifyableResourceImpl extends ManageableResourceImpl implements ManageableResource {
+
+ public NotifyableResourceImpl(EndpointReference epr)
+ throws MalformedURLException {
+ super(epr);
+ }
+
+ public NotifyableResourceImpl(URL url) throws MalformedURLException,
+ XmlException, IOException {
+ super(url);
+ }
+
+ public NotifyableResourceImpl(String txt) throws MalformedURLException,
+ XmlException, IOException {
+ super(txt);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#getTopics()
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotifyableResource#getTopics()
+ */
+ public TopicExpressionImpl[] getTopics() throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+ XmlObject[] propsValue = getProperty(NotificationProducerPortType.PROP_QNAME_TOPIC);
+ Vector results=new Vector(10);
+ for (int index = 0; index < propsValue.length; index++) {
+ XmlObject object = propsValue[index];
+ if(object instanceof TopicExpressionTypeImpl){
+ TopicExpressionTypeImpl tx=(TopicExpressionTypeImpl)object;
+ String dialect=tx.getDialect();
+ QName value = XmlBeanUtils.getValueAsQName(tx);
+ results.add(new TopicExpressionImpl(value,dialect));
+ }
+ }
+ return (TopicExpressionImpl[]) results.toArray(new TopicExpressionImpl[0]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#isFixedTopicSet()
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotifyableResource#isFixedTopicSet()
+ */
+ public boolean isFixedTopicSet() throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+ return getPropertyAsBoolean(ResourceAdvertiserPropertyQNames.FIXEDTOPICSET);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#getTopicExpressionDialects()
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotifyableResource#getTopicExpressionDialects()
+ */
+ public String[] getTopicExpressionDialects() throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+
+ XmlObject[] propsValue = getProperty(ResourceAdvertiserPropertyQNames.TOPICEXPRESSIONDIALECTS);
+ Vector results=new Vector(10);
+ for (int i = 0; i < propsValue.length; i++) {
+ XmlObject object = propsValue[i];
+ if(object instanceof XmlAnyUriImpl){
+ XmlAnyUriImpl xmlAny = (XmlAnyUriImpl)object;
+ results.add(xmlAny.getStringValue());
+ }
+ }
+ return (String[]) results.toArray(new String[0]);
+
+ }
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl, org.apache.ws.addressing.XmlBeansEndpointReference)
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotifyableResource#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl, org.apache.ws.addressing.XmlBeansEndpointReference)
+ */
+ public ManageableResource subscribe(TopicExpressionImpl topic,
+ XmlBeansEndpointReference consumerReference) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+ TopicExpressionImpl[] topics={topic};
+ return subscribe(topics,consumerReference,null,false,null,null,null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl, org.apache.ws.addressing.XmlBeansEndpointReference, java.util.Calendar, boolean)
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotifyableResource#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl, org.apache.ws.addressing.XmlBeansEndpointReference, java.util.Calendar, boolean)
+ */
+ public ManageableResource subscribe(TopicExpressionImpl topic,
+ XmlBeansEndpointReference consumerReference,Calendar terminationTime,boolean notify) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+ TopicExpressionImpl[] topics={topic};
+ return subscribe(topics,consumerReference,terminationTime,notify,null,null,null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl[], org.apache.ws.addressing.XmlBeansEndpointReference, java.util.Calendar, boolean, org.apache.ws.client.muse.client.impl.notification.QueryImpl, org.apache.ws.client.muse.client.impl.notification.QueryImpl, org.apache.xmlbeans.XmlObject)
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotifyableResource#subscribe(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl[], org.apache.ws.addressing.XmlBeansEndpointReference, java.util.Calendar, boolean, org.apache.ws.client.muse.client.impl.notification.QueryImpl, org.apache.ws.client.muse.client.impl.notification.QueryImpl, org.apache.xmlbeans.XmlObject)
+ */
+ public ManageableResource subscribe(TopicExpressionImpl[] topics,
+ XmlBeansEndpointReference consumerReference,Calendar terminationTime,boolean useNotify,
+ QueryImpl precondition,QueryImpl selector, XmlObject policy)
+ throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+
+ // Construct request
+ SubscribeDocument subscribeDocument=SubscribeDocument.Factory.newInstance();
+ Subscribe subscribeMessage = subscribeDocument.addNewSubscribe();
+
+ org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType consumerRefType = (org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType) consumerReference.getXmlObject(org.apache.ws.addressing.v2003_03.AddressingConstants.NSURI_ADDRESSING_SCHEMA);
+ subscribeMessage.setConsumerReference(consumerRefType);
+ if(terminationTime!=null)
+ subscribeMessage.setInitialTerminationTime(terminationTime);
+ subscribeMessage.setUseNotify(useNotify);
+
+ // Add all topics you would like to subscribe to
+ for (int i = 0; i < topics.length; i++) {
+ TopicExpressionImpl expression = topics[i];
+ TopicExpressionType topicExpression = subscribeMessage.addNewTopicExpression();
+ topicExpression.setDialect(expression.getDialect());
+ XmlBeanUtils.setValueAsQName(topicExpression,expression.getName());
+ }
+
+ // Blindly Insert a policy. This should be a WS-Policy Block when provided
+ if(policy!=null)
+ subscribeMessage.setSubscriptionPolicy(policy);
+
+ // Provide preconditions and selectors if avaialble
+ if(precondition!=null)
+ subscribeMessage.setPrecondition(precondition.toXmlObject());
+ if(selector!=null)
+ subscribeMessage.setSelector(selector.toXmlObject());
+
+
+ // Send request
+ XmlObject response = rs.sendRequest(subscribeDocument,"http://Subscribe","M");
+ if(!(response instanceof SubscribeResponseDocumentImpl.SubscribeResponseImpl)){
+ throw new UnexpectedServerResponseException(
+ "Server returned either an unrecognizable response or no response at all. Expected SubscribeResponseDocument but found "+response.getClass().getName());
+ }
+
+ // return newply created resource describing the subscription
+ SubscribeResponseDocumentImpl.SubscribeResponseImpl subscribeResponse=(SubscribeResponseImpl) response;
+ org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType subscriptionEpr = subscribeResponse.getSubscriptionReference();
+ return new NotifyableResourceImpl(new XmlBeansEndpointReference(subscriptionEpr)); // change this later
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.Temp#getCurrentMessage(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl)
+ */
+ /* (non-Javadoc)
+ * @see org.apache.ws.client.muse.client.impl.notification.NotifyableResource#getCurrentMessage(org.apache.ws.client.muse.client.impl.notification.TopicExpressionImpl)
+ */
+ public NotificationImpl getCurrentMessage(TopicExpressionImpl topic) throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+ //TODO This is not finished.
+ // Construct request
+ GetCurrentMessageDocument cmd=GetCurrentMessageDocument.Factory.newInstance();
+ GetCurrentMessage cm = cmd.addNewGetCurrentMessage();
+ TopicExpressionType tm = cm.addNewTopic();
+ tm.setDialect(topic.getDialect());
+ XmlBeanUtils.setValueAsQName(tm,topic.getName());
+
+ // Send request
+ XmlObject parts = rs.sendRequest(cmd,"http://GetCurrentMessage","M");
+
+ // Process response
+ if(!(parts instanceof GetCurrentMessageResponseDocument.GetCurrentMessageResponse))
+ throw new UnexpectedServerResponseException("Expected GetCurrentMessageResponseDocument but received "+parts.getClass().getName());
+ GetCurrentMessageResponseDocument.GetCurrentMessageResponse response=(GetCurrentMessageResponseDocument.GetCurrentMessageResponse)parts;
+
+ return new NotificationImpl(response);
+
+
+ }
+
+ // Create a custom ManageableResource for Returned subscriptions
+
+}
Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/QueryImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/QueryImpl.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/QueryImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/QueryImpl.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,17 @@
+package org.apache.ws.client.muse.client.impl.notification;
+
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
+
+public class QueryImpl {
+
+ public QueryImpl() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public QueryExpressionType toXmlObject() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/TopicExpressionImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/TopicExpressionImpl.java?rev=290182&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/TopicExpressionImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/notification/TopicExpressionImpl.java Mon Sep 19 08:16:51 2005
@@ -0,0 +1,46 @@
+package org.apache.ws.client.muse.client.impl.notification;
+
+import javax.xml.namespace.QName;
+
+public class TopicExpressionImpl {
+ private QName name;
+ private String dialect="http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Simple";
+ public TopicExpressionImpl(QName name,String dialect) {
+ super();
+ this.name=name;
+ this.dialect=dialect;
+ }
+ /**
+ * @return Returns the dialect.
+ */
+ public String getDialect() {
+ return dialect;
+ }
+ /**
+ * @param dialect The dialect to set.
+ */
+ public void setDialect(String dialect) {
+ this.dialect = dialect;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public QName getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(QName name) {
+ this.name = name;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ // TODO Auto-generated method stub
+ return "Name="+name+", Dialect="+dialect ;
+ }
+
+
+}
Modified: 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=290182&r1=290181&r2=290182&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ResourceStub.java (original)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ResourceStub.java Mon Sep 19 08:16:51 2005
@@ -30,6 +30,7 @@
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.FaultException;
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;
Modified: 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=290182&r1=290181&r2=290182&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ServiceStub.java (original)
+++ webservices/muse/trunk/src/examples/client/src/java/org/apache/ws/client/muse/client/impl/stubs/ServiceStub.java Mon Sep 19 08:16:51 2005
@@ -17,6 +17,7 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.ws.util.soap.SoapClient;
import org.apache.xmlbeans.XmlObject;