Esempio n. 1
0
  /**
   * Performs an XML-RPC call.
   *
   * @param action ONE action
   * @param args ONE arguments
   * @return The server's xml-rpc response encapsulated
   */
  public OneResponse call(String action, Object... args) {
    boolean success = false;
    String msg = null;

    try {
      Object[] params = new Object[args.length + 1];

      params[0] = oneAuth;

      for (int i = 0; i < args.length; i++) params[i + 1] = args[i];

      Object[] result = (Object[]) client.execute("one." + action, params);

      success = (Boolean) result[0];

      // In some cases, the xml-rpc response only has a boolean
      // OUT parameter
      if (result.length > 1) {
        try {
          msg = (String) result[1];
        } catch (ClassCastException e) {
          // The result may be an Integer
          msg = ((Integer) result[1]).toString();
        }
      }
    } catch (XmlRpcException e) {
      msg = e.getMessage();
    }

    return new OneResponse(success, msg);
  }
Esempio n. 2
0
  /**
   * @param testPlanId
   * @param testCaseId
   * @param testCaseExternalId
   * @return
   */
  @SuppressWarnings("unchecked")
  protected Execution getLastExecutionResult(
      Integer testPlanId, Integer testCaseId, Integer testCaseExternalId)
      throws TestLinkAPIException {

    Execution execution = null;

    try {
      Map<String, Object> executionData = new HashMap<String, Object>();
      executionData.put(TestLinkParams.TEST_PLAN_ID.toString(), testPlanId);
      executionData.put(TestLinkParams.TEST_CASE_ID.toString(), testCaseId);
      executionData.put(TestLinkParams.TEST_CASE_EXTERNAL_ID.toString(), testCaseExternalId);
      Object response =
          this.executeXmlRpcCall(
              TestLinkMethods.GET_LAST_EXECUTION_RESULT.toString(), executionData);
      Object[] responseArray = Util.castToArray(response);
      Map<String, Object> responseMap = (Map<String, Object>) responseArray[0];
      if (responseMap instanceof Map<?, ?> && responseMap.size() > 0) {
        execution = Util.getExecution(responseMap);
      }

    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException(
          "Error retrieving last execution result: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return execution;
  }
Esempio n. 3
0
 public void setValueAt(Object value, int aRow, int aColumn) {
   logger.debug("setValueAt(" + aRow + "," + aColumn + ")");
   Vector row = (Vector) rows.elementAt(aRow);
   try {
     Boolean n;
     Vector params = new Vector();
     if (aColumn == 1) {
       // id, name, id_obj
       params.add((Integer) row.elementAt(4));
       params.add((String) value);
       params.add(id_obj);
       n = (Boolean) xmlClient.execute("DateiHandler.updateName", params);
     } else if (aColumn == 2) {
       // id, beschreibung, id_obj
       params.add((Integer) row.elementAt(4));
       params.add((String) value);
       params.add(id_obj);
       n = (Boolean) xmlClient.execute("DateiHandler.updateBeschreibung", params);
     } else {
       return;
     }
   } catch (XmlRpcException e) {
     MsgBox.error(e.getMessage());
     return;
   }
   row.setElementAt(value, aColumn);
 }
  public void init() {

    try {

      server = new XmlRpcServletServer();

      mapping = new PropertyHandlerMapping();

      cl = Thread.currentThread().getContextClassLoader();

      // Here we load the property handler file

      mapping.load(cl, (propertyFilePath + propertyFile));

      server.setHandlerMapping(mapping);

      serverConfig = (XmlRpcServerConfigImpl) server.getConfig();

      serverConfig.setEnabledForExceptions(true);

      serverConfig.setEnabledForExtensions(true);

      server.setConfig(serverConfig);

    } catch (XmlRpcException e) {

      e.getMessage();

    } catch (IOException e) {

      e.getMessage();
    }
  }
Esempio n. 5
0
  public void addRow(String name, java.util.Date modified, String base64) {
    logger.debug("addRow(" + name + ")");
    Vector row;
    try {
      Vector params = new Vector(6);
      params.add(name);
      params.add(modified);
      params.add(base64);
      params.add(id_obj);
      row = (Vector) xmlClient.execute("DateiHandler.insertDatei", params);
    } catch (XmlRpcException e) {
      MsgBox.error(e.getMessage());
      return;
    }

    Integer id = (Integer) row.elementAt(0);
    String thumb = (String) row.elementAt(1);

    Vector rowData = new Vector();
    if (thumb != null) {

      rowData.add(new ImageIcon(Base64.decode(thumb.getBytes())));

    } else {
      rowData.add(new ImageIcon());
    }

    rowData.add(name);
    rowData.add("");
    rowData.add(modified);
    rowData.add(id);
    rows.addElement(rowData);
    fireTableDataChanged();
  }
Esempio n. 6
0
  /**
   * @param fkId
   * @param fkTable
   * @param title
   * @param description
   * @param fileName
   * @param fileType
   * @param file
   * @return Attachment
   * @throws TestLinkAPIException
   */
  @SuppressWarnings("unchecked")
  protected Attachment uploadAttachment(
      Integer fkId,
      String fkTable,
      String title,
      String description,
      String fileName,
      String fileType,
      String content)
      throws TestLinkAPIException {
    Attachment attachment = null;

    Integer id = 0;

    attachment =
        new Attachment(id, fkId, fkTable, title, description, fileName, null, fileType, content);

    try {
      Map<String, Object> executionData = Util.getAttachmentMap(attachment);
      Object response =
          this.executeXmlRpcCall(TestLinkMethods.UPLOAD_ATTACHMENT.toString(), executionData);
      Map<String, Object> responseMap = (Map<String, Object>) response;
      id = Util.getInteger(responseMap, TestLinkResponseParams.ID.toString());
      attachment.setId(id);
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException(
          "Error uploading attachment: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return attachment;
  }
Esempio n. 7
0
  /** @param nodeId */
  @SuppressWarnings("unchecked")
  protected String[] getFullPath(Integer nodeId) throws TestLinkAPIException {

    String[] names = null;

    try {
      Map<String, Object> executionData = new HashMap<String, Object>();
      executionData.put(TestLinkParams.NODE_ID.toString(), nodeId);
      Object response =
          this.executeXmlRpcCall(TestLinkMethods.GET_FULL_PATH.toString(), executionData);
      if (response instanceof Map<?, ?>) {
        Map<String, Object> responseMap = (Map<String, Object>) response;
        if (responseMap.size() > 0) {
          Object value = responseMap.get(nodeId.toString());
          Object values[] = (Object[]) value;
          names = new String[values.length];
          for (int i = 0; i < values.length; i++) {
            names[i] = values[i].toString();
          }
        }
      }

    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException(
          "Error uploading attachment: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return names;
  }
 /**
  * Execute test method with error
  *
  * @param params - parameters for test method
  * @param errorMsg - true error messages
  * @throws MalformedURLException
  */
 private void executeZoneCampaignStatisticsWithError(Object[] params, String errorMsg)
     throws MalformedURLException {
   try {
     execute(ZONE_CAMPAIGN_STATISTICS_METHOD, params);
     fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
   } catch (XmlRpcException e) {
     assertEquals(ErrorMessage.WRONG_ERROR_MESSAGE, errorMsg, e.getMessage());
   }
 }
 /**
  * Execute test method with error
  *
  * @param params - parameters for test method
  * @param errorMsg - true error messages
  * @throws MalformedURLException
  */
 private void executeAddPublisherWithError(Object[] params, String errorMsg)
     throws MalformedURLException {
   try {
     Integer result = (Integer) execute(ADD_PUBLISHER_METHOD, params);
     deletePublisher(result);
     fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
   } catch (XmlRpcException e) {
     assertEquals(ErrorMessage.WRONG_ERROR_MESSAGE, errorMsg, e.getMessage());
   }
 }
  /**
   * Execute test method with error
   *
   * @param params - parameters for test method
   * @param errorMsg - true error messages
   * @throws MalformedURLException
   */
  private void executeLinkUserToManagerWithError(Object[] params, String errorMsg)
      throws MalformedURLException {

    try {
      execute(LINK_USER_TO_MANAGER_METHOD, params);
      fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
    } catch (XmlRpcException e) {
      assertEquals(ErrorMessage.WRONG_ERROR_MESSAGE, errorMsg, e.getMessage());
    }
  }
Esempio n. 11
0
 @Deprecated
 /** Use {@link BeakerClient#authenticate(Identity identity)} instead. */
 public boolean authenticate() {
   try {
     beakerClient.authenticate(this);
   } catch (XmlRpcException e) {
     e.printStackTrace();
   }
   return true;
 }
Esempio n. 12
0
 public void SpikeItOut() {
   String command = "echo";
   // Object[] params = new Object[]{new Integer(33), new Integer(9)};
   try {
     Object result = xwrapper.runCommand(command);
   } catch (XmlRpcException e) {
     System.out.println("Could not run command " + command);
     e.printStackTrace();
   }
 }
Esempio n. 13
0
 @Deprecated
 /** Use {@link BeakerClient#authenticate(Identity identity)} instead. */
 public boolean authenticate(String login, String passwd) {
   try {
     beakerClient.authenticate(new Identity(login, passwd));
   } catch (XmlRpcException e) {
     e.printStackTrace();
   }
   return true;
 }
Esempio n. 14
0
 /**
  * Execute test method with error
  *
  * @param params - parameters for test method
  * @param errorMsg - true error messages
  * @throws MalformedURLException
  */
 @SuppressWarnings("unchecked")
 private void executeGetChannelWithError(Object[] params, String errorMsg)
     throws MalformedURLException {
   try {
     @SuppressWarnings("unused")
     Map<String, Object> result = (Map<String, Object>) execute(GET_CHANNEL_METHOD, params);
     fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
   } catch (XmlRpcException e) {
     assertEquals(ErrorMessage.WRONG_ERROR_MESSAGE, errorMsg, e.getMessage());
   }
 }
  /**
   * Test method with fields that has value less than min
   *
   * @throws MalformedURLException
   */
  public void testZoneCampaignStatisticsLessThanMinFieldValueError() throws MalformedURLException {
    Object[] params =
        new Object[] {sessionId, zoneId, DateUtils.DATE_LESS_THAN_MIN, DateUtils.MAX_DATE_VALUE};

    try {
      client.execute(ZONE_CAMPAIGN_STATISTICS_METHOD, params);
      fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
    } catch (XmlRpcException e) {
      assertEquals(ErrorMessage.YEAR_SHOULD_BE_IN_RANGE_1970_2038, e.getMessage());
    }
  }
  /**
   * Test method with fields that has value greater than max.
   *
   * @throws MalformedURLException
   * @throws XmlRpcException
   */
  public void testZoneAdvertiserStatisticsGreaterThanMaxFieldValueError()
      throws MalformedURLException, XmlRpcException {
    Object[] params =
        new Object[] {sessionId, zoneId, DateUtils.MIN_DATE_VALUE, DateUtils.DATE_GREATER_THAN_MAX};

    try {
      client.execute(ZONE_ADVERTISER_STATISTICS_METHOD, params);
      fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
    } catch (XmlRpcException e) {
      assertEquals(ErrorMessage.YEAR_SHOULD_BE_IN_RANGE_1970_2038, e.getMessage());
    }
  }
Esempio n. 17
0
  /**
   * Says hello.
   *
   * @return
   * @throws TestLinkAPIException
   */
  protected String sayHello() throws TestLinkAPIException {
    String message = null;

    try {
      Object response = this.executeXmlRpcCall(TestLinkMethods.SAY_HELLO.toString(), null);
      message = (String) response;
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException("Error saying hello: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return message;
  }
Esempio n. 18
0
  /**
   * @return
   * @throws TestLinkAPIException
   */
  protected String about() throws TestLinkAPIException {
    String message = null;

    try {
      Object response = this.executeXmlRpcCall(TestLinkMethods.ABOUT.toString(), null);
      message = (String) response;
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException("Error in about method: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return message;
  }
Esempio n. 19
0
 /* (non-Javadoc)
  * @see org.xmldb.api.base.Resource#getContent()
  */
 public Object getContent() throws XMLDBException {
   if (data != null) return data;
   Vector params = new Vector();
   params.addElement(path.toString());
   try {
     data = (byte[]) parent.getClient().execute("getBinaryResource", params);
   } catch (XmlRpcException e) {
     throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e.getMessage(), e);
   } catch (IOException e) {
     throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
   }
   return data;
 }
  public void removeCollection(XmldbURI collName) throws XMLDBException {
    if (parent != null) collName = parent.getPathURI().resolveCollectionPath(collName);

    Vector params = new Vector();
    params.addElement(collName.toString());
    try {
      client.execute("removeCollection", params);
    } catch (XmlRpcException xre) {
      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, xre.getMessage(), xre);
    } catch (IOException ioe) {
      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, ioe.getMessage(), ioe);
    }
    parent.removeChildCollection(collName);
  }
Esempio n. 21
0
  /**
   * @param str
   * @return
   * @throws TestLinkAPIException
   */
  protected String repeat(String str) throws TestLinkAPIException {
    String repeatMessage = null;

    try {
      Map<String, Object> executionData = new HashMap<String, Object>();
      executionData.put(TestLinkParams.STR.toString(), str);
      Object response = this.executeXmlRpcCall(TestLinkMethods.REPEAT.toString(), executionData);
      repeatMessage = (String) response;
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException("Error setting test mode: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return repeatMessage;
  }
Esempio n. 22
0
 public void removeRow(int aRow) {
   logger.debug("removeRow(" + aRow + ")");
   Vector row = (Vector) rows.elementAt(aRow);
   try {
     Vector params = new Vector(1);
     params.add((Integer) row.elementAt(4)); // id
     params.add(id_obj);
     Boolean bol = (Boolean) xmlClient.execute("DateiHandler.deleteDatei", params);
   } catch (XmlRpcException e) {
     MsgBox.error(e.getMessage());
     return;
   }
   rows.removeElementAt(aRow);
   fireTableDataChanged();
 }
 public Map<String, Object> generateTTS(
     String inVoiceName, String inLangAbbr, String inText, int inPriority) {
   final String theProcessName = ProcessName.getProcessName();
   final Object[] params =
       new Object[] {theProcessName, inVoiceName, inLangAbbr, inText, new Integer(inPriority)};
   try {
     return (Map<String, Object>)
         this.mXmlRpcClient.execute(
             TTSServerImpl.HANDLER_PREFIX + TTSServerImpl.GENERATE_TTS_METHOD, params);
   } catch (final XmlRpcException e) {
     TTSClient.LOGGER.fatal(e, e);
     System.err.println("XMLException : " + e.getMessage());
   }
   return null;
 }
Esempio n. 24
0
  /**
   * Sets test mode.
   *
   * @param testMode
   * @return true
   * @throws TestLinkAPIException
   */
  protected Boolean setTestMode(Boolean testMode) throws TestLinkAPIException {
    Boolean result = null;

    try {
      Map<String, Object> executionData = new HashMap<String, Object>();
      executionData.put(TestLinkParams.TEST_MODE.toString(), testMode);
      Object response =
          this.executeXmlRpcCall(TestLinkMethods.SET_TEST_MODE.toString(), executionData);
      result = (Boolean) response;
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException("Error setting test mode: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return result;
  }
Esempio n. 25
0
 @SuppressWarnings("unchecked")
 public String whoAmI() {
   Map<String, String> me = new HashMap<String, String>();
   try {
     me = (Map<String, String>) callOnBeaker(XmlRpcApi.AUTH_WHO_AM_I, new Object[] {});
   } catch (XmlRpcException e) {
     if (e.getMessage().contains("Please log in first")) {
       me.put("username", "unauthenticated");
     } else {
       me.put("username", "unknown");
       System.err.println("ERROR: " + e.getMessage());
     }
   }
   return me.get("username");
 }
Esempio n. 26
0
  /**
   * Checks if the given user exist.
   *
   * @param user
   * @return
   * @throws TestLinkAPIException
   */
  protected Boolean doesUserExist(String user) throws TestLinkAPIException {
    Boolean userExist = false;

    try {
      Map<String, Object> executionData = new HashMap<String, Object>();
      executionData.put(TestLinkParams.USER.toString(), user);
      Object response =
          this.executeXmlRpcCall(TestLinkMethods.DOES_USER_EXIST.toString(), executionData);
      userExist = Boolean.valueOf(response.toString());
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException(
          "Error verifying if user exists: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return userExist;
  }
Esempio n. 27
0
  protected Boolean checkDevKey(String devKey) throws TestLinkAPIException {
    Boolean statusOk = false;

    try {
      Map<String, Object> executionData = new HashMap<String, Object>();
      executionData.put(TestLinkParams.DEV_KEY.toString(), devKey);
      Object response =
          this.executeXmlRpcCall(TestLinkMethods.CHECK_DEV_KEY.toString(), executionData);
      statusOk = Boolean.valueOf(response.toString());
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException(
          "Error verifying developer key: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return statusOk;
  }
  /**
   * @see org.ofbiz.webapp.event.EventHandler#invoke(Event,
   *     org.ofbiz.webapp.control.ConfigXMLReader.RequestMap, HttpServletRequest,
   *     HttpServletResponse)
   */
  public String invoke(
      Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response)
      throws EventHandlerException {
    String report = request.getParameter("echo");
    if (report != null) {
      StringBuilder buf = new StringBuilder();
      try {
        // read the inputstream buffer
        String line;
        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
        while ((line = reader.readLine()) != null) {
          buf.append(line).append("\n");
        }
      } catch (Exception e) {
        throw new EventHandlerException(e.getMessage(), e);
      }
      Debug.logInfo("Echo: " + buf.toString(), module);

      // echo back the request
      try {
        response.setContentType("text/xml");
        Writer out = response.getWriter();
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        out.write("<methodResponse>");
        out.write("<params><param>");
        out.write("<value><string><![CDATA[");
        out.write(buf.toString());
        out.write("]]></string></value>");
        out.write("</param></params>");
        out.write("</methodResponse>");
        out.flush();
      } catch (Exception e) {
        throw new EventHandlerException(e.getMessage(), e);
      }
    } else {
      try {
        this.execute(this.getXmlRpcConfig(request), new HttpStreamConnection(request, response));
      } catch (XmlRpcException e) {
        Debug.logError(e, module);
        throw new EventHandlerException(e.getMessage(), e);
      }
    }

    return null;
  }
  public Hashtable runFunc(String function, Vector params) {
    Hashtable h = null;
    Object o = null;
    try {
      System.out.println("RPCClient: running function: " + function);
      o = xmlrpc.execute(function, params);
    } catch (XmlRpcException e) {
      h = new Hashtable();
      h.put("status", "error");
      h.put("error", "Cannot execute XML-RPC query: (" + e.getCause() + ":" + e.toString() + ")");
      return h;
    } catch (IOException e) {
      h = new Hashtable();
      h.put("status", "error");
      h.put("error", "IO Exception executing XML-RPC query: " + e.toString());
      return h;
    }
    if (o == null) {
      h = new Hashtable();
      h.put("status", "error");
      h.put("error", "Object is NULL");
      return h;
    }

    if (!o.getClass().isInstance(new Hashtable())) {
      h = new Hashtable();
      h.put("status", "error");
      h.put("error", "Returned object is not a Hashtable - it is a " + o.getClass().getName());
      return h;
    }
    h = (Hashtable) o;

    if (!h.containsKey("status")) {
      h.put("status", "error");
      h.put("error", "No status in result hash");
      return h;
    }

    String status = (String) h.get("status");
    if (status.equals("error") && !h.containsKey("error")) {
      h.put("error", "Unknown error - no error key found in hash");
    }

    return h;
  }
  /**
   * Test method without some required fields.
   *
   * @throws MalformedURLException
   */
  public void testAddZoneWithoutSomeRequiredFields() throws MalformedURLException {
    Map<String, Object> struct = new HashMap<String, Object>();
    struct.put(ZONE_NAME, "testZone");

    Object[] params = new Object[] {sessionId, struct};

    try {
      Integer result = (Integer) client.execute(ADD_ZONE_METHOD, params);
      assertNotNull(result);
      deleteZone(result);
      fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
    } catch (XmlRpcException e) {
      assertEquals(
          ErrorMessage.WRONG_ERROR_MESSAGE,
          ErrorMessage.getMessage(ErrorMessage.FIELD_IN_STRUCTURE_DOES_NOT_EXISTS, PUBLISHER_ID),
          e.getMessage());
    }
  }