예제 #1
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");
 }
예제 #2
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;
  }
예제 #3
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;
  }
예제 #4
0
파일: Client.java 프로젝트: hfeeki/one
  /**
   * 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);
  }
예제 #5
0
  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();
    }
  }
예제 #6
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);
 }
예제 #7
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();
  }
예제 #8
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;
  }
 /**
  * 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());
    }
  }
예제 #12
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());
    }
  }
예제 #14
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;
  }
  /**
   * 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());
    }
  }
예제 #16
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;
  }
예제 #17
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;
 }
예제 #18
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;
  }
  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);
  }
 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;
 }
예제 #21
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();
 }
예제 #22
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;
  }
예제 #23
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;
  }
예제 #24
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;
  }
예제 #25
0
  /**
   * @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;
  }
예제 #26
0
  /**
   * 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());
    }
  }
예제 #27
0
  /**
   * Get user by login.
   *
   * @param login
   * @return user
   * @throws TestLinkAPIException
   */
  @SuppressWarnings("unchecked")
  protected User getUserByLogin(String login) throws TestLinkAPIException {
    User user = null;

    try {
      Map<String, Object> executionData = new HashMap<String, Object>();
      executionData.put(TestLinkParams.USER.toString(), login);
      Object response =
          this.executeXmlRpcCall(TestLinkMethods.GET_USER_BY_LOGIN.toString(), executionData);
      Object[] responseArray = Util.castToArray(response);
      Map<String, Object> responseMap = (Map<String, Object>) responseArray[0];
      user = Util.getUser(responseMap);
    } catch (XmlRpcException xmlrpcex) {
      throw new TestLinkAPIException(
          "Error verifying if user exists: " + xmlrpcex.getMessage(), xmlrpcex);
    }

    return user;
  }
 public void copyResource(XmldbURI resourcePath, XmldbURI destinationPath, XmldbURI newName)
     throws XMLDBException {
   resourcePath = parent.getPathURI().resolveCollectionPath(resourcePath);
   if (destinationPath == null) destinationPath = resourcePath.removeLastSegment();
   else destinationPath = parent.getPathURI().resolveCollectionPath(destinationPath);
   if (newName == null) {
     newName = resourcePath.lastSegment();
   }
   Vector params = new Vector();
   params.addElement(resourcePath.toString());
   params.addElement(destinationPath.toString());
   params.addElement(newName.toString());
   try {
     client.execute("copyResource", 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);
   }
 }
  public Collection createCollection(XmldbURI collName, Date created) throws XMLDBException {
    if (parent != null) collName = parent.getPathURI().resolveCollectionPath(collName);

    Vector params = new Vector();
    params.addElement(collName.toString());

    if (created != null) {
      params.addElement(created);
    }

    try {
      client.execute("createCollection", 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);
    }
    RemoteCollection collection = new RemoteCollection(client, (RemoteCollection) parent, collName);
    parent.addChildCollection(collection);
    return collection;
  }
예제 #30
0
  /**
   * Test method with fields that has value greater than max.
   *
   * @throws MalformedURLException
   * @throws XmlRpcException
   */
  public void testAddZoneGreaterThanMaxFieldValueError()
      throws MalformedURLException, XmlRpcException {
    final String strGreaterThan255 = TextUtils.getString(256);

    Map<String, Object> struct = new HashMap<String, Object>();
    struct.put(PUBLISHER_ID, publisherId);
    struct.put(ZONE_NAME, strGreaterThan255);

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

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