Package org.springmodules.remoting.xmlrpc.support

Examples of org.springmodules.remoting.xmlrpc.support.XmlRpcRequest


   */
  public final void testParseRequestWithBooleanParameters() {
    XmlRpcBoolean[] parameters = { new XmlRpcBoolean(Boolean.TRUE),
        new XmlRpcBoolean(Boolean.FALSE) };

    XmlRpcRequest expected = new XmlRpcRequest(this.serviceName,
        this.methodName, parameters);

    StringBuffer builder = new StringBuffer();
    builder.append("<?xml version=\"1.0\"?>");
    builder.append("<methodCall><methodName>");
    builder.append(this.serviceAndMethodNames);
    builder.append("</methodName><params>");

    int parameterCount = parameters.length;
    for (int i = 0; i < parameterCount; i++) {
      XmlRpcBoolean xmlRpcBoolean = parameters[i];
      Boolean value = (Boolean) xmlRpcBoolean.getValue();

      builder.append("<param><value><boolean>");
      builder.append(value.booleanValue() ? "1" : "0");
      builder.append("</boolean></value></param>");
    }

    builder.append("</params></methodCall>");

    String request = builder.toString();

    InputStream inputStream = new ByteArrayInputStream(request.getBytes());
    XmlRpcRequest actual = this.parser.parseRequest(inputStream);

    this.logger.info("XML-RPC request: " + request);
    this.logger.info(actual);
   
    assertEquals("<XML-RPC request>", expected, actual);
View Full Code Here


    Date value = calendar.getTime();
    XmlRpcDateTime xmlRpcDateTime = new XmlRpcDateTime(value);
    XmlRpcElement[] parameters = { xmlRpcDateTime };

    XmlRpcRequest expected = new XmlRpcRequest(this.serviceName,
        this.methodName, parameters);

    StringBuffer builder = new StringBuffer();
    builder.append("<?xml version=\"1.0\"?>");
    builder.append("<methodCall><methodName>");
    builder.append(this.serviceAndMethodNames);
    builder.append("</methodName><params><param><value><dateTime.iso8601>");
    builder.append(dateFormat.format(value));
    builder.append("</dateTime.iso8601></value></param></params></methodCall>");

    String request = builder.toString();

    InputStream inputStream = new ByteArrayInputStream(request.getBytes());
    XmlRpcRequest actual = this.parser.parseRequest(inputStream);

    this.logger.info("XML-RPC request: " + request);
    this.logger.info(actual);
   
    assertEquals("<XML-RPC request>", expected, actual);
View Full Code Here

    Double value = new Double(782.99);

    XmlRpcDouble xmlRpcDouble = new XmlRpcDouble(value);
    XmlRpcElement[] parameters = { xmlRpcDouble };

    XmlRpcRequest expected = new XmlRpcRequest(this.serviceName,
        this.methodName, parameters);

    StringBuffer builder = new StringBuffer();
    builder.append("<?xml version=\"1.0\"?>");
    builder.append("<methodCall><methodName>");
    builder.append(this.serviceAndMethodNames);
    builder.append("</methodName><params><param><value><double>");
    builder.append(value.toString());
    builder.append("</double></value></param></params></methodCall>");

    String request = builder.toString();

    InputStream inputStream = new ByteArrayInputStream(request.getBytes());
    XmlRpcRequest actual = this.parser.parseRequest(inputStream);

    this.logger.info("XML-RPC request: " + request);
    this.logger.info(actual);
   
    assertEquals("<XML-RPC request>", expected, actual);
View Full Code Here

   */
  public final void testParseRequestWithIntegerParameters() {
    XmlRpcInteger[] parameters = { new XmlRpcInteger(new Integer(54)),
        new XmlRpcInteger(new Integer(438)) };

    XmlRpcRequest expected = new XmlRpcRequest(this.serviceName,
        this.methodName, parameters);

    StringBuffer builder = new StringBuffer();
    builder.append("<?xml version=\"1.0\"?>");
    builder.append("<methodCall><methodName>");
    builder.append(this.serviceAndMethodNames);
    builder.append("</methodName><params>");

    int parameterCount = parameters.length;
    for (int i = 0; i < parameterCount; i++) {
      XmlRpcInteger xmlRpcInteger = parameters[i];
      Integer value = (Integer) xmlRpcInteger.getValue();

      // even parameters will have "i4" as name, odd parameters will have "int"
      // as name.
      String elementName = (i % 2 == 0) ? "i4" : "int";

      builder.append("<param><value><");
      builder.append(elementName);
      builder.append(">");
      builder.append(value.toString());
      builder.append("</");
      builder.append(elementName);
      builder.append("></value></param>");
    }

    builder.append("</params></methodCall>");

    String request = builder.toString();

    InputStream inputStream = new ByteArrayInputStream(request.getBytes());
    XmlRpcRequest actual = this.parser.parseRequest(inputStream);

    this.logger.info("XML-RPC request: " + request);
    this.logger.info(actual);
   
    assertEquals("<XML-RPC request>", expected, actual);
View Full Code Here

   */
  public final void testParseRequestWithStringParameters() {
    XmlRpcString[] parameters = { new XmlRpcString("Hoth"),
        new XmlRpcString("Endor") };

    XmlRpcRequest expected = new XmlRpcRequest(this.serviceName,
        this.methodName, parameters);

    StringBuffer builder = new StringBuffer();
    builder.append("<?xml version=\"1.0\"?>");
    builder.append("<methodCall><methodName>");
    builder.append(this.serviceAndMethodNames);
    builder.append("</methodName><params>");

    int parameterCount = parameters.length;
    for (int i = 0; i < parameterCount; i++) {
      XmlRpcString xmlRpcString = parameters[i];
      String value = (String) xmlRpcString.getValue();

      // even parameters will have an extra "string" element.
      boolean addStringElement = (i % 2 == 0);

      builder.append("<param><value>");
      if (addStringElement) {
        builder.append("<string>");
      }
      builder.append(value);
      if (addStringElement) {
        builder.append("</string>");
      }
      builder.append("</value></param>");
    }

    builder.append("</params></methodCall>");

    String request = builder.toString();

    InputStream inputStream = new ByteArrayInputStream(request.getBytes());
    XmlRpcRequest actual = this.parser.parseRequest(inputStream);

    this.logger.info("XML-RPC request: " + request);
    this.logger.info(actual);
   
    assertEquals("<XML-RPC request>", expected, actual);
View Full Code Here

    xmlRpcStruct.add("name", new XmlRpcString("Darth Vader"));
    xmlRpcStruct.add("role", new XmlRpcString("Sith lord"));

    XmlRpcElement[] parameters = { xmlRpcStruct };

    XmlRpcRequest expected = new XmlRpcRequest(this.serviceName,
        this.methodName, parameters);

    StringBuffer builder = new StringBuffer();
    builder.append("<?xml version=\"1.0\"?>");
    builder.append("<methodCall><methodName>");
    builder.append(this.serviceAndMethodNames);
    builder.append("</methodName><params><param><value><struct>");

    XmlRpcMember[] members = xmlRpcStruct.getMembers();
    int memberCount = members.length;
    for (int i = 0; i < memberCount; i++) {
      XmlRpcMember member = members[i];
      XmlRpcString value = (XmlRpcString) member.value;

      builder.append("<member><name>");
      builder.append(member.name);
      builder.append("</name><value>");
      builder.append(value.getValue());
      builder.append("</value></member>");
    }

    builder.append("</struct></value></param></params></methodCall>");

    String request = builder.toString();

    InputStream inputStream = new ByteArrayInputStream(request.getBytes());
    XmlRpcRequest actual = this.parser.parseRequest(inputStream);

    this.logger.info("XML-RPC request: " + request);
    this.logger.info(actual);
   
    assertEquals("<XML-RPC request>", expected, actual);
View Full Code Here

   * @see XmlRpcRequestParser#parseRequest(InputStream)
   */
  public XmlRpcRequest parseRequest(InputStream inputStream) {
    Document document = loadXmlDocument(inputStream);

    XmlRpcRequest request = new XmlRpcRequest();

    Element root = document.getDocumentElement();
    NodeList children = root.getChildNodes();
    int childCount = children.getLength();

    for (int i = 0; i < childCount; i++) {
      Node child = children.item(i);

      if (child instanceof Element) {
        String childName = child.getNodeName();

        if (XmlRpcElementNames.METHOD_NAME.equals(childName)) {
          Element methodElement = (Element) child;
          String serviceAndMethodNames = DomUtils.getTextValue(methodElement);
          request.setServiceAndMethodNames(serviceAndMethodNames);

        } else if (XmlRpcElementNames.PARAMS.equals(childName)) {
          Element parametersElement = (Element) child;
          XmlRpcElement[] parameters = this
              .parseParametersElement(parametersElement);
          request.setParameters(parameters);

        } else {
          throw new XmlRpcInvalidPayloadException("Unexpected element "
              + Strings.quote(childName));
        }
View Full Code Here

    XmlRpcException xmlRpcException = null;

    try {
      InputStream requestInputStream = request.getInputStream();

      XmlRpcRequest xmlRpcRequest = this.requestParser
          .parseRequest(requestInputStream);

      String serviceName = xmlRpcRequest.getServiceName();
      if (logger.isDebugEnabled()) {
        logger.debug("Remote service: " + serviceName);
      }

      if (!exportedServices.containsKey(serviceName)) {
View Full Code Here

  /**
   * @see XmlRpcRequestParser#parseRequest(InputStream)
   */
  public XmlRpcRequest parseRequest(InputStream inputStream) {
    XmlRpcRequest request = new XmlRpcRequest();

    try {
      XMLStreamReader reader = loadXmlReader(inputStream);

      while (reader.hasNext()) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            String localName = reader.getLocalName();

            if (XmlRpcElementNames.METHOD_NAME.equals(localName)) {
              String serviceAndMethodNames = reader.getElementText();
              request.setServiceAndMethodNames(serviceAndMethodNames);

            } else if (XmlRpcElementNames.PARAMS.equals(localName)) {
              XmlRpcElement[] parameters = parseParametersElement(reader);
              request.setParameters(parameters);
            }
        }
      }
      reader.close();
    } catch (XMLStreamException exception) {
View Full Code Here

TOP

Related Classes of org.springmodules.remoting.xmlrpc.support.XmlRpcRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.