public SOAPHandler onStartChild(
        String namespace,
        String localName,
        String prefix,
        Attributes attributes,
        DeserializationContext context)
        throws SAXException {
      QName typeQName = context.getTypeFromAttributes(namespace, localName, attributes);
      Deserializer dser = context.getDeserializerForType(typeQName);

      if (dser == null) dser = new DeserializerImpl();

      SOAPConstants soapConstants = context.getSOAPConstants();
      String href = attributes.getValue(soapConstants.getAttrHref());

      if (href != null) {
        Object ref = context.getObjectByRef(href);

        ItemHandler handler = new ItemHandler(md);

        addChildDeserializer(handler);

        return handler;
      }

      addChildDeserializer(dser);
      return (SOAPHandler) dser;
    }
Example #2
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);
  }
  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();
  }
Example #4
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);
   }
 }
  /**
   * onStartChild is called on each child element.
   *
   * @param namespace is the namespace of the child element
   * @param localName is the local name of the child element
   * @param prefix is the prefix used on the name of the child element
   * @param attributes are the attributes of the child element
   * @param context is the deserialization context.
   * @return is a Deserializer to use to deserialize a child (must be a derived class of
   *     SOAPHandler) or null if no deserialization should be performed.
   */
  public SOAPHandler onStartChild(
      String namespace,
      String localName,
      String prefix,
      Attributes attributes,
      DeserializationContext context)
      throws SAXException {

    if (log.isDebugEnabled()) {
      log.debug("Enter: MapDeserializer::onStartChild()");
    }

    if (localName.equals("item")) {

      // liferay - changes started
      // check if 'href' attribute is present. if so, process it
      // with BigItemHandler (see bellow)
      SOAPConstants soapConstants = context.getSOAPConstants();
      String href = attributes.getValue(soapConstants.getAttrHref());

      if (href != null) {
        Object ref = context.getObjectByRef(href);

        BigItemHandler handler = new BigItemHandler(this);

        addChildDeserializer(handler);

        return handler;
      }
      // liferay - end of changes

      ItemHandler handler = new ItemHandler(this);

      // This item must be complete before we're complete...
      addChildDeserializer(handler);

      if (log.isDebugEnabled()) {
        log.debug("Exit: MapDeserializer::onStartChild()");
      }

      return handler;
    }

    return this;
  }
    public SOAPHandler onStartChild(
        String namespace,
        String localName,
        String prefix,
        Attributes attributes,
        DeserializationContext context)
        throws SAXException {
      QName typeQName = context.getTypeFromAttributes(namespace, localName, attributes);
      Deserializer dser = context.getDeserializerForType(typeQName);

      // If no deserializer, use the base DeserializerImpl.
      if (dser == null) dser = new DeserializerImpl();

      // When the child value is ready, we
      // want our set method to be invoked.
      // To do this register a DeserializeTarget on the
      // new Deserializer.
      DeserializerTarget dt = null;
      if (context.isNil(attributes)) {
        dt = new DeserializerTarget(this, NILHINT);
      } else if (localName.equals("key")) {
        dt = new DeserializerTarget(this, KEYHINT);
      } else if (localName.equals("value")) {
        dt = new DeserializerTarget(this, VALHINT);
      } else {
        // Do nothing
      }
      if (dt != null) {
        dser.registerValueTarget(dt);
      }

      // We need this guy to complete for us to complete.
      addChildDeserializer(dser);

      return (SOAPHandler) dser;
    }
  /**
   * This method is invoked after startElement when the element requires deserialization (i.e. the
   * element is not an href and the value is not nil.)
   *
   * <p>Simply creates map.
   *
   * @param namespace is the namespace of the element
   * @param localName is the name of the element
   * @param prefix is the prefix of the element
   * @param attributes are the attributes on the element...used to get the type
   * @param context is the DeserializationContext
   */
  public void onStartElement(
      String namespace,
      String localName,
      String prefix,
      Attributes attributes,
      DeserializationContext context)
      throws SAXException {
    if (log.isDebugEnabled()) {
      log.debug("Enter MapDeserializer::startElement()");
    }

    if (context.isNil(attributes)) {
      return;
    }

    // Create a hashmap to hold the deserialized values.
    setValue(new HashMap());

    if (log.isDebugEnabled()) {
      log.debug("Exit: MapDeserializer::startElement()");
    }
  }
  public void onStartElement(
      java.lang.String namespace,
      java.lang.String localName,
      java.lang.String prefix,
      org.xml.sax.Attributes attributes,
      DeserializationContext context)
      throws SAXException {

    try {

      MessageElement messageElement = context.getCurElement();
      String element = messageElement.getAsString();

      PolicySetTypeString object = new PolicySetTypeString(element);

      setValue(object);

    } catch (Exception exception) {
      throw new SAXException(
          "Error deserializing " + " : " + exception.getClass() + " : " + exception.getMessage());
    }
  }