You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2007/11/25 23:29:47 UTC
svn commit: r598071 - in /incubator/cxf/trunk/rt:
core/src/main/java/org/apache/cxf/transport/http/
javascript/src/main/java/org/apache/cxf/javascript/
javascript/src/main/resources/META-INF/
javascript/src/main/resources/META-INF/cxf/
Author: bimargulies
Date: Sun Nov 25 14:29:46 2007
New Revision: 598071
URL: http://svn.apache.org/viewvc?rev=598071&view=rev
Log:
Begin process of handling ?js URLs.
Added:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/UrlUtilities.java
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandlerRegistry.java
incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/
incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/
incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf-extension-javascript-client.xml
incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf.extension
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/UrlUtilities.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/UrlUtilities.java?rev=598071&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/UrlUtilities.java (added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/UrlUtilities.java Sun Nov 25 14:29:46 2007
@@ -0,0 +1,67 @@
+/**
+ * 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.cxf.transport.http;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * Functions used to work with URLs in HTTP-related code.
+ */
+public final class UrlUtilities {
+
+ private UrlUtilities() {
+ }
+
+ public static Map<String, String> parseQueryString(String s) {
+ Map<String, String> ht = new HashMap<String, String>();
+ StringTokenizer st = new StringTokenizer(s, "&");
+ while (st.hasMoreTokens()) {
+ String pair = (String)st.nextToken();
+ int pos = pair.indexOf('=');
+ if (pos == -1) {
+ ht.put(pair.toLowerCase(), "");
+ } else {
+ ht.put(pair.substring(0, pos).toLowerCase(),
+ pair.substring(pos + 1));
+ }
+ }
+ return ht;
+ }
+
+
+
+ public static String getStem(String baseURI) throws MalformedURLException {
+ URL url = null;
+ url = new URL(baseURI);
+ if (url != null) {
+ baseURI = url.getPath();
+ int idx = baseURI.lastIndexOf('/');
+ if (idx != -1) {
+ baseURI = baseURI.substring(0, idx);
+ }
+ }
+ return baseURI;
+ }
+
+}
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?rev=598071&r1=598070&r2=598071&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java Sun Nov 25 14:29:46 2007
@@ -24,10 +24,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -88,14 +86,20 @@
|| baseUri.toLowerCase().contains("xsd=")))) {
int idx = baseUri.indexOf("?");
- Map<String, String> map = parseQueryString(baseUri.substring(idx + 1));
+ Map<String, String> map = UrlUtilities.parseQueryString(baseUri.substring(idx + 1));
if (map.containsKey("wsdl")
|| map.containsKey("xsd")) {
if (contextMatchExact) {
return endpointInfo.getAddress().contains(ctx);
} else {
// contextMatchStrategy will be "stem"
- return endpointInfo.getAddress().contains(getStem(baseUri.substring(0, idx)));
+ try {
+ return endpointInfo.getAddress().
+ contains(UrlUtilities.getStem(baseUri.substring(0, idx)));
+ } catch (MalformedURLException mue) {
+ LOG.log(Level.WARNING, "URL creation failed: ", mue);
+ return false;
+ }
}
}
}
@@ -106,7 +110,7 @@
EndpointInfo endpointInfo, OutputStream os) {
try {
int idx = baseUri.toLowerCase().indexOf("?");
- Map<String, String> params = parseQueryString(baseUri.substring(idx + 1));
+ Map<String, String> params = UrlUtilities.parseQueryString(baseUri.substring(idx + 1));
String base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?"));
String wsdl = params.get("wsdl");
String xsd = params.get("xsd");
@@ -344,40 +348,4 @@
public boolean isRecognizedQuery(String baseUri, String ctx, EndpointInfo endpointInfo) {
return isRecognizedQuery(baseUri, ctx, endpointInfo, false);
}
-
-
- private String getStem(String baseURI) {
-
- URL url = null;
- try {
- url = new URL(baseURI);
- } catch (MalformedURLException e) {
- LOG.log(Level.WARNING, "URL creation failed: ", e);
- }
- if (url != null) {
- baseURI = url.getPath();
- int idx = baseURI.lastIndexOf('/');
- if (idx != -1) {
- baseURI = baseURI.substring(0, idx);
- }
- }
- return baseURI;
- }
-
- static Map<String, String> parseQueryString(String s) {
- Map<String, String> ht = new HashMap<String, String>();
- StringTokenizer st = new StringTokenizer(s, "&");
- while (st.hasMoreTokens()) {
- String pair = (String)st.nextToken();
- int pos = pair.indexOf('=');
- if (pos == -1) {
- ht.put(pair.toLowerCase(), "");
- } else {
- ht.put(pair.substring(0, pos).toLowerCase(),
- pair.substring(pos + 1));
- }
- }
- return ht;
- }
-
}
Added: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java?rev=598071&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java (added)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java Sun Nov 25 14:29:46 2007
@@ -0,0 +1,109 @@
+/**
+ * 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.cxf.javascript;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.MalformedURLException;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.i18n.UncheckedException;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.javascript.service.ServiceJavascriptBuilder;
+import org.apache.cxf.javascript.types.SchemaJavascriptBuilder;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.SchemaInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.transport.http.UrlUtilities;
+import org.apache.cxf.transports.http.StemMatchingQueryHandler;
+
+public class JavascriptQueryHandler implements StemMatchingQueryHandler {
+ private static final Logger LOG = LogUtils.getL7dLogger(JavascriptQueryHandler.class);
+ private static final Charset UTF8 = Charset.forName("utf-8");
+ private Bus bus;
+
+ public JavascriptQueryHandler(Bus b) {
+ bus = b;
+ LOG.finest("Bus " + bus);
+ }
+
+ public String getResponseContentType(String fullQueryString, String ctx) {
+ if (fullQueryString.toLowerCase().contains("?js")) {
+ return "application/javascript;charset=UTF-8";
+ }
+ return null;
+ }
+
+ public boolean isRecognizedQuery(String baseUri, String ctx, EndpointInfo endpointInfo,
+ boolean contextMatchExact) {
+ if (baseUri != null
+ && (baseUri.contains("?")
+ && (baseUri.toLowerCase().contains("js")))) {
+ int idx = baseUri.indexOf("?");
+ Map<String, String> map = UrlUtilities.parseQueryString(baseUri.substring(idx + 1));
+ if (map.containsKey("js")) {
+ try {
+ return endpointInfo.getAddress()
+ .contains(UrlUtilities.getStem(baseUri.substring(0, idx)));
+ } catch (MalformedURLException mue) {
+ LOG.log(Level.WARNING, "URL creation failed: ", mue);
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ public void writeResponse(String fullQueryString, String ctx, EndpointInfo endpoint, OutputStream os) {
+ OutputStreamWriter writer = new OutputStreamWriter(os, UTF8);
+ ServiceInfo serviceInfo = endpoint.getService();
+ Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
+ BasicNameManager nameManager = new BasicNameManager(serviceInfo);
+ NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
+ .getXmlSchemaCollection());
+ try {
+ for (SchemaInfo schema : schemata) {
+ SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
+ .getXmlSchemaCollection(), prefixManager, nameManager, schema);
+ String allThatJavascript = builder.generateCodeForSchema(schema);
+ writer.append(allThatJavascript);
+ }
+
+ ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, prefixManager,
+ nameManager);
+ serviceBuilder.walk();
+ String serviceJavascript = serviceBuilder.getCode();
+ writer.append(serviceJavascript);
+ } catch (IOException e) {
+ throw new UncheckedException(e);
+ }
+
+ }
+
+ public boolean isRecognizedQuery(String fullQueryString, String ctx, EndpointInfo endpoint) {
+ return isRecognizedQuery(fullQueryString, ctx, endpoint, false);
+ }
+}
Added: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandlerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandlerRegistry.java?rev=598071&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandlerRegistry.java (added)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandlerRegistry.java Sun Nov 25 14:29:46 2007
@@ -0,0 +1,49 @@
+/**
+ * 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.cxf.javascript;
+
+import javax.annotation.PostConstruct;
+import org.apache.cxf.Bus;
+import org.apache.cxf.transports.http.QueryHandlerRegistry;
+
+/**
+ *
+ */
+public class JavascriptQueryHandlerRegistry {
+ private Bus bus;
+
+
+ public JavascriptQueryHandlerRegistry() {
+ }
+ public JavascriptQueryHandlerRegistry(Bus b) {
+ bus = b;
+ }
+
+
+ @PostConstruct
+ public void register() {
+ if (bus != null) {
+ QueryHandlerRegistry registry = bus.getExtension(QueryHandlerRegistry.class);
+ if (registry != null) {
+ registry.registerHandler(new JavascriptQueryHandler(bus));
+ }
+ }
+ }
+}
Added: incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf-extension-javascript-client.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf-extension-javascript-client.xml?rev=598071&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf-extension-javascript-client.xml (added)
+++ incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf-extension-javascript-client.xml Sun Nov 25 14:29:46 2007
@@ -0,0 +1,30 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean class="org.apache.cxf.javascript.http.QueryHandlerRegistry"
+ id="org.apache.cxf.javascript.http.QueryHandlerRegistry"
+ lazy-init="true">
+ <constructor-arg ref="cxf"/>
+ </bean>
+</beans>
Added: incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf.extension
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf.extension?rev=598071&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf.extension (added)
+++ incubator/cxf/trunk/rt/javascript/src/main/resources/META-INF/cxf/cxf.extension Sun Nov 25 14:29:46 2007
@@ -0,0 +1 @@
+META-INF/cxf/cxf-extension-javascript-client.xml
\ No newline at end of file