summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/common-http
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-02-20 08:38:48 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-02-20 08:38:48 +0000
commit4f7f10f97d60a5e7083f9a5b190c2818de7359a1 (patch)
tree6d166ee0e551decd8989c66e0e8dfbe5a7acbed6 /sca-java-2.x/trunk/modules/common-http
parentda556f44f1b1fe17aa80d38cef206d266c114737 (diff)
Providing utility module to share common HTTP Utilities and Constants
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@912092 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/common-http')
-rw-r--r--sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF13
-rw-r--r--sca-java-2.x/trunk/modules/common-http/pom.xml31
-rw-r--r--sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java27
-rw-r--r--sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java56
4 files changed, 127 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..c1c08f864c
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/common-http/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Common HTTP
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Common HTTP
+Bundle-SymbolicName: org.apache.tuscany.sca.common.http
+Bundle-DocURL: http://www.apache.org/
+Export-Package: org.apache.tuscany.sca.common.http;version="2.0.0"
+
+
diff --git a/sca-java-2.x/trunk/modules/common-http/pom.xml b/sca-java-2.x/trunk/modules/common-http/pom.xml
new file mode 100644
index 0000000000..2a8cbdfa25
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/common-http/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-common-http</artifactId>
+ <name>Apache Tuscany SCA Common HTTP</name>
+
+</project>
diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java
new file mode 100644
index 0000000000..34052bfea8
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.common.http;
+
+public class HTTPConstants {
+ public static final String CHARACTER_ENCODING_UTF8 = "UTF-8";
+
+ public static final String HTML_CONTENT_TYPE = "text/html";
+ public static final String JAVASCRIPT_CONTENT_TYPE = "text/javascript";
+}
diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java
new file mode 100644
index 0000000000..1ce8cd2fd1
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.common.http;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility class to provide default HTTP Content-Type header
+ * based on resource type
+ */
+public class HTTPContentTypeMapper {
+ private static Map<String, String> contentTypeTable = new HashMap<String, String>();
+
+ static {
+ contentTypeTable.put("htm", HTTPConstants.HTML_CONTENT_TYPE);
+ contentTypeTable.put("html", HTTPConstants.HTML_CONTENT_TYPE);
+ contentTypeTable.put("js", "text/javascript");
+ }
+
+ /**
+ * Provided a resource path, identify default content-type based on the resource extension
+ * @param resourcePath
+ * @return
+ */
+ public static String getContentType(String resourcePath) {
+ return contentTypeTable.get(getResourceType(resourcePath));
+ }
+
+ /**
+ * Utility function to calculate file type based on its extension
+ * Useful to map HTTP content-type based on file extension
+ * @param resource the resource/file name
+ * @return the resource type/extension
+ */
+ private static String getResourceType(String resource) {
+ return resource.substring(resource.lastIndexOf(".") + 1);
+ }
+}