예제 #1
0
  public void testcreateblog2() {
    System.out.println("Test Case to Create a Blog");
    Resource resource1 = client.resource(url);
    System.out.println("URL: " + url);
    JSONObject sendobject = new JSONObject();
    try {
      sendobject.put("subject", "sjsu_cmpe202");
      sendobject.put("description", "XML");
      sendobject.put("userid", "Shaunak");
      sendobject.put("timestamp", "11:53");

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    String jsonStringObj = sendobject.toString();
    System.out.println("Create : " + jsonStringObj);
    ClientResponse created =
        resource1
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .post(jsonStringObj);
    System.out.println(created.getStatusCode());
    System.out.println(created.getEntity(String.class));
  }
  @Test
  public void recipRegTest() {

    RestClient rc = new RestClient();

    StringBuilder strb = new StringBuilder();
    strb.append(
        "{\"userName\":\"[email protected]\",\"passWord\":\"Pan\",\"name\":\"Pan\",\"bloodGroup\":\"O+\",\"type\":\"Donor\",\"dob\":\"1987-06-28\"}");
    Resource resource = rc.resource("http://localhost:8080/donoroncall/doc/register");
    String response =
        resource
            .contentType("application/json")
            .accept("application/json")
            .post(String.class, strb.toString());
    System.out.println(response);
  }
예제 #3
0
  public static void main(String[] args) {

    try {
      // set the keystore
      SampleConstants.setKeyStore();
      // create SCIM client
      SCIMClient scimClient = new SCIMClient();
      // create a apache wink ClientHandler to intercept and identify response messages
      CharonResponseHandler responseHandler = new CharonResponseHandler();
      responseHandler.setSCIMClient(scimClient);
      // set the handler in wink client config
      ClientConfig clientConfig = new ClientConfig();
      clientConfig.handlers(new ClientHandler[] {responseHandler});
      // create a wink rest client with the above config
      RestClient restClient = new RestClient(clientConfig);

      BasicAuthInfo basicAuthInfo = new BasicAuthInfo();
      basicAuthInfo.setUserName(SampleConstants.CRED_USER_NAME);
      basicAuthInfo.setPassword(SampleConstants.CRED_PASSWORD);

      BasicAuthHandler basicAuthHandler = new BasicAuthHandler();
      BasicAuthInfo encodedBasicAuthInfo =
          (BasicAuthInfo) basicAuthHandler.getAuthenticationToken(basicAuthInfo);

      // create resource endpoint to access a known user resource.
      Resource userResource = restClient.resource(SampleConstants.USER_ENDPOINT);
      String response =
          userResource
              .header(
                  SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader())
              .contentType(SCIMConstants.APPLICATION_JSON)
              .accept(SCIMConstants.APPLICATION_JSON)
              .get(String.class);

      // decode the response
      System.out.println(response);
    } catch (ClientWebException e) {
      System.out.println(e.getRequest().getEntity());
      System.out.println(e.getResponse().getMessage());
      e.printStackTrace();
    }
  }