Author: sergeyb
Date: Thu Sep 2 11:21:57 2010
New Revision: 991893
URL: http://svn.apache.org/viewvc?rev=991893&view=rev
Log:
[CXF-2967] Support the unwrapping of JAXB responses for Dispatch
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceUnwrap.java
(with props)
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersUnwrap.java
(with props)
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbers.java
(with props)
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbersResponse.java
(with props)
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/package-info.java
(with props)
Modified:
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
Modified:
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java?rev=991893&r1=991892&r2=991893&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
(original)
+++
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
Thu Sep 2 11:21:57 2010
@@ -68,6 +68,11 @@ public class DataReaderImpl<T> extends J
veventHandler = databinding.getValidationEventHandler();
}
setEventHandler = MessageUtils.getContextualBoolean(m,
"set-jaxb-validation-event-handler", true);
+
+ Object unwrapProperty = m.get(JAXBDataBinding.UNWRAP_JAXB_ELEMENT);
+ if (unwrapProperty != null) {
+ unwrapJAXBElement = Boolean.TRUE.equals(unwrapProperty);
+ }
}
}
private Unmarshaller createUnmarshaller() {
@@ -106,9 +111,10 @@ public class DataReaderImpl<T> extends J
public Object read(MessagePartInfo part, T reader) {
boolean honorJaxbAnnotation = false;
- if (part != null && part.getProperty("honor.jaxb.annotations") !=
null) {
+ if (part != null && part.getProperty("honor.jaxb.annotations") !=
null) {
honorJaxbAnnotation =
(Boolean)part.getProperty("honor.jaxb.annotations");
}
+
Annotation[] anns = null;
if (honorJaxbAnnotation) {
Modified:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java?rev=991893&r1=991892&r2=991893&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
(original)
+++
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
Thu Sep 2 11:21:57 2010
@@ -29,6 +29,7 @@ import java.util.logging.Logger;
import javax.activation.DataSource;
import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
@@ -275,6 +276,9 @@ public class DispatchImpl<T> implements
if (msg.countAttachments() > 0) {
client.getRequestContext().put(AttachmentOutInterceptor.WRITE_ATTACHMENTS,
Boolean.TRUE);
}
+ } else if (context != null) {
+ Boolean unwrapProperty = obj instanceof JAXBElement ?
Boolean.FALSE : Boolean.TRUE;
+ getRequestContext().put("unwrap.jaxb.element", unwrapProperty);
}
QName opName =
(QName)getRequestContext().get(MessageContext.WSDL_OPERATION);
Modified:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java?rev=991893&r1=991892&r2=991893&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
(original)
+++
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
Thu Sep 2 11:21:57 2010
@@ -661,7 +661,6 @@ public class ServiceImpl extends Service
AbstractServiceFactoryBean sf = null;
try {
JAXBDataBinding db = new JAXBDataBinding(context);
- db.setUnwrapJAXBElement(false);
sf = createDispatchService(db);
} catch (ServiceConstructionException e) {
throw new WebServiceException(e);
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceUnwrap.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceUnwrap.java?rev=991893&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceUnwrap.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceUnwrap.java
Thu Sep 2 11:21:57 2010
@@ -0,0 +1,85 @@
+/**
+ * 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.systest.handlers;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebEndpoint;
+import javax.xml.ws.WebServiceClient;
+import javax.xml.ws.WebServiceFeature;
+
+//CHECKSTYLE:OFF
+...@webserviceclient(name = "AddNumbersService",
+ wsdlLocation = "/wsdl/addNumbers.wsdl",
+ targetNamespace = "http://apache.org/handlers")
+public class AddNumbersServiceUnwrap extends Service {
+
+ public final static URL WSDL_LOCATION;
+ public final static QName SERVICE = new
QName("http://apache.org/handlers", "AddNumbersService");
+ public final static QName AddNumbersPort = new
QName("http://apache.org/handlers", "AddNumbersPort");
+ static {
+ URL url = null;
+ try {
+ url = new URL("/wsdl/addNumbers.wsdl");
+ } catch (MalformedURLException e) {
+ System.err.println("Can not initialize the default wsdl from
file:/home/sberyozkin/work/cxf/trunk/testutils/src/main/resources/wsdl/addNumbers.wsdl");
+ // e.printStackTrace();
+ }
+ WSDL_LOCATION = url;
+ }
+
+ public AddNumbersServiceUnwrap(URL wsdlLocation) {
+ super(wsdlLocation, SERVICE);
+ }
+
+ public AddNumbersServiceUnwrap(URL wsdlLocation, QName serviceName) {
+ super(wsdlLocation, serviceName);
+ }
+
+ public AddNumbersServiceUnwrap() {
+ super(WSDL_LOCATION, SERVICE);
+ }
+
+
+ /**
+ *
+ * @return
+ * returns AddNumbers
+ */
+ @WebEndpoint(name = "AddNumbersPort")
+ public AddNumbersUnwrap getAddNumbersPort() {
+ return super.getPort(AddNumbersPort, AddNumbersUnwrap.class);
+ }
+
+ /**
+ *
+ * @param features
+ * A list of {...@link javax.xml.ws.WebServiceFeature} to configure on
the proxy. Supported features not in the <code>features</code> parameter will
have their default values.
+ * @return
+ * returns AddNumbers
+ */
+ @WebEndpoint(name = "AddNumbersPort")
+ public AddNumbersUnwrap getAddNumbersPort(WebServiceFeature... features) {
+ return super.getPort(AddNumbersPort, AddNumbersUnwrap.class, features);
+ }
+
+}
+//CHECKSTYLE:ON
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceUnwrap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersServiceUnwrap.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersUnwrap.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersUnwrap.java?rev=991893&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersUnwrap.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersUnwrap.java
Thu Sep 2 11:21:57 2010
@@ -0,0 +1,45 @@
+/**
+ * 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.systest.handlers;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebResult;
+import javax.jws.WebService;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.ResponseWrapper;
+
+//CHECKSTYLE:OFF
+...@webservice(targetNamespace = "http://apache.org/handlers", name =
"AddNumbers")
+public interface AddNumbersUnwrap {
+
+ @WebResult(name = "return", targetNamespace =
"http://apache.org/handlers/types")
+ @RequestWrapper(localName = "addNumbers", targetNamespace =
"http://apache.org/handlers/types",
+ className =
"org.apache.cxf.systest.handlers.types.AddNumbers")
+ @WebMethod
+ @ResponseWrapper(localName = "addNumbersResponse", targetNamespace =
"http://apache.org/handlers/types",
+ className =
"org.apache.cxf.systest.handlers.types.AddNumbersResponse")
+ public int addNumbers(
+ @WebParam(name = "arg0", targetNamespace =
"http://apache.org/handlers/types")
+ int arg0,
+ @WebParam(name = "arg1", targetNamespace =
"http://apache.org/handlers/types")
+ int arg1
+ );
+}
+//CHECKSTYLE:ON
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersUnwrap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/AddNumbersUnwrap.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java?rev=991893&r1=991892&r2=991893&view=diff
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
(original)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
Thu Sep 2 11:21:57 2010
@@ -108,6 +108,37 @@ public class DispatchHandlerInvocationTe
AddNumbersResponse value = (AddNumbersResponse)response.getValue();
assertEquals(222, value.getReturn());
}
+
+ @Test
+ public void testInvokeWithJAXBUnwrapPayloadMode() throws Exception {
+ URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+ assertNotNull(wsdl);
+
+ org.apache.cxf.systest.handlers.AddNumbersServiceUnwrap service =
+ new org.apache.cxf.systest.handlers.AddNumbersServiceUnwrap(wsdl,
serviceName);
+ assertNotNull(service);
+
+ JAXBContext jc = JAXBContext.newInstance(
+ org.apache.cxf.systest.handlers.types.AddNumbers.class,
+ org.apache.cxf.systest.handlers.types.AddNumbersResponse.class);
+
+ Dispatch<Object> disp = service.createDispatch(portName, jc,
Service.Mode.PAYLOAD);
+ setAddress(disp, addNumbersAddress);
+
+ TestHandler handler = new TestHandler();
+ TestSOAPHandler soapHandler = new TestSOAPHandler();
+ addHandlersProgrammatically(disp, handler, soapHandler);
+
+ org.apache.cxf.systest.handlers.types.AddNumbers req =
+ new org.apache.cxf.systest.handlers.types.AddNumbers();
+ req.setArg0(10);
+ req.setArg1(20);
+
+ org.apache.cxf.systest.handlers.types.AddNumbersResponse response =
+
(org.apache.cxf.systest.handlers.types.AddNumbersResponse)disp.invoke(req);
+ assertNotNull(response);
+ assertEquals(222, response.getReturn());
+ }
@Test
public void testInvokeWithDOMSourcMessageMode() throws Exception {
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbers.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbers.java?rev=991893&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbers.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbers.java
Thu Sep 2 11:21:57 2010
@@ -0,0 +1,93 @@
+/**
+ * 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.systest.handlers.types;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for addNumbers complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained
within this class.
+ *
+ * <pre>
+ * <complexType name="addNumbers">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="arg0"
type="{http://www.w3.org/2001/XMLSchema}int"/>
+ * <element name="arg1"
type="{http://www.w3.org/2001/XMLSchema}int"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+//CHECKSTYLE:OFF
+...@xmlrootelement(name = "addNumbers",
+ namespace = "http://apache.org/handlers/types")
+...@xmlaccessortype(XmlAccessType.FIELD)
+...@xmltype(name = "addNumbers", propOrder = {
+ "arg0",
+ "arg1"
+})
+public class AddNumbers {
+
+ protected int arg0;
+ protected int arg1;
+
+ /**
+ * Gets the value of the arg0 property.
+ *
+ */
+ public int getArg0() {
+ return arg0;
+ }
+
+ /**
+ * Sets the value of the arg0 property.
+ *
+ */
+ public void setArg0(int value) {
+ this.arg0 = value;
+ }
+
+ /**
+ * Gets the value of the arg1 property.
+ *
+ */
+ public int getArg1() {
+ return arg1;
+ }
+
+ /**
+ * Sets the value of the arg1 property.
+ *
+ */
+ public void setArg1(int value) {
+ this.arg1 = value;
+ }
+
+}
+//CHECKSTYLE:ON
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbers.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbers.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbersResponse.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbersResponse.java?rev=991893&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbersResponse.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbersResponse.java
Thu Sep 2 11:21:57 2010
@@ -0,0 +1,77 @@
+/**
+ * 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.systest.handlers.types;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for addNumbersResponse complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained
within this class.
+ *
+ * <pre>
+ * <complexType name="addNumbersResponse">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="return"
type="{http://www.w3.org/2001/XMLSchema}int"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+//CHECKSTYLE:OFF
+...@xmlrootelement(name = "addNumbersResponse",
+ namespace = "http://apache.org/handlers/types")
+...@xmlaccessortype(XmlAccessType.FIELD)
+...@xmltype(name = "addNumbersResponse", propOrder = {
+ "_return"
+})
+public class AddNumbersResponse {
+
+ @XmlElement(name = "return")
+ protected int _return;
+
+ /**
+ * Gets the value of the return property.
+ *
+ */
+ public int getReturn() {
+ return _return;
+ }
+
+ /**
+ * Sets the value of the return property.
+ *
+ */
+ public void setReturn(int value) {
+ this._return = value;
+ }
+
+}
+//CHECKSTYLE:ON
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbersResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/AddNumbersResponse.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/package-info.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/package-info.java?rev=991893&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/package-info.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/package-info.java
Thu Sep 2 11:21:57 2010
@@ -0,0 +1,4 @@
+//CHECKSTYLE:OFF
[email protected](namespace =
"http://apache.org/handlers/types", elementFormDefault =
javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.cxf.systest.handlers.types;
+//CHECKSTYLE:ON
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/types/package-info.java
------------------------------------------------------------------------------
svn:keywords = Rev Date