Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am using Jersey Client to make API call to validate Session. This call is being made at rate of around 5 calls/second. I want to ensure that the client call doesn't have performance issues. Please review the snippet.

String sessionUrlPrefix = Config.getInstance().getString(Helper.SESSION_SERVICE_URL);
String urlParameters = getParameters(sessionId);
String sessionURL = sessionUrlPrefix + "?" + urlParameters;
WebResource webResource = client.resource(sessionURL);
logger.debug("Session URL is " + sessionURL);
ClientResponse response = webResource
    .accept(MediaType.TEXT_PLAIN_TYPE)
    .type(MediaType.TEXT_PLAIN_TYPE)
    .get(ClientResponse.class);

String responseStr = response.getEntity(String.class);
logger.debug("Response received is " + responseStr);
if (response.getStatus() != HttpStatus.OK.value())
{
    throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    // Could throw more appropriate HttpException.
}
return responseStr;
share|improve this question

1 Answer 1

I'm not familiar with Jersey at all, so just two generic notes:

  1. You might want/could use HEAD instead GET which does not download the message body.

  2. I don't know what is logging framework but if it's SLF4J you should use the {} pattern instead of string concatenation.

    logger.debug("Session URL is {}", sessionURL);
    
share|improve this answer
    
I am using log4j as my logging framework. I will look at using {} pattern if it is supported in log4j. –  Srinivas Nov 5 '12 at 2:14
    
I also need the Message body as it contains the email id of the user etc. which is required for further validation. –  Srinivas Nov 5 '12 at 2:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.