Author: ningjiang
Date: Tue Apr 6 11:55:16 2010
New Revision: 931102
URL: http://svn.apache.org/viewvc?rev=931102&view=rev
Log:
CXF-2753 Applied patch with thanks to William.
Added:
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml
(with props)
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/DocLiteralInInterceptorTest.java
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java?rev=931102&r1=931101&r2=931102&view=diff
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
(original)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
Tue Apr 6 11:55:16 2010
@@ -48,6 +48,9 @@ import org.apache.cxf.staxutils.StaxUtil
import org.apache.ws.commons.schema.XmlSchemaElement;
public class DocLiteralInInterceptor extends AbstractInDatabindingInterceptor {
+ public static final String KEEP_PARAMETERS_WRAPPER =
DocLiteralInInterceptor.class.getName()
+ + ".DocLiteralInInterceptor.keep-parameters-wrapper";
+
private static final Logger LOG =
LogUtils.getL7dLogger(DocLiteralInInterceptor.class);
public DocLiteralInInterceptor() {
@@ -96,8 +99,8 @@ public class DocLiteralInInterceptor ext
// Wrapped case
MessageInfo msgInfo = setMessage(message, bop, client, si);
- // Determine if there is a wrapper class
- if (msgInfo.getMessageParts().get(0).getTypeClass() != null) {
+ // Determine if we should keep the parameters wrapper
+ if (shouldWrapParameters(msgInfo, message)) {
QName startQName = xmlReader.getName();
if
(!msgInfo.getMessageParts().get(0).getConcreteName().equals(startQName)) {
throw new Fault("UNEXPECTED_WRAPPER_ELEMENT", LOG,
null, startQName,
@@ -273,4 +276,13 @@ public class DocLiteralInInterceptor ext
}
return bop;
}
+
+ protected boolean shouldWrapParameters(MessageInfo msgInfo, Message
message) {
+ Object keepParametersWrapperFlag =
message.get(KEEP_PARAMETERS_WRAPPER);
+ if (keepParametersWrapperFlag == null) {
+ return msgInfo.getMessageParts().get(0).getTypeClass() != null;
+ } else {
+ return Boolean.parseBoolean(keepParametersWrapperFlag.toString());
+ }
+ }
}
Modified:
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/DocLiteralInInterceptorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/DocLiteralInInterceptorTest.java?rev=931102&r1=931101&r2=931102&view=diff
==============================================================================
---
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/DocLiteralInInterceptorTest.java
(original)
+++
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/DocLiteralInInterceptorTest.java
Tue Apr 6 11:55:16 2010
@@ -23,6 +23,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
@@ -31,6 +32,7 @@ import javax.xml.transform.dom.DOMSource
import org.apache.cxf.databinding.source.SourceDataBinding;
import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.XPathUtils;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
@@ -61,6 +63,7 @@ import org.junit.Test;
*/
public class DocLiteralInInterceptorTest extends Assert {
+ private static final String NS = "http://cxf.apache.org/wsdl-first/types";
protected IMocksControl control;
@Before
@@ -149,4 +152,101 @@ public class DocLiteralInInterceptorTest
assertEquals("IntParamInElem",
((DOMSource)params.get(1)).getNode().getFirstChild().getNodeName());
}
+
+
+ @Test
+ public void testUnmarshalSourceDataWrapped() throws Exception {
+ XMLStreamReader reader = StaxUtils.createXMLStreamReader(getClass()
+ .getResourceAsStream("resources/docLitWrappedReq.xml"));
+
+ assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
+
+ XMLStreamReader filteredReader = new PartialXMLStreamReader(reader,
+ new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"));
+
+ // advance the xml reader to the message parts
+ StaxUtils.read(filteredReader);
+ assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
+
+ Message m = new MessageImpl();
+ // request to keep the document as wrapped
+ m.put(DocLiteralInInterceptor.KEEP_PARAMETERS_WRAPPER, true);
+ Exchange exchange = new ExchangeImpl();
+
+ Service service = control.createMock(Service.class);
+ exchange.put(Service.class, service);
+ EasyMock.expect(service.getDataBinding()).andReturn(new
SourceDataBinding()).anyTimes();
+ EasyMock.expect(service.size()).andReturn(0).anyTimes();
+
+ Endpoint endpoint = control.createMock(Endpoint.class);
+ exchange.put(Endpoint.class, endpoint);
+
+ // wrapped
+ OperationInfo operationInfo = new OperationInfo();
+ MessageInfo messageInfo = new MessageInfo(operationInfo, Type.INPUT,
new QName(NS, "foo"));
+ messageInfo.addMessagePart(new MessagePartInfo(new QName(NS,
"personId"), null));
+ messageInfo.addMessagePart(new MessagePartInfo(new QName(NS, "ssn"),
null));
+ messageInfo.getMessagePart(0).setConcreteName(new QName(NS,
"personId"));
+ messageInfo.getMessagePart(1).setConcreteName(new QName(NS, "ssn"));
+ operationInfo.setInput("inputName", messageInfo);
+
+ // wrapper
+ OperationInfo operationInfoWrapper = new OperationInfo();
+ MessageInfo messageInfoWrapper = new MessageInfo(operationInfo,
Type.INPUT, new QName(NS, "foo"));
+ messageInfoWrapper.addMessagePart(new MessagePartInfo(new QName(NS,
"GetPerson"), null));
+ messageInfoWrapper.getMessagePart(0).setConcreteName(new QName(NS,
"GetPerson"));
+ operationInfoWrapper.setInput("inputName", messageInfoWrapper);
+ operationInfoWrapper.setUnwrappedOperation(operationInfo);
+
+ ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
+
+ EasyMock.expect(serviceInfo.getName()).andReturn(new
QName("http://foo.com", "service")).anyTimes();
+ InterfaceInfo interfaceInfo = control.createMock(InterfaceInfo.class);
+
EasyMock.expect(serviceInfo.getInterface()).andReturn(interfaceInfo).anyTimes();
+ EasyMock.expect(interfaceInfo.getName()).andReturn(new
QName("http://foo.com", "interface"))
+ .anyTimes();
+
+ BindingInfo bindingInfo = new BindingInfo(serviceInfo, "");
+ BindingOperationInfo boi = new BindingOperationInfo(bindingInfo,
operationInfoWrapper);
+ exchange.put(BindingOperationInfo.class, boi);
+
+ EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
+ BindingInfo binding = control.createMock(BindingInfo.class);
+
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
+
EasyMock.expect(endpointInfo.getBinding()).andReturn(binding).anyTimes();
+ EasyMock.expect(binding.getProperties()).andReturn(new HashMap<String,
Object>()).anyTimes();
+ EasyMock.expect(endpointInfo.getProperties()).andReturn(new
HashMap<String, Object>()).anyTimes();
+ EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
+
EasyMock.expect(endpointInfo.getService()).andReturn(serviceInfo).anyTimes();
+
+ EasyMock.expect(endpointInfo.getName()).andReturn(new
QName("http://foo.com", "endpoint")).anyTimes();
+ EasyMock.expect(endpointInfo.getProperty("URI",
URI.class)).andReturn(new URI("dummy")).anyTimes();
+
+ List<OperationInfo> operations = new ArrayList<OperationInfo>();
+
EasyMock.expect(interfaceInfo.getOperations()).andReturn(operations).anyTimes();
+
+ m.setExchange(exchange);
+ m.put(Message.SCHEMA_VALIDATION_ENABLED, false);
+ m.setContent(XMLStreamReader.class, reader);
+
+ control.replay();
+
+ new DocLiteralInInterceptor().handleMessage(m);
+
+ MessageContentsList params =
(MessageContentsList)m.getContent(List.class);
+
+ // we expect a wrapped document
+ assertEquals(1, params.size());
+
+ Map<String, String> ns = new HashMap<String, String>();
+ ns.put("ns", NS);
+
+ XPathUtils xu = new XPathUtils(ns);
+ assertEquals("hello", xu.getValueString("//ns:GetPerson/ns:personId",
+
((DOMSource)params.get(0)).getNode().getFirstChild()));
+ assertEquals("1234", xu.getValueString("//ns:GetPerson/ns:ssn",
+
((DOMSource)params.get(0)).getNode().getFirstChild()));
+
+ }
+
}
Added:
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml?rev=931102&view=auto
==============================================================================
---
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml
(added)
+++
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml
Tue Apr 6 11:55:16 2010
@@ -0,0 +1,27 @@
+<?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.
+-->
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <GetPerson xmlns="http://cxf.apache.org/wsdl-first/types">
+ <personId>hello</personId>
+ <ssn>1234</ssn>
+ </GetPerson>
+ </soap:Body>
+</soap:Envelope>
\ No newline at end of file
Propchange:
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/interceptor/resources/docLitWrappedReq.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml