Need help on REST client communicating with remote server

micheal john

micheal john

@micheal-john-l1fIn3 • Oct 26, 2024
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);


😀

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Feb 10, 2014

    A very nice explanation for your Problem.

    #-Link-Snipped-#

    I don't know anything about this language, but it is clear you are passing request parameters in incorrect way
  • micheal john

    micheal john

    @micheal-john-l1fIn3 Feb 10, 2014

    Manish Goyal
    A very nice explanation for your Problem.

    #-Link-Snipped-#

    I don't know anything about this language, but it is clear you are passing request parameters in incorrect way
    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"
  • micheal john

    micheal john

    @micheal-john-l1fIn3 Feb 10, 2014

  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Feb 11, 2014

    Try to turn on debug level, it will show you actual error,
  • micheal john

    micheal john

    @micheal-john-l1fIn3 Feb 12, 2014

    @#-Link-Snipped-#, 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
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Feb 12, 2014

    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