Esempio n. 1
0
  public void doTestData(boolean multiref) throws Exception {
    MessageContext msgContext = new MessageContext(new AxisServer());
    msgContext.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
    msgContext.setProperty(Constants.MC_NO_OPERATION_OK, Boolean.TRUE);

    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 SerializationContext(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_SOAP12_ENC});
    reg.register(Constants.URI_SOAP12_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 DeserializationContext(
            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.getObjectValue();
    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);
  }
Esempio n. 2
0
  public Object deserialize(InputStream is, Hashtable extendedContext) throws Exception {

    // getting deserializer
    Class targetCls = (Class) extendedContext.get("targetClass");
    Object objectOfTargetCls = targetCls.newInstance();
    TypeDesc desc =
        (TypeDesc)
            objectOfTargetCls
                .getClass()
                .getMethod("getTypeDesc", new Class[] {})
                .invoke(objectOfTargetCls, new Object[] {});
    final QName xmlType; // = desc.getXmlType();
    xmlType =
        new QName(
            "http://" + objectOfTargetCls.getClass().getName(),
            org.uengine.util.UEngineUtil.getClassNameOnly(objectOfTargetCls.getClass()));
    Deserializer dser =
        (Deserializer)
            objectOfTargetCls
                .getClass()
                .getMethod("getDeserializer", new Class[] {String.class, Class.class, QName.class})
                .invoke(
                    objectOfTargetCls, new Object[] {"", objectOfTargetCls.getClass(), xmlType});
    // end
    System.out.println("dser:" + dser);

    DeserializationContext context =
        new DeserializationContextImpl(
            new org.xml.sax.InputSource(is),
            /*			new MessageContext(null){
            	public String getEncodingStyle(){
            		return xmlType.getNamespaceURI();
            	}
            },*/
            new MessageContext(new AxisClient()),
            // Message.RESPONSE
            "PurchaseOrder");

    boolean oldVal = context.isDoneParsing();
    ((DeserializationContextImpl) context).deserializing(true);
    context.pushElementHandler(new EnvelopeHandler((SOAPHandler) dser));

    //	        context.getRecorder().replay(0, -1, (org.xml.sax.ContentHandler)context);
    context.getRecorder().replay(0, -1, (org.xml.sax.ContentHandler) context);

    ((DeserializationContextImpl) context).deserializing(oldVal);

    context.parse();

    return dser.getValue();
  }
Esempio n. 3
0
 public void testNSStack2() throws Exception {
   String msg = prefix + m2 + suffix;
   StringReader strReader = new StringReader(msg);
   DeserializationContext dser =
       new DeserializationContext(
           new InputSource(strReader), null, org.apache.axis.Message.REQUEST);
   dser.parse();
   org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
   String xml = env.toString();
   boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
   XMLUnit.setIgnoreWhitespace(true);
   try {
     assertXMLIdentical("NSStack invalidated XML canonicalization", new Diff(msg, xml), true);
   } finally {
     XMLUnit.setIgnoreWhitespace(oldIgnore);
   }
 }