[Carbon-dev] svn commit r42013 - in trunk/carbon-components/request-processors: . source source/src source/src/main source/src/main/java source/src/main/java/org source/src/main/java/org/wso2 source/src/main/java/org/wso2/carbon source/src/main/java/org/wso2/carbon/request source/src/main/java/org/wso2/carbon/request/processors source/src/main/java/org/wso2/carbon/request/processors/source source/src/main/java/org/wso2/carbon/request/processors/source/internal source/src/main/resources source/src/main/resources/META-INF

keith at wso2.com keith at wso2.com
Tue Jul 28 08:04:34 PDT 2009


Author: keith
Date: Tue Jul 28 08:04:33 2009
New Revision: 42013
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=42013

Log:
Adding in the ?source request processor needed for the Mashup Server


Added:
   trunk/carbon-components/request-processors/
   trunk/carbon-components/request-processors/pom.xml   (contents, props changed)
   trunk/carbon-components/request-processors/source/
   trunk/carbon-components/request-processors/source/pom.xml   (contents, props changed)
   trunk/carbon-components/request-processors/source/src/
   trunk/carbon-components/request-processors/source/src/main/
   trunk/carbon-components/request-processors/source/src/main/java/
   trunk/carbon-components/request-processors/source/src/main/java/org/
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/SourceRequestProcessor.java   (contents, props changed)
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/internal/
   trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/internal/Activator.java   (contents, props changed)
   trunk/carbon-components/request-processors/source/src/main/resources/
   trunk/carbon-components/request-processors/source/src/main/resources/META-INF/
   trunk/carbon-components/request-processors/source/src/main/resources/META-INF/component.xml

Added: trunk/carbon-components/request-processors/pom.xml
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/request-processors/pom.xml?pathrev=42013
==============================================================================
--- (empty file)
+++ trunk/carbon-components/request-processors/pom.xml	Tue Jul 28 08:04:33 2009
@@ -0,0 +1,22 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <parent>
+        <groupId>org.wso2.carbon</groupId>
+        <artifactId>carbon-parent</artifactId>
+        <version>2.0.0</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.wso2.carbon</groupId>
+    <artifactId>org.wso2.carbon.request-processors</artifactId>
+    <version>2.0.0.SNAPSHOT</version>
+    <packaging>pom</packaging>
+    <name>WSO2 Carbon request processors</name>
+    <url>http://wso2.org</url>
+
+    <modules>
+        <module>source</module>
+    </modules>
+</project>

Added: trunk/carbon-components/request-processors/source/pom.xml
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/request-processors/source/pom.xml?pathrev=42013
==============================================================================
--- (empty file)
+++ trunk/carbon-components/request-processors/source/pom.xml	Tue Jul 28 08:04:33 2009
@@ -0,0 +1,108 @@
+<!--
+  ~ Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
+  ~
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <parent>
+        <groupId>org.wso2.carbon</groupId>
+        <artifactId>org.wso2.carbon.request-processors</artifactId>
+        <version>2.0.0.SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>org.wso2.carbon.request-processors.source</artifactId>
+    <packaging>bundle</packaging>
+    <version>2.0.0.SNAPSHOT</version>
+    <name>WSO2 Carbon - Document request processor</name>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.mashup-utils</artifactId>
+            <version>2.0.0.SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.tryit.common</artifactId>
+            <version>${wso2carbon.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.ui</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <!--resources>
+            <resource>
+                <directory>src/main/java</directory>
+                <includes>
+                    <include>**/*.xsl</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+        </resources-->
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>1.4.0</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Name>${pom.artifactId}</Bundle-Name>
+                        <Bundle-Activator>org.wso2.carbon.request.processors.source.internal.Activator</Bundle-Activator>
+                        <Private-Package>
+                            org.wso2.carbon.request.processors.source.internal
+                        </Private-Package>
+                        <Export-Package>
+                            org.wso2.carbon.request.processors.source.*
+                        </Export-Package>
+                        <Import-Package>
+                            !org.wso2.carbon.request.processors.source.*,
+                            org.apache.axis2.*; version="${axis2.osgi.version.range}",
+			                org.apache.axiom.*; version="${axiom.osgi.version.range}",
+                            org.apache.commons.logging.*,
+                            org.wso2.carbon.core.*,
+                            org.wso2.carbon.utils.*,
+                            org.wso2.carbon.mashup.*,
+                            javax.servlet.*; version=2.4.0,
+                            *;resolution:=optional
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/SourceRequestProcessor.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/SourceRequestProcessor.java?pathrev=42013
==============================================================================
--- (empty file)
+++ trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/SourceRequestProcessor.java	Tue Jul 28 08:04:33 2009
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * 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.carbon.request.processors.source;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.core.transports.HttpGetRequestProcessor;
+import org.wso2.carbon.mashup.MashupConstants;
+import org.wso2.carbon.mashup.utils.MashupUtils;
+import org.wso2.carbon.utils.ServerConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.OutputStream;
+
+public class SourceRequestProcessor implements HttpGetRequestProcessor {
+
+    private static Log log = LogFactory.getLog(SourceRequestProcessor.class);
+
+    /* (non-Javadoc)
+     * @see org.wso2.wsas.transport.HttpGetRequestProcessor#process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.axis2.context.ConfigurationContext)
+     */
+    public void process(HttpServletRequest request, HttpServletResponse response,
+                        ConfigurationContext configurationContext) throws Exception {
+        String requestURI = request.getRequestURI();
+        String contextPath = configurationContext.getServiceContextPath();
+        String serviceName = requestURI.substring(requestURI.indexOf(contextPath) +
+                contextPath.length() + 1);
+        AxisConfiguration configuration = configurationContext.getAxisConfiguration();
+        AxisService axisService = configuration
+                .getServiceForActivation(serviceName);
+        OutputStream outputStream = response.getOutputStream();
+
+        if (axisService != null) {
+            if (axisService.isActive()) {
+
+                String serviceType =
+                        (String) axisService.getParameterValue(ServerConstants.SERVICE_TYPE);
+
+                // We can show source only if this service is a javascript service
+                if (MashupConstants.JS_SERVICE.equals(serviceType)) {
+                    String contentTypeParameter =
+                            request.getParameter(MashupConstants.CONTENT_TYPE_QUERY_PARAM);
+                    String contentType = "application/javascript";
+                    if (contentTypeParameter != null && !"".equals(contentTypeParameter.trim())) {
+                        contentType = contentTypeParameter;
+                    }
+                    response.setContentType(contentType + "; charset=utf-8");
+                    String serviceJSFile = (String) axisService
+                            .getParameterValue(MashupConstants.SERVICE_JS);
+                    if (serviceJSFile != null) {
+                        File file = new File(serviceJSFile);
+                        MashupUtils.writeFile(response, file);
+                    } else {
+                        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                        response.setContentType("text/html");
+                        outputStream
+                                .write(("<h4>Source is not available for this service.")
+                                        .getBytes());
+                        outputStream.flush();
+                    }
+                } else if (ServerConstants.SERVICE_TYPE_DB.equals(serviceType)) {
+                    String contentTypeParameter =
+                            request.getParameter(MashupConstants.CONTENT_TYPE_QUERY_PARAM);
+                    String contentType = "text/plain";
+                    if (contentTypeParameter != null && !"".equals(contentTypeParameter.trim())) {
+                        contentType = contentTypeParameter;
+                    }
+                    response.setContentType(contentType + "; charset=utf-8");
+                    Parameter implInfoParam = axisService
+                            .getParameter("data_service");
+                    if (implInfoParam != null && implInfoParam.getValue() instanceof String) {
+                        String filePath = (String) implInfoParam.getValue();
+                        File file = new File(filePath);
+                        if (file.exists()) {
+                            MashupUtils.writeFile(response, file);
+                        } else {
+                            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                            response.setContentType("text/html");
+                            outputStream
+                                    .write(("<h4>Cannot find source file for Data Service").getBytes());
+                            outputStream.flush();
+                        }
+                    } else {
+                        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                        response.setContentType("text/html");
+                        outputStream
+                                .write(("<h4>Source is not available for this service.")
+                                        .getBytes());
+                        outputStream.flush();
+                    }
+                } else {
+                    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                    response.setContentType("text/html");
+                    outputStream
+                            .write(("<h4>Source is not available for this service. The source view " +
+                                    "is avalable only for JavaScript services")
+                                    .getBytes());
+                    outputStream.flush();
+                }
+            } else {
+                response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                response.setContentType("text/html");
+                outputStream
+                        .write(("<h4>Source is not available for this service. This service " +
+                                "is not active").getBytes());
+                outputStream.flush();
+            }
+
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Cannot find the service" + serviceName + ". Axis Service is null.");
+            }
+            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            response.setContentType("text/html");
+            outputStream
+                    .write(("<h4>Service cannot be found. Cannot display <em>Source</em>.</h4>")
+                            .getBytes());
+            outputStream.flush();
+        }
+    }
+}

Added: trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/internal/Activator.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/internal/Activator.java?pathrev=42013
==============================================================================
--- (empty file)
+++ trunk/carbon-components/request-processors/source/src/main/java/org/wso2/carbon/request/processors/source/internal/Activator.java	Tue Jul 28 08:04:33 2009
@@ -0,0 +1,19 @@
+package org.wso2.carbon.request.processors.source.internal;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.wso2.carbon.core.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class Activator implements BundleActivator {
+
+    private static Log log = LogFactory.getLog(Activator.class);
+    public void start(BundleContext bundleContext) throws Exception {
+        Utils.registerHTTPGetRequestProcessors(bundleContext);
+    }
+
+    public void stop(BundleContext bundleContext) throws Exception {
+    }
+}

Added: trunk/carbon-components/request-processors/source/src/main/resources/META-INF/component.xml
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/request-processors/source/src/main/resources/META-INF/component.xml?pathrev=42013
==============================================================================
--- (empty file)
+++ trunk/carbon-components/request-processors/source/src/main/resources/META-INF/component.xml	Tue Jul 28 08:04:33 2009
@@ -0,0 +1,8 @@
+<component xmlns="http://products.wso2.org/carbon">
+	<httpGetRequestProcessors>
+		<processor>
+			<item>source</item>
+			<class>org.wso2.carbon.request.processors.source.SourceRequestProcessor</class>
+		</processor>
+	</httpGetRequestProcessors>
+</component>



More information about the Carbon-dev mailing list