Пример #1
0
  public GetStreamKeyStreamServer getGetStreamKeyStreamServer(
      String songID, GetCountry country, String sesionID) {
    GetStreamKeyStreamServer res = null;
    String post =
        "{\"method\":\"getStreamKeyStreamServer\",\"header\":{\"wsKey\":\""
            + KEY
            + "\",\"sessionID\":\""
            + sesionID
            + "\"},\"parameters\":{\"songID\":\""
            + songID
            + "\",\"country\":"
            + country.getResult()
            + ",\"lowBitrate\":\"\"}}";
    ClientResource cr = new ClientResource(uri + getSignatures(post));
    try {
      res = gson.fromJson(cr.post(post).getText(), GetStreamKeyStreamServer.class);
    } catch (JsonSyntaxException e) {
      e.printStackTrace();
    } catch (ResourceException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return res;
  }
Пример #2
0
 public void doGet(String path) {
   ClientResource cr = new ClientResource(testContext, BASE_URI + path);
   try {
     cr.get();
   } catch (ResourceException e) {
     e.printStackTrace();
     Assert.fail();
   }
 }
Пример #3
0
 public void doPut(String path, String fileToPut) {
   ClientResource cr = new ClientResource(testContext, BASE_URI + path);
   LocalReference ref = new LocalReference(fileToPut);
   ref.setProtocol(Protocol.CLAP);
   ClientResource local = new ClientResource(ref);
   Representation rep = local.get();
   if (fileToPut.endsWith(".csv")) rep.setMediaType(MediaType.TEXT_CSV);
   try {
     cr.put(rep);
   } catch (ResourceException e) {
     e.printStackTrace();
     Assert.fail();
   }
 }
 /**
  * Create WADL documentation
  *
  * @param url application url
  * @param docPath repository name
  */
 protected void createWadl(String url, String docPath) {
   ClientResource cr = new ClientResource(url);
   DocWadl dw = new DocWadl(docPath);
   try {
     cr.options().write(dw.getWadlPrintStream());
     cr.options(MediaType.TEXT_HTML).write(dw.getHtmlPrintStream());
   } catch (ResourceException e) {
     e.printStackTrace();
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #5
0
  public void doDelete(String path) {
    ClientResource cr = new ClientResource(testContext, BASE_URI + path);
    try {
      cr.delete();
    } catch (ResourceException e) {
      e.printStackTrace();
      Assert.fail();
    }

    try {
      cr.get();
      Assert.fail("resource still exists after delete");
    } catch (ResourceException e) {

    }
  }
Пример #6
0
 public GetCountry getCountry() {
   GetCountry res = null;
   String post =
       "{\"method\":\"getCountry\",\"header\":{\"wsKey\":\"" + KEY + "\"},\"parameters\":[]}";
   ClientResource cr = new ClientResource(uri + getSignatures(post));
   try {
     res = gson.fromJson(cr.post(post).getText(), GetCountry.class);
   } catch (JsonSyntaxException e) {
     e.printStackTrace();
   } catch (ResourceException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return res;
 }
Пример #7
0
 public StartSession getStartSession() {
   StartSession res = null;
   String post =
       "{\"method\":\"startSession\",\"header\":{\"wsKey\":\"" + KEY + "\"},\"parameters\":[]}";
   String sig = getSignatures(post);
   ClientResource cr = new ClientResource(uri + sig);
   try {
     res = gson.fromJson(cr.post(post).getText(), StartSession.class);
   } catch (JsonSyntaxException e) {
     e.printStackTrace();
   } catch (ResourceException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return res;
 }
Пример #8
0
  /**
   * fire the supplied event to my listeners
   *
   * @param event
   */
  protected void fireEvent(EventType event) {
    Vector<URI> toDitch = null;

    for (Iterator<URI> url = _myURIs.values().iterator(); url.hasNext(); ) {
      URI thisURI = url.next();

      try {
        ClientResource client = new ClientResource(thisURI.toString());
        fireThisEvent(client, event);
      } catch (ResourceException re) {
        if (re.getStatus().getCode() == 1001) {
          if (toDitch == null) toDitch = new Vector<URI>();
          toDitch.add(thisURI);
        } else re.printStackTrace();
      }
    }

    // ok, are we ditching any?
    if (toDitch != null) {
      // yup, work through them
      for (Iterator<URI> iterator = toDitch.iterator(); iterator.hasNext(); ) {
        URI thisURI = (URI) iterator.next();

        Set<Integer> mine = _myURIs.keySet();
        for (Iterator<Integer> iterator2 = mine.iterator(); iterator2.hasNext(); ) {
          Integer thisId = (Integer) iterator2.next();
          if (_myURIs.get(thisId).equals(thisURI)) {
            _myURIs.remove(thisId);
          }
        }
      }

      // and close.
      toDitch.removeAllElements();
    }
  }
Пример #9
0
  public GetSongSearchResults getSongSearchResults(
      String query, Integer limit, Integer offset, GetCountry country) {

    GetSongSearchResults res = null;
    ClientResource cr = null;
    String post =
        "{\"method\":\"getSongSearchResults\",\"header\":{\"wsKey\":\""
            + KEY
            + "\"},\"parameters\":{\"query\":\""
            + query
            + "\",\"country\":"
            + country.getResult()
            + ",\"limit\":\""
            + limit
            + "\",\"offset\":\""
            + offset
            + "\"}}";
    //		String post = "{\"method\":\"getSongSearchResults\",\"header\":{\"wsKey\":\""+ KEY
    //						+ "\"},\"parameters\":{\"query\":\""+query
    //						+"\",\"country\":\"\",\"limit\":\""+limit
    //						+"\",\"offset\":\""+offset+"\"}}";
    String sig = getSignatures(post);

    cr = new ClientResource(uri + sig);
    try {

      res = gson.fromJson(cr.post(post).getText(), GetSongSearchResults.class);
    } catch (JsonSyntaxException e) {
      e.printStackTrace();
    } catch (ResourceException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return res;
  }