cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <daniel.k...@iona.com>
Subject Re: svn commit: r440967 - in /incubator/cxf/trunk/rt/bindings/xml: ./ src/main/java/org/apache/cxf/binding/xml/interceptor/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/cxf/ src/test/java/org/apache/cxf/binding/ src/test/java/org/a...
Date Thu, 07 Sep 2006 14:14:23 GMT

This commit has introduced some warnings during the build:

[WARNING] /home/dkulp/working/cxf/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptorTest.java:
[84,18] [unchecked] unchecked call to add(E) as a member of the raw type 
java.util.List

[WARNING] /home/dkulp/working/cxf/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptorTest.java:
[112,18] [unchecked] unchecked call to add(E) as a member of the raw type 
java.util.List

[WARNING] /home/dkulp/working/cxf/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptorTest.java:
[113,18] [unchecked] unchecked call to add(E) as a member of the raw type 
java.util.List

[WARNING] /home/dkulp/working/cxf/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptorTest.java:
[154,18] [unchecked] unchecked call to add(E) as a member of the raw type 
java.util.List


ALL uses of the collection classes should be properly typed.   The line:
List params = new ArrayList();
is not allowed.   The list should be properly typed.


Dan



On Wednesday September 06 2006 11:51 pm, tli@apache.org wrote:
> Author: tli
> Date: Wed Sep  6 20:51:53 2006
> New Revision: 440967
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=440967
> Log:
> add unit test for xml in/out interceptors
>
> Added:
>    
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/Messages.properties   (with props)
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/
>     incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/
>     incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/
>    
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/TestBase.java   (with props)
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptorTest.java   (with props)
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptorTest.java   (with props) Modified:
>     incubator/cxf/trunk/rt/bindings/xml/.checkstyle
>    
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptor.java
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptor.java
> incubator/cxf/trunk/rt/bindings/xml/src/test/resources/message-wrap.xml
>
> Modified: incubator/cxf/trunk/rt/bindings/xml/.checkstyle
> URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/.checkstyl
>e?view=diff&rev=440967&r1=440966&r2=440967
> ===========================================================================
>=== --- incubator/cxf/trunk/rt/bindings/xml/.checkstyle (original)
> +++ incubator/cxf/trunk/rt/bindings/xml/.checkstyle Wed Sep  6 20:51:53
> 2006 @@ -1,4 +1,6 @@
> -<?xml version="1.0" encoding="UTF-8"?><fileset-config
> file-format-version="1.1.0" simple-config="false"> -<fileset name="all"
> enabled="true" check-config-name="CXF Checks" type="external"
> description=""><file-match-pattern match-pattern="^src[/\\]."
> include-pattern="true"/> -</fileset>
> -</fileset-config>
> \ No newline at end of file
> +<?xml version="1.0" encoding="UTF-8"?>
> +<fileset-config file-format-version="1.2.0" simple-config="false">
> +    <fileset name="all" enabled="true" check-config-name="CXF"
> local="false"> +        <file-match-pattern match-pattern="^src[/\\]."
> include-pattern="true"/> +    </fileset>
> +</fileset-config>
>
> Added:
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/Messages.properties URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/j
>ava/org/apache/cxf/binding/xml/interceptor/Messages.properties?view=auto&rev
>=440967
> ===========================================================================
>=== ---
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/Messages.properties (added) +++
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/Messages.properties Wed Sep  6 20:51:53 2006 @@ -0,0 +1,8 @@
> +STREAM_CREATE_EXC = Could not create XMLStreamReader.
> +STAX_READ_EXC = Could not read from XMLStreamReader.
> +STAX_WRITE_EXC = Could not write from XMLStreamReader.
> +NO_OPERATION_ELEMENT=There must be an operation element.
> +NO_OPERATION=No such operation: {0}
> +NO_DATAREADER=No DataReader is available for Service: {0}
> +NO_DATAWRITER=No DataWriter is available for Service: {0}
> +COULD_NOT_UNRWAP=Could not unrwap message parts.
> \ No newline at end of file
>
> Propchange:
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/Messages.properties
> ---------------------------------------------------------------------------
>--- svn:eol-style = native
>
> Propchange:
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/Messages.properties
> ---------------------------------------------------------------------------
>--- svn:mime-type = text/plain
>
> Modified:
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptor.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/j
>ava/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java?view
>=diff&rev=440967&r1=440966&r2=440967
> ===========================================================================
>=== ---
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptor.java (original) +++
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptor.java Wed Sep  6 20:51:53 2006 @@ -19,6
> +19,8 @@
>
>  package org.apache.cxf.binding.xml.interceptor;
>
> +import java.util.HashMap;
> +import java.util.Map;
>  import java.util.ResourceBundle;
>
>  import javax.xml.namespace.QName;
> @@ -50,31 +52,16 @@
>          DepthXMLStreamReader dxsr = new DepthXMLStreamReader(xsr);
>          Endpoint ep = message.getExchange().get(Endpoint.class);
>          BindingInfo service = ep.getEndpointInfo().getBinding();
> -
> +        Map<Class<?>, Object> objMap = new HashMap<Class<?>, Object>();
>          // StaxUtils.nextEvent(xmlReader);
>          if (!StaxUtils.toNextElement(dxsr)) {
>              throw new Fault(new
> org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT", BUNDLE)); }
>          QName startQName = new QName(dxsr.getNamespaceURI(),
> dxsr.getLocalName()); for (BindingOperationInfo boi :
> service.getOperations()) { -            MessageInfo mi;
> -            BindingMessageInfo bmi;
> -            if (!isRequestor(message)) {
> -                mi = boi.getOperationInfo().getInput();
> -                bmi = boi.getInput();
> -            } else {
> -                mi = boi.getOperationInfo().getOutput();
> -                bmi = boi.getOutput();
> -            }
> -            QName rootInModel = null;
> -            Object ext = bmi.getExtensor(XMLBindingMessageFormat.class);
> -            if (ext instanceof XMLBindingMessageFormat) {
> -                // it's bare mode method, the root node exist for multi
> param -                rootInModel = ((XMLBindingMessageFormat)
> ext).getRootNode(); -            } else {
> -                // its wrap mode or bare-single-param mode, using
> operation name -                rootInModel = boi.getName();
> -            }
> +            setObjectMap(boi, message, objMap);
> +            MessageInfo mi = getObject(MessageInfo.class, objMap);
> +            QName rootInModel = getObject(QName.class, objMap);
>              if (rootInModel != null && rootInModel.equals(startQName)) {
>                  if (mi.getMessageParts().size() != 1) {
>                      // handle multi param in bare mode
> @@ -87,8 +74,7 @@
>                      if (!boi.isUnwrapped()) {
>                          // it's bare with one part and part name equals
>                          // operation name (not support yet)
> -                        QName paramName =
> mi.getMessagePartByIndex(0).getElementQName(); -                        if
> (paramName.equals(startQName)) {
> +                        if (rootInModel.equals(startQName)) {
>                             
> message.getExchange().put(BindingOperationInfo.class, boi); new
> BareInInterceptor().handleMessage(message); break;
> @@ -107,15 +93,7 @@
>                      if (mi.getMessageParts().size() != 1) {
>                          continue;
>                      }
> -                    MessagePartInfo mpi = mi.getMessagePartByIndex(0);
> -                    QName paramName;
> -                    if (mpi.isElement()) {
> -                        paramName = mpi.getElementQName();
> -                    } else {
> -                        // currently this has not been suppoerted by
> JAXBEncoderDecoder -                        paramName = mpi.getTypeQName();
> -                    }
> -                    if (paramName.equals(startQName)) {
> +                    if (rootInModel.equals(startQName)) {
>                         
> message.getExchange().put(BindingOperationInfo.class, boi); new
> BareInInterceptor().handleMessage(message); break;
> @@ -123,5 +101,46 @@
>                  }
>              }
>          }
> +    }
> +
> +    private <T> T getObject(Class<T> cls, Map<Class<?>, Object>
objMap) {
> +        return cls.cast(objMap.get(cls));
> +    }
> +
> +    private void setObjectMap(BindingOperationInfo boi, Message message,
> Map<Class<?>, Object> objMap) { +        MessageInfo mi;
> +        BindingMessageInfo bmi;
> +        if (!isRequestor(message)) {
> +            mi = boi.getOperationInfo().getInput();
> +            bmi = boi.getInput();
> +        } else {
> +            mi = boi.getOperationInfo().getOutput();
> +            bmi = boi.getOutput();
> +        }
> +        QName paramFirst = null;
> +        if (mi.getMessageParts().size() > 0) {
> +            MessagePartInfo mpiFirst = mi.getMessagePartByIndex(0);
> +            if (mpiFirst.isElement()) {
> +                paramFirst = mpiFirst.getElementQName();
> +            } else {
> +                // currently this has not been suppoerted by
> JAXBEncoderDecoder +                paramFirst = mpiFirst.getTypeQName();
> +            }
> +        }
> +        QName rootInModel = null;
> +        Object ext = bmi.getExtensor(XMLBindingMessageFormat.class);
> +        if (ext instanceof XMLBindingMessageFormat) {
> +            // it's bare mode method, the root node exist for multi param
> +            rootInModel = ((XMLBindingMessageFormat) ext).getRootNode();
> +        } else {
> +            // its wrap mode or bare-single-param mode, using operation
> name +            if (mi.getMessageParts().size() == 1) {
> +                rootInModel = paramFirst;
> +            } else {
> +                rootInModel = boi.getName();
> +            }
> +        }
> +        objMap.put(QName.class, rootInModel);
> +        objMap.put(MessageInfo.class, mi);
>      }
>  }
>
> Modified:
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptor.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/j
>ava/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java?vie
>w=diff&rev=440967&r1=440966&r2=440967
> ===========================================================================
>=== ---
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptor.java (original) +++
> incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptor.java Wed Sep  6 20:51:53 2006 @@
> -16,6 +16,7 @@
>   * specific language governing permissions and limitations
>   * under the License.
>   */
> +
>  package org.apache.cxf.binding.xml.interceptor;
>
>  import java.util.ResourceBundle;
> @@ -31,45 +32,55 @@
>  import org.apache.cxf.interceptor.Fault;
>  import org.apache.cxf.interceptor.WrappedOutInterceptor;
>  import org.apache.cxf.message.Message;
> +import org.apache.cxf.service.model.BindingMessageInfo;
>  import org.apache.cxf.service.model.BindingOperationInfo;
>  import org.apache.cxf.service.model.MessageInfo;
> +import org.apache.cxf.staxutils.StaxUtils;
>
> -public class XMLMessageOutInterceptor
> -                extends AbstractOutDatabindingInterceptor {
> +public class XMLMessageOutInterceptor extends
> AbstractOutDatabindingInterceptor {
>
>      private static final ResourceBundle BUNDLE =
> BundleUtils.getBundle(WrappedOutInterceptor.class);
>
>      public void handleMessage(Message message) throws Fault {
> -
> -        MessageInfo mi;
>          BindingOperationInfo boi =
> message.getExchange().get(BindingOperationInfo.class); +        MessageInfo
> mi;
> +        BindingMessageInfo bmi;
>          if (isRequestor(message)) {
>              mi = boi.getOperationInfo().getInput();
> +            bmi = boi.getInput();
>          } else {
>              mi = boi.getOperationInfo().getOutput();
> +            bmi = boi.getOutput();
>          }
> -        if (boi.isUnwrapped()) {
> -            if (mi.getMessageParts().size() != 1) {
> -                QName rootInModel = ((XMLBindingMessageFormat)
> mi.getExtensor(XMLBindingMessageFormat.class)) -                           
>     .getRootNode();
> -                if (rootInModel == null) {
> -                    throw new RuntimeException("Bare style must define the
> rootNode in this case!"); -                }
> -                writeMessage(message, rootInModel);
> +        XMLBindingMessageFormat xmf =
> bmi.getExtensor(XMLBindingMessageFormat.class); +        QName rootInModel
> = null;
> +        if (xmf != null) {
> +            rootInModel = xmf.getRootNode();
> +        }
> +        if (mi.getMessageParts().size() == 1) {
> +            // bare-one-param & wrap
> +            new BareOutInterceptor().handleMessage(message);
> +        } else {
> +            if (rootInModel == null) {
> +                rootInModel = boi.getName();
> +            }
> +            if (mi.getMessageParts().size() == 0) {
> +                // write empty operation qname
> +                writeMessage(message, rootInModel, false);
>              } else {
> -                new BareOutInterceptor().handleMessage(message);
> +                // multi param, bare mode, needs write root node
> +                writeMessage(message, rootInModel, true);
>              }
> -        } else {
> -            QName name = mi.getName();
> -            writeMessage(message, name);
>          }
>      }
>
> -    private void writeMessage(Message message, QName name) {
> +    private void writeMessage(Message message, QName name, boolean
> executeBare) { XMLStreamWriter xmlWriter =
> message.getContent(XMLStreamWriter.class); try {
> -            xmlWriter.writeStartElement(name.getLocalPart(),
> name.getNamespaceURI()); -            new
> BareOutInterceptor().handleMessage(message);
> +            StaxUtils.writeStartElement(xmlWriter, "xmlroot",
> name.getLocalPart(), name.getNamespaceURI()); +            if (executeBare)
> {
> +                new BareOutInterceptor().handleMessage(message);
> +            }
>              xmlWriter.writeEndElement();
>          } catch (XMLStreamException e) {
>              throw new Fault(new
> org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
>
> Added:
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/TestBase.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/test/j
>ava/org/apache/cxf/binding/xml/interceptor/TestBase.java?view=auto&rev=44096
>7
> ===========================================================================
>=== ---
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/TestBase.java (added) +++
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/TestBase.java Wed Sep  6 20:51:53 2006 @@ -0,0 +1,198 @@
> +/**
> + * 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.binding.xml.interceptor;
> +
> +import java.io.InputStream;
> +import java.io.OutputStream;
> +import java.lang.reflect.Method;
> +import java.net.URL;
> +import java.util.ArrayList;
> +import java.util.Iterator;
> +import java.util.List;
> +
> +import javax.wsdl.Definition;
> +import javax.wsdl.Service;
> +import javax.xml.bind.JAXBContext;
> +import javax.xml.namespace.QName;
> +import javax.xml.stream.XMLStreamReader;
> +import javax.xml.stream.XMLStreamWriter;
> +
> +import junit.framework.TestCase;
> +
> +import org.apache.cxf.Bus;
> +import org.apache.cxf.binding.Binding;
> +import org.apache.cxf.binding.BindingFactoryManager;
> +import org.apache.cxf.binding.xml.XMLBindingFactory;
> +import org.apache.cxf.endpoint.Endpoint;
> +import org.apache.cxf.endpoint.EndpointImpl;
> +import org.apache.cxf.jaxb.JAXBDataReaderFactory;
> +import org.apache.cxf.jaxb.JAXBDataWriterFactory;
> +import org.apache.cxf.jaxb.JAXBEncoderDecoder;
> +import org.apache.cxf.message.Exchange;
> +import org.apache.cxf.message.ExchangeImpl;
> +import org.apache.cxf.message.Message;
> +import org.apache.cxf.message.MessageImpl;
> +import org.apache.cxf.phase.Phase;
> +import org.apache.cxf.phase.PhaseInterceptorChain;
> +import org.apache.cxf.service.ServiceImpl;
> +import org.apache.cxf.service.model.BindingInfo;
> +import org.apache.cxf.service.model.EndpointInfo;
> +import org.apache.cxf.service.model.ServiceInfo;
> +import org.apache.cxf.staxutils.StaxUtils;
> +import org.apache.cxf.wsdl11.WSDLManagerImpl;
> +import org.apache.cxf.wsdl11.WSDLServiceBuilder;
> +import org.easymock.classextension.EasyMock;
> +import org.easymock.classextension.IMocksControl;
> +
> +public class TestBase extends TestCase {
> +
> +    protected PhaseInterceptorChain chain;
> +
> +    protected Message xmlMessage;
> +
> +    protected Bus bus;
> +
> +    protected IMocksControl control;
> +
> +    protected ServiceInfo serviceInfo;
> +
> +    public void setUp() throws Exception {
> +        List<Phase> phases = new ArrayList<Phase>();
> +        Phase phase1 = new Phase("phase1", 1);
> +        Phase phase2 = new Phase("phase2", 2);
> +        Phase phase3 = new Phase("phase3", 3);
> +        phases.add(phase1);
> +        phases.add(phase2);
> +        phases.add(phase3);
> +        chain = new PhaseInterceptorChain(phases);
> +
> +        Exchange exchange = new ExchangeImpl();
> +        MessageImpl messageImpl = new MessageImpl();
> +        messageImpl.setInterceptorChain(chain);
> +        messageImpl.setExchange(exchange);
> +        xmlMessage = messageImpl;
> +    }
> +
> +    public void tearDown() throws Exception {
> +    }
> +
> +    public InputStream getTestStream(Class<?> clz, String file) {
> +        return clz.getResourceAsStream(file);
> +    }
> +
> +    public XMLStreamReader getXMLStreamReader(InputStream is) {
> +        return StaxUtils.createXMLStreamReader(is);
> +    }
> +
> +    public XMLStreamWriter getXMLStreamWriter(OutputStream os) {
> +        return StaxUtils.createXMLStreamWriter(os);
> +    }
> +
> +    public Method getTestMethod(Class<?> sei, String methodName) {
> +        Method[] iMethods = sei.getMethods();
> +        for (Method m : iMethods) {
> +            if (methodName.equals(m.getName())) {
> +                return m;
> +            }
> +        }
> +        return null;
> +    }
> +
> +    public ServiceInfo getTestService(Class<?> clz) {
> +        // FIXME?!?!?!?? There should NOT be JAX-WS stuff here
> +        return null;
> +    }
> +
> +    protected BindingInfo getTestService(String wsdlUrl, String port)
> throws Exception { +        ServiceInfo service =
> getMockedServiceModel(getClass().getResource(wsdlUrl)); +       
> assertNotNull(service);
> +        BindingInfo binding = service.getEndpoint(new
> QName(service.getName().getNamespaceURI(), port)) +                       
> .getBinding();
> +        assertNotNull(binding);
> +        return binding;
> +    }
> +
> +    protected ServiceInfo getMockedServiceModel(URL wsdlUrl) throws
> Exception { +
> +        WSDLManagerImpl wmi = new WSDLManagerImpl();
> +        Definition def = wmi.getDefinition(wsdlUrl);
> +
> +        control = EasyMock.createNiceControl();
> +        bus = control.createMock(Bus.class);
> +
> +        BindingFactoryManager bindingFactoryManager =
> control.createMock(BindingFactoryManager.class); +       
> WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus); +
> +        Service service = null;
> +        for (Iterator<?> it = def.getServices().values().iterator();
> it.hasNext();) { +            Object obj = it.next();
> +            if (obj instanceof Service) {
> +                service = (Service) obj;
> +                break;
> +            }
> +        }
> +
> +       
> EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bi
>ndingFactoryManager); +        control.replay();
> +        serviceInfo = wsdlServiceBuilder.buildService(def, service);
> +        serviceInfo.setProperty(WSDLServiceBuilder.WSDL_DEFINITION, null);
> +        serviceInfo.setProperty(WSDLServiceBuilder.WSDL_SERVICE, null);
> +        return serviceInfo;
> +    }
> +
> +    protected JAXBDataReaderFactory getTestReaderFactory(Class<?> clz)
> throws Exception { +        JAXBContext ctx =
> JAXBEncoderDecoder.createJAXBContextForClass(clz); +       
> JAXBDataReaderFactory readerFacotry = new JAXBDataReaderFactory(); +       
> readerFacotry.setJAXBContext(ctx);
> +        return readerFacotry;
> +    }
> +
> +    protected JAXBDataWriterFactory getTestWriterFactory(Class<?> clz)
> throws Exception { +        JAXBContext ctx =
> JAXBEncoderDecoder.createJAXBContextForClass(clz); +       
> JAXBDataWriterFactory writerFacotry = new JAXBDataWriterFactory(); +       
> writerFacotry.setJAXBContext(ctx);
> +        return writerFacotry;
> +    }
> +
> +    protected void common(String wsdl, QName portName, Class seiClazz)
> throws Exception { +
> +        URL wsdlUrl = this.getClass().getResource(wsdl);
> +        ServiceInfo si = getMockedServiceModel(wsdlUrl);
> +
> +        EndpointInfo epi = si.getEndpoint(portName);
> +        Binding xmlBinding = new
> XMLBindingFactory().createBinding(epi.getBinding()); +
> +        control.reset();
> +        org.apache.cxf.service.Service service =
> control.createMock(ServiceImpl.class); +       
> EasyMock.expect(service.getDataReaderFactory()).andReturn(getTestReaderFact
>ory(seiClazz)); +       
> EasyMock.expect(service.getDataWriterFactory()).andReturn(getTestWriterFact
>ory(seiClazz)); +
> +        Endpoint endpoint = control.createMock(EndpointImpl.class);
> +        EasyMock.expect(endpoint.getEndpointInfo()).andReturn(epi);
> +        EasyMock.expect(endpoint.getBinding()).andReturn(xmlBinding);
> +
> +        control.replay();
> +
> +        xmlMessage.getExchange().put(Endpoint.class, endpoint);
> +        xmlMessage.getExchange().put(org.apache.cxf.service.Service.class,
> service); +
> +
> +    }
> +}
>
> Propchange:
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/TestBase.java
> ---------------------------------------------------------------------------
>--- svn:eol-style = native
>
> Added:
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptorTest.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/test/j
>ava/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptorTest.java?
>view=auto&rev=440967
> ===========================================================================
>=== ---
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptorTest.java (added) +++
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptorTest.java Wed Sep  6 20:51:53 2006 @@
> -0,0 +1,97 @@
> +/**
> + * 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.binding.xml.interceptor;
> +
> +import java.io.InputStream;
> +import java.util.List;
> +
> +import javax.xml.namespace.QName;
> +import javax.xml.stream.XMLStreamReader;
> +
> +import org.apache.cxf.staxutils.StaxUtils;
> +import org.apache.hello_world_xml_http.bare.types.MyComplexStructType;
> +import org.apache.hello_world_xml_http.wrapped.types.GreetMe;
> +
> +public class XMLMessageInInterceptorTest extends TestBase {
> +
> +    XMLMessageInInterceptor in = new XMLMessageInInterceptor();
> +
> +    public void setUp() throws Exception {
> +        super.setUp();
> +        in.setPhase("phase1");
> +        chain.add(in);
> +    }
> +
> +    public void tearDown() throws Exception {
> +        super.tearDown();
> +    }
> +
> +    public void testHandleMessageOnBareMultiParam() throws Exception {
> +        String ns = "http://apache.org/hello_world_xml_http/bare";
> +        prepareMessage("/message-bare-multi-param.xml");
> +        common("/wsdl/hello_world_xml_bare.wsdl", new QName(ns,
> "XMLPort"), +                       
> org.apache.hello_world_xml_http.bare.Greeter.class); +       
> in.handleMessage(xmlMessage);
> +        List list = xmlMessage.getContent(List.class);
> +        assertNotNull(list);
> +        assertEquals("expect 2 param", 2, list.size());
> +        assertEquals("method input in2 is MyComplexStructType", true,
> +                        list.get(0) instanceof MyComplexStructType);
> +        assertEquals("method input in1 is String tli", true, ((String)
> list.get(1)).indexOf("tli") >= 0); +    }
> +
> +    public void testHandleMessageOnBareSingleChild() throws Exception {
> +        String ns = "http://apache.org/hello_world_xml_http/bare";
> +        prepareMessage("/message-bare-single-param-element.xml");
> +        common("/wsdl/hello_world_xml_bare.wsdl", new QName(ns,
> "XMLPort"), +                       
> org.apache.hello_world_xml_http.bare.Greeter.class); +       
> in.handleMessage(xmlMessage);
> +        List list = xmlMessage.getContent(List.class);
> +        assertNotNull(list);
> +        assertEquals("expect 1 param", 1, list.size());
> +        assertEquals("method input me is String tli", true, ((String)
> list.get(0)).indexOf("tli") >= 0); +        //
> prepareMessage("/message-bare-single-param-type.xml"); +        //
> common();
> +        // assertNotNull(list);
> +        // assertEquals("expect 1 param", 1, list.size());
> +        // assertEquals("method input in2 is MyComplexStructType", true,
> +        // list.get(0) instanceof MyComplexStructType);
> +    }
> +
> +    public void testHandleMessageWrapped() throws Exception {
> +        String ns = "http://apache.org/hello_world_xml_http/wrapped";
> +        prepareMessage("/message-wrap.xml");
> +        common("/wsdl/hello_world_xml_wrapped.wsdl", new QName(ns,
> "XMLPort"), +                       
> org.apache.hello_world_xml_http.wrapped.Greeter.class); +       
> in.handleMessage(xmlMessage);
> +        List list = xmlMessage.getContent(List.class);
> +        assertNotNull(list);
> +        assertEquals("expect 1 param", 1, list.size());
> +        assertEquals("method input me is String tli", true, list.get(0)
> instanceof GreetMe); +    }
> +
> +
> +
> +    private void prepareMessage(String messageFileName) throws Exception {
> +        InputStream inputStream =
> this.getClass().getResourceAsStream(messageFileName); +       
> xmlMessage.setContent(InputStream.class, inputStream);
> +        xmlMessage.setContent(XMLStreamReader.class,
> StaxUtils.createXMLStreamReader(inputStream)); +    }
> +}
>
> Propchange:
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageInInterceptorTest.java
> ---------------------------------------------------------------------------
>--- svn:eol-style = native
>
> Added:
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptorTest.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/test/j
>ava/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptorTest.java
>?view=auto&rev=440967
> ===========================================================================
>=== ---
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptorTest.java (added) +++
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptorTest.java Wed Sep  6 20:51:53 2006 @@
> -0,0 +1,192 @@
> +/**
> + * 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.binding.xml.interceptor;
> +
> +import java.io.ByteArrayInputStream;
> +import java.io.ByteArrayOutputStream;
> +import java.io.InputStream;
> +import java.io.OutputStream;
> +import java.util.ArrayList;
> +import java.util.List;
> +
> +import javax.xml.namespace.QName;
> +import javax.xml.stream.XMLStreamReader;
> +import javax.xml.stream.XMLStreamWriter;
> +
> +import org.apache.cxf.message.Message;
> +import org.apache.cxf.service.model.BindingInfo;
> +import org.apache.cxf.service.model.BindingOperationInfo;
> +import org.apache.cxf.staxutils.DepthXMLStreamReader;
> +import org.apache.cxf.staxutils.StaxUtils;
> +import org.apache.hello_world_xml_http.bare.types.MyComplexStructType;
> +import org.apache.hello_world_xml_http.wrapped.types.GreetMe;
> +
> +public class XMLMessageOutInterceptorTest extends TestBase {
> +
> +    static String bareNs = "http://apache.org/hello_world_xml_http/bare";
> +
> +    static String wrapNs =
> "http://apache.org/hello_world_xml_http/wrapped"; +
> +    static String bareNsType =
> "http://apache.org/hello_world_xml_http/bare/types"; +
> +    static String wrapNsType =
> "http://apache.org/hello_world_xml_http/wrapped/types"; +
> +    OutputStream outputStream;
> +
> +    XMLStreamWriter writer;
> +
> +    XMLMessageOutInterceptor out = new XMLMessageOutInterceptor();
> +
> +    List params = new ArrayList();
> +
> +    QName bareMyComplexStructQName = new QName(bareNsType,
> "myComplexStructType"); +
> +    QName bareRequestTypeQName = new QName(bareNsType, "requestType");
> +
> +    QName wrapGreetMeQName = new QName(wrapNsType, "greetMe");
> +
> +    QName wrapRequestTypeQName = new QName(wrapNsType, "requestType");
> +
> +    public void setUp() throws Exception {
> +        super.setUp();
> +        out.setPhase("phase1");
> +        chain.add(out);
> +        prepareMessage(params);
> +    }
> +
> +    public void tearDown() throws Exception {
> +        super.tearDown();
> +    }
> +
> +    public void testBareOutSingle() throws Exception {
> +
> +        MyComplexStructType myComplexStruct = new MyComplexStructType();
> +        myComplexStruct.setElem1("elem1");
> +        myComplexStruct.setElem2("elem2");
> +        myComplexStruct.setElem3(45);
> +        params.add(myComplexStruct);
> +
> +        common("/wsdl/hello_world_xml_bare.wsdl", new QName(bareNs,
> "XMLPort"), +                       
> org.apache.hello_world_xml_http.bare.Greeter.class); +
> +        BindingInfo bi = super.serviceInfo.getBinding(new QName(bareNs,
> "Greeter_XMLBinding")); +        BindingOperationInfo boi =
> bi.getOperation(new QName(bareNs, "sendReceiveData")); +       
> xmlMessage.getExchange().put(BindingOperationInfo.class, boi); +
> +        out.handleMessage(xmlMessage);
> +
> +        XMLStreamReader reader = getXMLReader();
> +        DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader);
> +        StaxUtils.nextEvent(dxr);
> +        StaxUtils.toNextElement(dxr);
> +        assertEquals(bareMyComplexStructQName.getNamespaceURI(),
> dxr.getNamespaceURI()); +       
> assertEquals(bareMyComplexStructQName.getLocalPart(), dxr.getLocalName());
> +        StaxUtils.toNextElement(dxr);
> +        StaxUtils.toNextText(dxr);
> +        assertEquals(myComplexStruct.getElem1(), dxr.getText());
> +    }
> +
> +    public void testBareOutMultiWithRoot() throws Exception {
> +
> +        MyComplexStructType myComplexStruct = new MyComplexStructType();
> +        myComplexStruct.setElem1("elem1");
> +        myComplexStruct.setElem2("elem2");
> +        myComplexStruct.setElem3(45);
> +        params.add(myComplexStruct);
> +        params.add("tli");
> +
> +        common("/wsdl/hello_world_xml_bare.wsdl", new QName(bareNs,
> "XMLPort"), +                       
> org.apache.hello_world_xml_http.bare.Greeter.class); +
> +        BindingInfo bi = super.serviceInfo.getBinding(new QName(bareNs,
> "Greeter_XMLBinding")); +        BindingOperationInfo boi =
> bi.getOperation(new QName(bareNs, "testMultiParamPart")); +       
> xmlMessage.getExchange().put(BindingOperationInfo.class, boi); +
> +        out.handleMessage(xmlMessage);
> +
> +        XMLStreamReader reader = getXMLReader();
> +        DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader);
> +        StaxUtils.nextEvent(dxr);
> +        StaxUtils.toNextElement(dxr);
> +        assertEquals(bareNs, dxr.getNamespaceURI());
> +        assertEquals("multiParamRootReq", dxr.getLocalName());
> +        StaxUtils.nextEvent(dxr);
> +        StaxUtils.toNextElement(dxr);
> +        assertEquals(bareMyComplexStructQName.getNamespaceURI(),
> dxr.getNamespaceURI()); +        assertEquals("myComplexStruct",
> dxr.getLocalName());
> +        boolean foundRequest = false;
> +        while (true) {
> +            StaxUtils.nextEvent(dxr);
> +            StaxUtils.toNextElement(dxr);
> +            QName requestType = new QName(dxr.getNamespaceURI(),
> dxr.getLocalName()); +            if
> (requestType.equals(bareRequestTypeQName)) {
> +                foundRequest = true;
> +                break;
> +            }
> +        }
> +        assertEquals("found request type", true, foundRequest);
> +        StaxUtils.nextEvent(dxr);
> +        if (StaxUtils.toNextText(dxr)) {
> +            assertEquals("tli", dxr.getText());
> +        }
> +    }
> +
> +    public void testWrapOut() throws Exception {
> +        GreetMe greetMe = new GreetMe();
> +        greetMe.setRequestType("tli");
> +        params.add(greetMe);
> +        common("/wsdl/hello_world_xml_wrapped.wsdl", new QName(wrapNs,
> "XMLPort"), +                       
> org.apache.hello_world_xml_http.wrapped.Greeter.class); +
> +        BindingInfo bi = super.serviceInfo.getBinding(new QName(wrapNs,
> "Greeter_XMLBinding")); +        BindingOperationInfo boi =
> bi.getOperation(new QName(wrapNs, "greetMe")); +       
> xmlMessage.getExchange().put(BindingOperationInfo.class, boi); +
> +        out.handleMessage(xmlMessage);
> +
> +        XMLStreamReader reader = getXMLReader();
> +        DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader);
> +        StaxUtils.nextEvent(dxr);
> +        StaxUtils.toNextElement(dxr);
> +        assertEquals(wrapGreetMeQName.getNamespaceURI(),
> dxr.getNamespaceURI()); +       
> assertEquals(wrapGreetMeQName.getLocalPart(), dxr.getLocalName()); +       
> StaxUtils.toNextElement(dxr);
> +        StaxUtils.toNextText(dxr);
> +        assertEquals(greetMe.getRequestType(), dxr.getText());
> +    }
> +
> +    private void prepareMessage(List paramsList) throws Exception {
> +        outputStream = new ByteArrayOutputStream();
> +        // all test case here use input message to do test,
> +        // that means the out interceptor's role is Server-Out
> +        xmlMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
> +        xmlMessage.setContent(OutputStream.class, outputStream);
> +        writer = StaxUtils.createXMLStreamWriter(outputStream);
> +        xmlMessage.setContent(XMLStreamWriter.class, writer);
> +        xmlMessage.setContent(List.class, paramsList);
> +    }
> +
> +    private XMLStreamReader getXMLReader() throws Exception {
> +        ByteArrayOutputStream o = (ByteArrayOutputStream)
> xmlMessage.getContent(OutputStream.class); +        writer.flush();
> +        InputStream in = new ByteArrayInputStream(o.toByteArray());
> +        return StaxUtils.createXMLStreamReader(in);
> +    }
> +}
>
> Propchange:
> incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xm
>l/interceptor/XMLMessageOutInterceptorTest.java
> ---------------------------------------------------------------------------
>--- svn:eol-style = native
>
> Modified:
> incubator/cxf/trunk/rt/bindings/xml/src/test/resources/message-wrap.xml
> URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/test/r
>esources/message-wrap.xml?view=diff&rev=440967&r1=440966&r2=440967
> ===========================================================================
>=== ---
> incubator/cxf/trunk/rt/bindings/xml/src/test/resources/message-wrap.xml
> (original) +++
> incubator/cxf/trunk/rt/bindings/xml/src/test/resources/message-wrap.xml Wed
> Sep  6 20:51:53 2006 @@ -1 +1,5 @@
> -<?xml version="1.0" encoding="UTF-8"?>
> +<ns2:greetMe xmlns="http://www.w3.org/2005/08/addressing/wsdl"
> +	xmlns:ns2="http://apache.org/hello_world_xml_http/wrapped/types">
> +	<ns2:requestType>tli</ns2:requestType>
> +</ns2:greetMe>
> +

-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194   F:781-902-8001
daniel.kulp@iona.com

Mime
View raw message