You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2006/12/14 14:02:20 UTC
svn commit: r487198 - in
/webservices/axis2/branches/java/WSDL_2_0/modules/kernel:
src/org/apache/axis2/transport/http/ src/org/apache/axis2/util/
test/org/apache/axis2/util/
Author: chinthaka
Date: Thu Dec 14 05:02:19 2006
New Revision: 487198
URL: http://svn.apache.org/viewvc?view=rev&rev=487198
Log:
Fixing the server side code to pickup url templating. Now our rest handling logic will pickup httpLocation with templates.
I only fixed to pick up from "?last={LastName}" sort of scenario where the templating is only within the query parameter. Will fix this to pick up something like /blah/{Foo}/blah as well.
Added:
webservices/axis2/branches/java/WSDL_2_0/modules/kernel/test/org/apache/axis2/util/SchemaUtilTest.java
Modified:
webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/SchemaUtil.java
Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java?view=diff&rev=487198&r1=487197&r2=487198
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java Thu Dec 14 05:02:19 2006
@@ -116,7 +116,6 @@
} catch (AxisFault axisFault) {
log.info(axisFault.getMessage());
}
-
}
/**
Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java?view=diff&rev=487198&r1=487197&r2=487198
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java Thu Dec 14 05:02:19 2006
@@ -225,6 +225,7 @@
OMElement httpURLParam = parentElement.getFirstChildWithName(new QName(elementName));
if (httpURLParam != null) {
+ httpURLParam.detach();
return httpURLParam.getText();
}
Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/SchemaUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/SchemaUtil.java?view=diff&rev=487198&r1=487197&r2=487198
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/SchemaUtil.java (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/SchemaUtil.java Thu Dec 14 05:02:19 2006
@@ -21,6 +21,9 @@
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.AxisBindingOperation;
+import org.apache.axis2.description.WSDL2Constants;
import org.apache.axis2.context.MessageContext;
import org.apache.ws.commons.schema.XmlSchemaComplexType;
import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -37,6 +40,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
+
/**
*
*/
@@ -113,6 +117,9 @@
}
} else {
+ // first get the target namespace from the schema and the wrapping element.
+ // create an OMElement out of those information. We are going to extract parameters from
+ // url, create OMElements and add them as children to this wrapping element.
String targetNamespace = xmlSchemaElement.getQName().getNamespaceURI();
QName bodyFirstChildQName;
if (targetNamespace != null && !"".equals(targetNamespace)) {
@@ -122,9 +129,13 @@
}
OMElement bodyFirstChild = soapFactory.createOMElement(bodyFirstChildQName, body);
+ // we handle only GET and POST methods. Do a sanity check here, first
String httpMethod = request.getMethod();
if (org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD_POST.equals(httpMethod)
- || (org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD_GET.equals(httpMethod))) {
+ || (org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD_GET.equals(httpMethod)))
+ {
+ // Schema should adhere to the IRI style in this. So assume IRI style and dive in to
+ // schema
XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
if (schemaType instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
@@ -133,24 +144,61 @@
XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) particle;
Iterator iterator = xmlSchemaSequence.getItems().getIterator();
+ // now we need to know some information from the binding operation.
+
+ // First retrieve the binding operations from message context
+ AxisBindingOperation axisBindingOperation = (AxisBindingOperation) msgCtxt.getProperty(Constants.AXIS_BINDING_OPERATION);
+
+ // Now we are going to extrac information from the binding operation. WSDL 2.0
+ // http bindiing allows to define a query parameter separator. To capture it
+ // create a variable wit the default as "&"
+ String queryParameterSeparator = "&";
+
+ Map httpLocationParameterMap = new HashMap(1);
+ if (axisBindingOperation != null) {
+
+ // now check whether we have a query parameter separator defined in this
+ // operation
+ String queryParamSeparatorTemp = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
+ if (queryParamSeparatorTemp != null && !"".equals(queryParamSeparatorTemp))
+ {
+ queryParameterSeparator = queryParamSeparatorTemp;
+ }
+
+ // get the http location property
+ String httpLocation = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION);
+
+ // parameter names can be different from the element name in the schema, due
+ // to http location. Let's filter the parameter names from it.
+ httpLocationParameterMap = createHttpLocationParameterMap(httpLocation, queryParameterSeparator);
+
+ }
+
Map parameterMap = request.getParameterMap();
while (iterator.hasNext()) {
XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
QName qName = innerElement.getQName();
String name = qName != null ? qName.getLocalPart() : innerElement.getName();
+
+ // check whether this has a mapping in httpLocationParameterMap.
+ String mappingParamName = (String) httpLocationParameterMap.get(name);
+ if (mappingParamName != null) {
+ name = mappingParamName;
+ }
+
String[] parameterValuesArray = (String[]) parameterMap.get(name);
if (parameterValuesArray != null &&
- !"".equals(parameterValuesArray[0]) && parameterValuesArray[0] != null)
+ !"".equals(parameterValuesArray[0]) && parameterValuesArray[0] != null)
{
OMNamespace ns = (qName == null || qName.getNamespaceURI() == null || qName.getNamespaceURI().length() == 0) ?
null :
soapFactory.createOMNamespace(qName.getNamespaceURI(), null);
soapFactory.createOMElement(name, ns,
- bodyFirstChild).setText(parameterValuesArray[0]);
+ bodyFirstChild).setText(parameterValuesArray[0]);
} else {
throw new AxisFault("Required element " + qName +
- " defined in the schema can not be found in the request");
+ " defined in the schema can not be found in the request");
}
}
}
@@ -161,5 +209,44 @@
}
return soapEnvelope;
+ }
+
+ /**
+ * WSDL 2.0 HTTP binding introduces the concept of http location. User can provide some thing like
+ * ?first={FirstName}, where FirstName is what is defined in the schema. In this case, when you
+ * want to get the parameter value from the request parameter map, you have to ask for "first" and
+ * not "FirstName".
+ * <p/>
+ * This method will create a map from the schema name to the name visible in the query string.
+ * Eg: FirstName ==> first
+ *
+ * @param httpLocation
+ * @param queryParameterSeparator
+ */
+ protected static Map createHttpLocationParameterMap(String httpLocation, String queryParameterSeparator) {
+
+ Map httpLocationParameterMap = new HashMap();
+ // if there is a questions mark in the front, remove it
+ if (httpLocation.startsWith("?")) {
+ httpLocation = httpLocation.substring(1, httpLocation.length());
+ }
+
+// now let's tokenize the string with query parameter separator
+ String[] nameValuePairs = httpLocation.split(queryParameterSeparator);
+ for (int i = 0; i < nameValuePairs.length; i++) {
+ StringBuffer buffer = new StringBuffer(nameValuePairs[i]);
+ // this name value pair will be either name=value or
+ // name={SchemaElementName}. The first case is handled above
+ // let's handle the second case
+ if (buffer.indexOf("{") > 0 && buffer.indexOf("}") > 0) {
+ String parameterName = buffer.substring(0, buffer.indexOf("="));
+ String schemaElementName = buffer.substring(buffer.indexOf("=") + 2, buffer.length() - 1);
+ httpLocationParameterMap.put(schemaElementName, parameterName);
+
+ }
+
+ }
+
+ return httpLocationParameterMap;
}
}
Added: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/test/org/apache/axis2/util/SchemaUtilTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/test/org/apache/axis2/util/SchemaUtilTest.java?view=auto&rev=487198
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/test/org/apache/axis2/util/SchemaUtilTest.java (added)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/test/org/apache/axis2/util/SchemaUtilTest.java Thu Dec 14 05:02:19 2006
@@ -0,0 +1,32 @@
+package org.apache.axis2.util;
+
+import junit.framework.TestCase;
+
+import java.util.Map;
+/*
+ * 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.
+ */
+
+public class SchemaUtilTest extends TestCase {
+
+ String httpLocation = "?test=1&last={LastName}&firstNamePart={FirstName}";
+
+ public void testCreateHttpLocationParameterMap() {
+ Map httpLocationParameterMap = SchemaUtil.createHttpLocationParameterMap(httpLocation, "&");
+ assertEquals("firstNamePart", httpLocationParameterMap.get("FirstName"));
+ assertEquals("last", httpLocationParameterMap.get("LastName"));
+ assertTrue(httpLocationParameterMap.size() == 2);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org