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 sc...@us.ibm.com on 2002/08/12 22:53:39 UTC

Re: cvs commit: xml-axis/java/src/org/apache/axis/encoding SerializationContextImpl.java

Glen,

I am catching up on my mail...

Did you try changing the multiref testcase (in your sandbox) to see if
inlining multirefs works for more complicated situations ?

Thanks,

Rich Scheuerle
IBM WebSphere & Axis Web Services Development
512-838-5115  (IBM TL 678-5115)


                                                                                                                                 
                      gdaniels@apache.                                                                                           
                      org                      To:       xml-axis-cvs@apache.org                                                 
                                               cc:                                                                               
                      07/26/2002 03:30         Subject:  cvs commit: xml-axis/java/src/org/apache/axis/encoding                  
                      PM                        SerializationContextImpl.java                                                    
                      Please respond to                                                                                          
                      axis-dev                                                                                                   
                                                                                                                                 
                                                                                                                                 



gdaniels    2002/07/26 13:30:36

  Modified:    java/src/org/apache/axis/encoding
                        SerializationContextImpl.java
  Added:       java/test/soap12 TestSer.java
  Log:
  When using SOAP 1.2, we can (and should) inline serialization of
multirefs.

  Enable this, and put in a quick test (copy of TestSer).

  Revision  Changes    Path
  1.1                  xml-axis/java/test/soap12/TestSer.java

  Index: TestSer.java
  ===================================================================
  package test.soap12;

  import junit.framework.TestCase;

  import org.apache.axis.MessageContext;
  import org.apache.axis.encoding.DeserializationContext;
  import org.apache.axis.encoding.DeserializationContextImpl;
  import org.apache.axis.encoding.SerializationContext;
  import org.apache.axis.encoding.SerializationContextImpl;
  import org.apache.axis.encoding.TypeMappingRegistry;
  import org.apache.axis.encoding.TypeMapping;
  import org.apache.axis.Constants;
  import org.apache.axis.soap.SOAPConstants;
  import org.apache.axis.message.RPCElement;
  import org.apache.axis.message.RPCParam;
  import org.apache.axis.message.SOAPEnvelope;
  import org.apache.axis.server.AxisServer;

  import org.apache.axis.components.logger.LogFactory;
  import org.apache.commons.logging.Log;

  import org.xml.sax.InputSource;
  import org.w3c.dom.Document;

  import javax.xml.namespace.QName;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import java.io.StringReader;
  import java.io.StringWriter;
  import java.io.Writer;

  import test.encoding.Data;
  import test.encoding.DataSerFactory;
  import test.encoding.DataDeserFactory;

  /** Little serialization test with a struct.
   */
  public class TestSer extends TestCase {
      Log log =
              LogFactory.getLog(TestSer.class.getName());

      public static final String myNS = "urn:myNS";

      public TestSer(String name) {
          super(name);
      }

      public void testDataNoHrefs () throws Exception {
          doTestData(false);
      }

      public void testDataWithHrefs () throws Exception {
          doTestData(true);
      }

      public void doTestData (boolean multiref) throws Exception {
          MessageContext msgContext = new MessageContext(new AxisServer());
          msgContext.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
          SOAPEnvelope msg = new SOAPEnvelope(SOAPConstants.
SOAP12_CONSTANTS);
          RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam",
"this is a string");

          Data data = new Data();
          data.stringMember = "String member";
          data.floatMember = new Float("4.54");

          RPCParam arg2 = new RPCParam("", "struct", data);
          RPCElement body = new RPCElement("urn:myNamespace", "method1",
new Object[]{ arg1, arg2 });
          msg.addBodyElement(body);

          Writer stringWriter = new StringWriter();
          SerializationContext context = new
SerializationContextImpl(stringWriter, msgContext);
          context.setDoMultiRefs(multiref);

          // Create a TypeMapping and register the specialized Type Mapping
          TypeMappingRegistry reg = context.getTypeMappingRegistry();
          TypeMapping tm = (TypeMapping) reg.createTypeMapping();
          tm.setSupportedEncodings(new String[] {Constants.
URI_DEFAULT_SOAP_ENC});
          reg.register(Constants.URI_DEFAULT_SOAP_ENC, tm);

          QName dataQName = new QName("typeNS", "Data");
          tm.register(Data.class, dataQName, new DataSerFactory(), new
DataDeserFactory());

          msg.output(context);

          String msgString = stringWriter.toString();

          log.debug("---");
          log.debug(msgString);
          log.debug("---");

          StringReader reader = new StringReader(msgString);

          DeserializationContext dser = new DeserializationContextImpl(
              new InputSource(reader), msgContext, org.apache.axis.Message.
REQUEST);
          dser.parse();

          SOAPEnvelope env = dser.getEnvelope();
          RPCElement rpcElem = (RPCElement)env.getFirstBody();
          RPCParam struct = rpcElem.getParam("struct");
          assertNotNull("No <struct> param", struct);

          Data val = (Data)struct.getValue();
          assertNotNull("No value for struct param", val);

          assertEquals("Data and Val string members are not equal", data.
stringMember, val.stringMember);
          assertEquals("Data and Val float members are not equal",data.
floatMember.floatValue(),
                       val.floatMember.floatValue(), 0.00001F);
      }

      /**
       * Test RPC element serialization when we have no MessageContext
       */
      public void testRPCElement()
      {
          try {
              SOAPEnvelope env = new SOAPEnvelope();
              RPCElement method = new RPCElement("ns",
                                                 "method",
                                                 new Object [] { "argument"
});
              env.addBodyElement(method);
              String soapStr = env.toString();
          } catch (Exception e) {
              fail(e.getMessage());
          }

          // If there was no exception, we succeeded in serializing it.
      }

      public void testEmptyXMLNS()
      {
          try {
              MessageContext msgContext = new MessageContext(new
AxisServer());
              String req =
                  "<xsd1:A xmlns:xsd1='urn:myNamespace'>"
                      + "<xsd1:B>"
                      + "<xsd1:C>foo bar</xsd1:C>"
                      + "</xsd1:B>"
                      + "</xsd1:A>";

              StringWriter stringWriter=new StringWriter();
              StringReader reqReader = new StringReader(req);
              InputSource reqSource = new InputSource(reqReader);

              DocumentBuilder xdb = DocumentBuilderFactory.newInstance().
newDocumentBuilder();
              Document document = xdb.parse(reqSource );

              String msgString = null;

              SOAPEnvelope msg = new SOAPEnvelope();
              RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam",
document.getFirstChild());
              arg1.setXSITypeGeneration(Boolean.FALSE);

              RPCElement body = new RPCElement("urn:myNamespace",
"method1", new Object[] { arg1 });
              msg.addBodyElement(body);
              body.setEncodingStyle(Constants.URI_LITERAL_ENC);

              SerializationContext context = new
SerializationContextImpl(stringWriter, msgContext);
              msg.output(context);

              msgString = stringWriter.toString();
              assertTrue(msgString.indexOf("xmlns=\"\"")==-1);
          } catch (Exception e) {
              fail(e.getMessage());
          }
      }
  }



  1.50      +17 -1     xml-
axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java

  Index: SerializationContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-
axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- SerializationContextImpl.java        24 Jul 2002 19:08:33 -0000
 1.49
  +++ SerializationContextImpl.java        26 Jul 2002 20:30:36 -0000
 1.50
  @@ -689,6 +689,21 @@
                   mri = new MultiRefItem (id, xmlType, sendType, value);
                   multiRefValues.put(getIdentityKey(value), mri);

  +                /**
  +                 * If we're SOAP 1.2, we can "inline" the
serializations,
  +                 * so put it out now, with it's ID.
  +                 */
  +                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
  +                    AttributesImpl attrs = new AttributesImpl();
  +                    if (attributes != null && 0 < attributes.
getLength())
  +                        attrs.setAttributes(attributes);
  +                    attrs.addAttribute("", Constants.ATTR_ID, "id",
"CDATA",
  +                                       id);
  +                    serializeActual(elemQName, attrs, value, xmlType,
sendType);
  +                    return;
  +                }
  +
  +
                   /** If we're in the middle of writing out
                    * the multi-refs, we've already cloned the list of
objects
                    * and so even though we add a new one to
multiRefValues,
  @@ -756,7 +771,8 @@
        */
       public void outputMultiRefs() throws IOException
       {
  -        if (!doMultiRefs || (multiRefValues == null))
  +        if (!doMultiRefs || (multiRefValues == null) ||
  +                soapConstants == SOAPConstants.SOAP12_CONSTANTS)
               return;
           outputMultiRefsFlag = true;
           AttributesImpl attrs = new AttributesImpl();