Need help on REST client communicating with remote server

Discussion in 'Computer Science | IT | Networking' started by micheal john, Feb 10, 2014.

  1. micheal john

    micheal john Enthusiast

    Engineering Discipline:
    Computer Science
    Hi guys,

    Projects initial requirements is to create a client to communicate with a REST web service server(remote server) using jersey,

    i want to create a CLIENT REQUEST HEADER which contains following parameters in same order.

    Request PATTERN:

    1)GET(method)
    2)URL domain(remote)
    3)URL path
    4)date field(date and time)
    5)access key(public key)
    6)accept field(application/xml or application/json)

    amateur code:

    Client client = Client.create();
    WebResource webResource =client.resource(url);

    ClientResponse response = webResource.queryParam("Date", timeStamp+" GMT")
    .header("Authorization", requestAuthKey)
    .accept(MediaType.APPLICATION_XML_TYPE)
    .get(ClientResponse.class);


    :)
    Last edited: Feb 10, 2014
  2. Manish Goyal

    Manish Goyal Ace

    Engineering Discipline:
    Computer Science
    • Informative Informative x 1
  3. micheal john

    micheal john Enthusiast

    Engineering Discipline:
    Computer Science
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("q", "stuff"); //set parametes for request
    Client client = Client.create(config);
    client.addFilter(new LoggingFilter(System.out));
    WebResource webResource =client.resource(url);
    com.sun.jersey.api.client.WebResource.Builder builder = webResource
    .queryParams(queryParams).header("x-date", timeStamp+" GMT")
    .header("Authorization", requestAuthKey)
    .accept(MediaType.APPLICATION_XML);

    for this i'm getting 500 "internal server error"
  4. micheal john

    micheal john Enthusiast

    Engineering Discipline:
    Computer Science
  5. Manish Goyal

    Manish Goyal Ace

    Engineering Discipline:
    Computer Science
    Try to turn on debug level, it will show you actual error,
  6. micheal john

    micheal john Enthusiast

    Engineering Discipline:
    Computer Science
    @Manish Goyal, i tried debbuging for 2 long days and now i arrived at solution.

    problem was my machine time was not synchronized with the server.

    thanks you
    • Like Like x 1
  7. Manish Goyal

    Manish Goyal Ace

    Engineering Discipline:
    Computer Science
    Good to hear that, Please share what did you learn from this problem, I mean How did you find this problem that it is something related to sync time between machine time

Share This Page