[wsas-java-dev] svn commit r1864 - in
trunk/wsas/java/modules/core/src/org/wso2/wsas: feed
feed/atom feed/rss transport/util
svn at wso2.org
svn at wso2.org
Tue Apr 17 07:40:22 PDT 2007
Author: azeez
Date: Tue Apr 17 07:40:08 2007
New Revision: 1864
Added:
trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/atom/AtomFeedFactory.java
trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/rss/RSSFeedFactory.java
Modified:
trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/FeedConstants.java
trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/atom/AtomFeedBuilder.java
trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/rss/RSSFeedBuilder.java
trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/util/HttpGetRequestProcessor.java
Log:
Caching the RSS & Atom feed objects, and statically getting them from the cache
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/FeedConstants.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/FeedConstants.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/FeedConstants.java Tue Apr 17 07:40:08 2007
@@ -24,9 +24,8 @@
public static final int RSS_FEED = 1;
public static final int ATOM_FEED = 2;
- public static final String RSS_KEY = "RSS";
- public static final String ATOM_KEY = "ATOM";
-
+ public static final String WSO2WSAS_RSS_FEED = "wso2wsas.rss";
+ public static final String WSO2WSAS_ATOM_FEED = "wso2wsas.atom";
public static final String FEED_DIRECTORY = "\\feed";
public static final String RSS_HOME = "\\feed\\rss";
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/atom/AtomFeedBuilder.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/atom/AtomFeedBuilder.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/atom/AtomFeedBuilder.java Tue Apr 17 07:40:08 2007
@@ -32,16 +32,15 @@
public class AtomFeedBuilder extends AbstractFeedBuilder {
private static Log log = LogFactory.getLog(AtomFeedBuilder.class);
+ private AtomFeed atomFeed;
public AtomFeedBuilder(AxisConfiguration axisConfig) {
super(axisConfig);
- AtomFeed rssFeed = new AtomFeed(axisConfig);
-// System.getProperties().put(FeedConstants.ATOM_KEY, rssFeed);
+ atomFeed = AtomFeedFactory.getAtomFeed(FeedConstants.WSO2WSAS_ATOM_FEED, axisConfig);
}
public void addService(AxisService serviceDescription, String itemDefualtLink) {
try {
- AtomFeed atomFeed = getAtomFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setDescription(serviceDescription.getServiceDescription());
serviceElement.setName(serviceDescription.getName());
@@ -69,13 +68,12 @@
public void removeService(AxisService serviceDescription, String itemDefualtLink) {
try {
- AtomFeed atomfeed = getAtomFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setDescription(serviceDescription.getServiceDescription());
serviceElement.setName(serviceDescription.getName());
serviceElement.setUpdate(true);
serviceElement.setEventType(ServiceElement.SERVICE_REMOVE);
- atomfeed.addAtomElement(serviceElement);
+ atomFeed.addAtomElement(serviceElement);
} catch (Exception e) {
log.error(e);
}
@@ -83,13 +81,12 @@
public void stopService(AxisService serviceDescription, String itemDefualtLink) {
try {
- AtomFeed atomfeed = getAtomFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setDescription(serviceDescription.getServiceDescription());
serviceElement.setName(serviceDescription.getName());
serviceElement.setUpdate(true);
serviceElement.setEventType(ServiceElement.SERVICE_STOP);
- atomfeed.addAtomElement(serviceElement);
+ atomFeed.addAtomElement(serviceElement);
} catch (Exception e) {
log.error(e);
}
@@ -97,21 +94,19 @@
public void startService(AxisService serviceDescription, String itemDefualtLink) {
try {
- AtomFeed atomfeed = getAtomFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setDescription(serviceDescription.getServiceDescription());
serviceElement.setName(serviceDescription.getName());
serviceElement.setUpdate(true);
serviceElement.setEventType(ServiceElement.SERVICE_START);
- atomfeed.addAtomElement(serviceElement);
+ atomFeed.addAtomElement(serviceElement);
} catch (Exception e) {
log.error(e);
}
}
- public void serviceUpdate(AxisService serviceDescription, String itemDefualtLink) {
+ public void serviceUpdate(AxisService serviceDescription, String itemDefaultLink) {
try {
- AtomFeed atomfeed = getAtomFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setDescription(serviceDescription.getServiceDescription());
serviceElement.setName(serviceDescription.getName());
@@ -134,13 +129,9 @@
}
serviceElement.setModules(modules);
serviceElement.setEventType(ServiceElement.SERVICE_UPDATE);
- atomfeed.addAtomElement(serviceElement);
+ atomFeed.addAtomElement(serviceElement);
} catch (Exception e) {
log.error(e);
}
}
-
- private AtomFeed getAtomFeed() {
- return (AtomFeed) System.getProperties().get(FeedConstants.ATOM_KEY);
- }
}
Added: trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/atom/AtomFeedFactory.java
==============================================================================
--- (empty file)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/atom/AtomFeedFactory.java Tue Apr 17 07:40:08 2007
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsas.feed.atom;
+
+import org.apache.axis2.engine.AxisConfiguration;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ *
+ */
+public class AtomFeedFactory {
+ private static Map feeds = new HashMap();
+
+ public static AtomFeed getAtomFeed(String feedSource, AxisConfiguration axisConfiguration){
+ AtomFeed atomFeed = (AtomFeed) feeds.get(feedSource);
+ if(atomFeed == null){
+ atomFeed = new AtomFeed(axisConfiguration);
+ feeds.put(feedSource, atomFeed);
+ }
+ return atomFeed;
+ }
+
+ public static AtomFeed getAtomFeed(String feedSource){
+ return (AtomFeed) feeds.get(feedSource);
+ }
+}
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/rss/RSSFeedBuilder.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/rss/RSSFeedBuilder.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/rss/RSSFeedBuilder.java Tue Apr 17 07:40:08 2007
@@ -15,30 +15,29 @@
*/
package org.wso2.wsas.feed.rss;
-import org.wso2.wsas.feed.AbstractFeedBuilder;
-import org.wso2.wsas.feed.FeedConstants;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.wsas.feed.AbstractFeedBuilder;
+import org.wso2.wsas.feed.FeedConstants;
import java.util.ArrayList;
import java.util.Iterator;
public class RSSFeedBuilder extends AbstractFeedBuilder {
private static Log log = LogFactory.getLog(RSSFeedBuilder.class);
+ private RSSFeed rssFeed;
public RSSFeedBuilder(AxisConfiguration axisConfig) {
super(axisConfig);
- RSSFeed rssFeed = new RSSFeed(axisConfig);
-// System.getProperties().put(FeedConstants.RSS_KEY, rssFeed);
+ rssFeed = RSSFeedFactory.getRSSFeed(FeedConstants.WSO2WSAS_RSS_FEED, axisConfig);
}
public void addService(AxisService serviceDescription, String itemDefaultLink) {
try {
- RSSFeed rssFeed = getRSSFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setDescription(serviceDescription.getServiceDescription());
serviceElement.setName(serviceDescription.getName());
@@ -66,7 +65,6 @@
public void removeService(AxisService serviceDescription, String itemDefaultLink) {
try {
- RSSFeed rssFeed = getRSSFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setRssType(true);
serviceElement.setDescription(serviceDescription.getServiceDescription());
@@ -80,7 +78,6 @@
public void stopService(AxisService serviceDescription, String itemDefaultLink) {
try {
- RSSFeed rssFeed = getRSSFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setRssType(true);
serviceElement.setDescription(serviceDescription.getServiceDescription());
@@ -94,7 +91,6 @@
public void startService(AxisService serviceDescription, String itemDefaultLink) {
try {
- RSSFeed rssFeed = getRSSFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setRssType(true);
serviceElement.setDescription(serviceDescription.getServiceDescription());
@@ -108,7 +104,6 @@
public void serviceUpdate(AxisService serviceDescription, String itemDefaultLink) {
try {
- RSSFeed rssFeed = getRSSFeed();
ServiceElement serviceElement = new ServiceElement();
serviceElement.setDescription(serviceDescription.getServiceDescription());
serviceElement.setName(serviceDescription.getName());
@@ -136,8 +131,4 @@
log.error(e);
}
}
-
- private RSSFeed getRSSFeed() {
- return (RSSFeed) System.getProperties().get(FeedConstants.RSS_KEY);
- }
}
Added: trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/rss/RSSFeedFactory.java
==============================================================================
--- (empty file)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/feed/rss/RSSFeedFactory.java Tue Apr 17 07:40:08 2007
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsas.feed.rss;
+
+import org.apache.axis2.engine.AxisConfiguration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class RSSFeedFactory {
+ private static Map feeds = new HashMap();
+
+ public static RSSFeed getRSSFeed(String feedSource, AxisConfiguration axisConfiguration) {
+ RSSFeed rssFeed = (RSSFeed) feeds.get(feedSource);
+ if (rssFeed == null) {
+ rssFeed = new RSSFeed(axisConfiguration);
+ feeds.put(feedSource, rssFeed);
+ }
+ return rssFeed;
+ }
+
+ public static RSSFeed getRSSFeed(String feedSource) {
+ return (RSSFeed) feeds.get(feedSource);
+ }
+}
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/util/HttpGetRequestProcessor.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/util/HttpGetRequestProcessor.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/util/HttpGetRequestProcessor.java Tue Apr 17 07:40:08 2007
@@ -31,15 +31,15 @@
import org.apache.ws.commons.schema.XmlSchema;
import org.wso2.utils.NetworkUtils;
import org.wso2.utils.ServerConfiguration;
-import org.wso2.wsas.ServerConstants;
import org.wso2.wsas.ServerManager;
import org.wso2.wsas.feed.FeedConstants;
import org.wso2.wsas.feed.atom.AtomFeed;
+import org.wso2.wsas.feed.atom.AtomFeedFactory;
import org.wso2.wsas.feed.rss.RSSFeed;
+import org.wso2.wsas.feed.rss.RSSFeedFactory;
import org.wso2.wsas.persistence.PersistenceManager;
import org.wso2.wsas.persistence.dataobject.KeyStoreDO;
import org.wso2.wsas.persistence.dataobject.ServiceDO;
-import org.wso2.wsas.util.HibernateConfigFactory;
import org.wso2.wsas.util.KeyStoreUtil;
import javax.servlet.http.HttpServletRequest;
@@ -152,7 +152,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
axisService.printWSDL(baos, ip, servicePath);
- writeDocument(baos, outputStream, "annotated-wsdl.xsl",contextRoot);
+ writeDocument(baos, outputStream, "annotated-wsdl.xsl", contextRoot);
} else if (wsdlType == 1) {
axisService.printWSDL2(outputStream, ip, servicePath);
} else {
@@ -330,7 +330,7 @@
response.setContentType("text/xml");
// Write to the output stream
- processSchema((XmlSchema) schemas.get(0), outputStream,contextRoot);
+ processSchema((XmlSchema) schemas.get(0), outputStream, contextRoot);
} else {
String idParam = request.getParameter("id");
@@ -338,7 +338,7 @@
XmlSchema schema = axisService.getSchema(Integer.parseInt(idParam));
if (schema != null) {
response.setContentType("text/xml");
- processSchema(schema, outputStream,contextRoot);
+ processSchema(schema, outputStream, contextRoot);
} else {
response.setContentType("text/html");
outputStream.write("<h4>Schema not found!</h4>".getBytes());
@@ -435,17 +435,18 @@
public static void processAtomFeed(HttpServletResponse response, String contextRoot) {
try {
response.setContentType("text/xml; charset=utf-8");
- AtomFeed atomFeed =
- (AtomFeed) System.getProperties().get(FeedConstants.ATOM_KEY);
- XMLStreamWriter writer =
- XMLOutputFactory.newInstance().
- createXMLStreamWriter(response.getOutputStream());
- writer.writeProcessingInstruction("xml-stylesheet",
- " type=\"text/xsl\" href=\"" +
- contextRoot +
- "/styles/atom.xsl\"");
- atomFeed.getFeedElement().serialize(writer);
- writer.flush();
+ AtomFeed atomFeed = AtomFeedFactory.getAtomFeed(FeedConstants.WSO2WSAS_ATOM_FEED);
+ if (atomFeed != null) {
+ XMLStreamWriter writer =
+ XMLOutputFactory.newInstance().
+ createXMLStreamWriter(response.getOutputStream());
+ writer.writeProcessingInstruction("xml-stylesheet",
+ " type=\"text/xsl\" href=\"" +
+ contextRoot +
+ "/styles/atom.xsl\"");
+ atomFeed.getFeedElement().serialize(writer);
+ writer.flush();
+ }
} catch (OMException e) {
log.debug(e);
} catch (Exception e) {
@@ -456,16 +457,18 @@
public static void processRssFeed(HttpServletResponse response, String contextRoot) {
try {
response.setContentType("text/xml; charset=utf-8");
- RSSFeed rssFeed = (RSSFeed) System.getProperties().get(FeedConstants.RSS_KEY);
- XMLStreamWriter writer =
- XMLOutputFactory.newInstance()
- .createXMLStreamWriter(response.getOutputStream());
- writer.writeProcessingInstruction("xml-stylesheet",
- " type=\"text/xsl\" href=\"" +
- contextRoot +
- "/styles/rss.xsl\"");
- rssFeed.getFeedElement().serialize(writer);
- writer.flush();
+ RSSFeed rssFeed = RSSFeedFactory.getRSSFeed(FeedConstants.WSO2WSAS_RSS_FEED);
+ if (rssFeed != null) {
+ XMLStreamWriter writer =
+ XMLOutputFactory.newInstance()
+ .createXMLStreamWriter(response.getOutputStream());
+ writer.writeProcessingInstruction("xml-stylesheet",
+ " type=\"text/xsl\" href=\"" +
+ contextRoot +
+ "/styles/rss.xsl\"");
+ rssFeed.getFeedElement().serialize(writer);
+ writer.flush();
+ }
} catch (OMException e) {
log.debug(e);
} catch (Exception e) {
More information about the Wsas-java-dev
mailing list