Author: jliu
Date: Sun Aug 12 22:58:58 2007
New Revision: 565248
URL: http://svn.apache.org/viewvc?view=rev&rev=565248
Log:
CXF-903. Fixed a problem using HTTP binding REST in wrapped style.
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/resources/expected_get_book123_xmlwrapped.txt
(with props)
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrapped.java
(with props)
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrappedImpl.java
(with props)
Modified:
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/BookServer.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
Modified:
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java?view=diff&rev=565248&r1=565247&r2=565248
==============================================================================
---
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
(original)
+++
incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
Sun Aug 12 22:58:58 2007
@@ -43,6 +43,7 @@
import org.apache.ws.commons.schema.XmlSchemaAnnotated;
import org.apache.ws.commons.schema.XmlSchemaComplexType;
import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaForm;
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.XmlSchemaSimpleType;
import org.apache.ws.commons.schema.XmlSchemaType;
@@ -186,11 +187,21 @@
}
return null;
}
+
+ private static boolean findSchemaUnQualified(Collection<SchemaInfo>
schemas, QName name) {
+ for (SchemaInfo inf : schemas) {
+ if (inf.getNamespaceURI().equals(name.getNamespaceURI())) {
+ return
inf.getSchema().getElementFormDefault().getValue().equals(XmlSchemaForm.UNQUALIFIED);
+ }
+ }
+ //Unqualified by default
+ return true;
+ }
/**
* Create a dom document conformant with the given schema element with the
* input parameters.
- *
+ *
* @param element
* @param params
* @return
@@ -201,11 +212,14 @@
XmlSchemaElement element = null;
QName qname = null;
+ boolean unQualified = false;
+
XmlSchemaComplexType cplxType = null;
if (schemaAnnotation instanceof XmlSchemaElement) {
element = (XmlSchemaElement)schemaAnnotation;
qname = element.getQName();
cplxType = (XmlSchemaComplexType)element.getSchemaType();
+ unQualified = findSchemaUnQualified(schemas,
element.getSchemaTypeName());
if (cplxType == null) {
cplxType = (XmlSchemaComplexType)findSchemaType(schemas,
element.getSchemaTypeName());
}
@@ -237,11 +251,17 @@
break;
}
}
- Element ec =
doc.createElementNS(elChild.getQName().getNamespaceURI(), elChild.getQName()
- .getLocalPart());
- if
(!elChild.getQName().getNamespaceURI().equals(qname.getNamespaceURI())) {
- ec.setAttribute(XMLConstants.XMLNS_ATTRIBUTE,
elChild.getQName().getNamespaceURI());
+ Element ec = null;
+ if (unQualified) {
+ ec = doc.createElement(elChild.getQName().getLocalPart());
+ } else {
+ ec = doc.createElementNS(elChild.getQName().getNamespaceURI(),
elChild.getQName()
+ .getLocalPart());
+ if
(!elChild.getQName().getNamespaceURI().equals(qname.getNamespaceURI())) {
+ ec.setAttribute(XMLConstants.XMLNS_ATTRIBUTE,
elChild.getQName().getNamespaceURI());
+ }
}
+
if (param != null) {
params.remove(param);
ec.appendChild(doc.createTextNode(param.getValue()));
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/BookServer.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/BookServer.java?view=diff&rev=565248&r1=565247&r2=565248
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/BookServer.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/BookServer.java
Sun Aug 12 22:58:58 2007
@@ -28,6 +28,8 @@
import org.apache.cxf.binding.http.HttpBindingFactory;
import org.apache.cxf.customer.book.BookService;
import org.apache.cxf.customer.book.BookServiceImpl;
+import org.apache.cxf.customer.book.BookServiceWrapped;
+import org.apache.cxf.customer.book.BookServiceWrappedImpl;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.service.invoker.BeanInvoker;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -37,6 +39,7 @@
public class BookServer extends AbstractBusTestServerBase {
protected void run() {
+ //book service in unwrapped style
BookServiceImpl serviceObj = new BookServiceImpl();
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(BookService.class);
@@ -52,6 +55,17 @@
sf.getServiceFactory().setWrapped(false);
sf.create();
+
+ //book service in wrapped style
+ BookServiceWrappedImpl serviceWrappedObj = new
BookServiceWrappedImpl();
+ JaxWsServerFactoryBean sfWrapped = new JaxWsServerFactoryBean();
+ sfWrapped.setServiceClass(BookServiceWrapped.class);
+ // Use the HTTP Binding which understands the Java Rest Annotations
+ sfWrapped.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
+ sfWrapped.setAddress("http://localhost:9080/xmlwrapped");
+ sfWrapped.getServiceFactory().setInvoker(new
BeanInvoker(serviceWrappedObj));
+ sfWrapped.create();
+
JaxWsServerFactoryBean sfJson = new JaxWsServerFactoryBean();
sfJson.setServiceClass(BookService.class);
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java?view=diff&rev=565248&r1=565247&r2=565248
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
Sun Aug 12 22:58:58 2007
@@ -89,6 +89,20 @@
assertEquals(book.getName(), "CXF in Action");
}
+ @Test
+ public void testGetBookWrapped() throws Exception {
+ String endpointAddress =
+ "http://localhost:9080/xmlwrapped/books/123";
+ URL url = new URL(endpointAddress);
+ InputStream in = url.openStream();
+ assertNotNull(in);
+
+ InputStream expected = getClass()
+
.getResourceAsStream("resources/expected_get_book123_xmlwrapped.txt");
+
+ //System.out.println("---" + getStringFromInputStream(in));
+ assertEquals(getStringFromInputStream(expected),
getStringFromInputStream(in));
+ }
@Test
public void testGetBooksJSON() throws Exception {
@@ -150,7 +164,7 @@
IOUtils.copy(in, bos);
in.close();
bos.close();
- System.out.println(bos.getOut().toString());
+ //System.out.println(bos.getOut().toString());
return bos.getOut().toString();
}
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/resources/expected_get_book123_xmlwrapped.txt
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/resources/expected_get_book123_xmlwrapped.txt?view=auto&rev=565248
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/resources/expected_get_book123_xmlwrapped.txt
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/resources/expected_get_book123_xmlwrapped.txt
Sun Aug 12 22:58:58 2007
@@ -0,0 +1 @@
+<ns1:getBookResponse xmlns:ns1="http://book.customer.cxf.apache.org/"><Book
xmlns="http://book.acme.com"><id>123</id><name>CXF in
Action</name></Book></ns1:getBookResponse>
\ No newline at end of file
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/resources/expected_get_book123_xmlwrapped.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/resources/expected_get_book123_xmlwrapped.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrapped.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrapped.java?view=auto&rev=565248
==============================================================================
---
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrapped.java
(added)
+++
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrapped.java
Sun Aug 12 22:58:58 2007
@@ -0,0 +1,38 @@
+/**
+ * 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.customer.book;
+
+
+import javax.jws.WebParam;
+import javax.jws.WebService;
+
+import org.codehaus.jra.Get;
+import org.codehaus.jra.HttpResource;
+
+
[EMAIL PROTECTED](targetNamespace = "http://book.customer.cxf.apache.org/")
+public interface BookServiceWrapped {
+
+ @Get
+ @HttpResource(location = "/books/{id}")
+ Book getBook(@WebParam(name = "id")long bookid) throws BookNotFoundFault;
+
+
+}
Propchange:
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrapped.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrapped.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrappedImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrappedImpl.java?view=auto&rev=565248
==============================================================================
---
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrappedImpl.java
(added)
+++
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrappedImpl.java
Sun Aug 12 22:58:58 2007
@@ -0,0 +1,64 @@
+/**
+ * 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.customer.book;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jws.WebService;
+
+
[EMAIL PROTECTED](endpointInterface =
"org.apache.cxf.customer.book.BookService")
+public class BookServiceWrappedImpl implements BookServiceWrapped {
+ long currentId = 1;
+ Map books = new HashMap();
+
+ @SuppressWarnings("unchecked")
+ public BookServiceWrappedImpl() {
+ Book book = createBook();
+ System.out.println("Enregistre Book de id " + book.getId());
+ books.put(book.getId(), book);
+ }
+
+ public Book getBook(long bookid) throws BookNotFoundFault {
+ for (Iterator iter = books.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry me = (Map.Entry)iter.next();
+ System.out.println("getBook -> " + me.getKey() + " : "
+ + ((Book)me.getValue()).getName() + ", " +
((Book)me.getValue()).getId());
+ }
+ System.out.println("Book de id " + bookid);
+ Book b = (Book)books.get(bookid);
+
+ if (b == null) {
+ BookNotFoundDetails details = new BookNotFoundDetails();
+ details.setId(bookid);
+ throw new BookNotFoundFault(details);
+ }
+ return b;
+ }
+
+ final Book createBook() {
+ Book b = new Book();
+ b.setName("CXF in Action");
+ b.setId(123);
+ return b;
+ }
+}
Propchange:
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrappedImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/testutils/src/main/java/org/apache/cxf/customer/book/BookServiceWrappedImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date