logger.log(Level.WARNING, "An error occured during the handling of an HTTP client call.", e);
logger.log(Level.FINE, "An error occured during the handling of the HTTP client call.", e); call.setStatus(new DefaultStatus(Statuses.SERVER_ERROR_INTERNAL, "Unable to complete the call. " + e.getMessage()));
   public void handle(Call call)   {      try      {         // Create a new HTTP client call         ClientCall clientCall = createCall(call.getMethod().getName(), call.getResourceRef().toString(), hasInput(call));         // Add the user agent header         if(call.getClientName() != null)         {            clientCall.addRequestHeader(ConnectorCall.HEADER_USER_AGENT, call.getClientName());         }         else         {            clientCall.addRequestHeader(ConnectorCall.HEADER_USER_AGENT, FactoryImpl.VERSION_HEADER);         }         // Add the conditions         ConditionData condition = call.getCondition();          if(condition.getMatch() != null)         {            StringBuilder value = new StringBuilder();                        for(int i = 0; i < condition.getMatch().size(); i++)            {               if(i > 0) value.append(", ");               value.append(condition.getMatch().get(i).getName());            }            clientCall.addRequestHeader(ConnectorCall.HEADER_IF_MATCH, value.toString());         }                  if(condition.getModifiedSince() != null)         {            String imsDate = DateUtils.format(condition.getModifiedSince(), DateUtils.FORMAT_RFC_1123[0]);            clientCall.addRequestHeader(ConnectorCall.HEADER_IF_MODIFIED_SINCE, imsDate);         }                  if(condition.getNoneMatch() != null)         {            StringBuilder value = new StringBuilder();                        for(int i = 0; i < condition.getNoneMatch().size(); i++)            {               if(i > 0) value.append(", ");               value.append(condition.getNoneMatch().get(i).getName());            }            clientCall.addRequestHeader(ConnectorCall.HEADER_IF_NONE_MATCH, value.toString());         }         if(condition.getUnmodifiedSince() != null)         {            String iusDate = DateUtils.format(condition.getUnmodifiedSince(), DateUtils.FORMAT_RFC_1123[0]);            clientCall.addRequestHeader(ConnectorCall.HEADER_IF_UNMODIFIED_SINCE, iusDate);         }                  // Add the cookies         if(call.getCookies().size() > 0)         {            String cookies = CookieUtils.format(call.getCookies());            clientCall.addRequestHeader(ConnectorCall.HEADER_COOKIE, cookies);         }                  // Add the referrer header         if(call.getReferrerRef() != null)         {            clientCall.addRequestHeader(ConnectorCall.HEADER_REFERRER, call.getReferrerRef().toString());         }         // Add the preferences         PreferenceData pref = call.getPreference();         if(pref.getMediaTypes().size() > 0)         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT, PreferenceUtils.format(pref.getMediaTypes()));         }         else         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT, MediaTypes.ALL.getName());         }                  if(pref.getCharacterSets().size() > 0)         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT_CHARSET, PreferenceUtils.format(pref.getCharacterSets()));         }         else         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT_CHARSET, CharacterSets.ALL.getName());         }                  if(pref.getEncodings().size() > 0)         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT_ENCODING, PreferenceUtils.format(pref.getEncodings()));         }         else         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT_ENCODING, Encodings.ALL.getName());         }                  if(pref.getLanguages().size() > 0)         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT_LANGUAGE, PreferenceUtils.format(pref.getLanguages()));         }         else         {            clientCall.addRequestHeader(ConnectorCall.HEADER_ACCEPT_LANGUAGE, Languages.ALL.getName());         }         // Add the security         ChallengeResponse response = call.getSecurity().getChallengeResponse();         if(response != null)         {            clientCall.addRequestHeader(ConnectorCall.HEADER_AUTHORIZATION, SecurityUtils.format(response));         }                  // Add the custom headers that may have been set by the user         Parameter header;         for(Iterator<Parameter> iter = call.getConnectorCall().getRequestHeaders().iterator(); iter.hasNext();)         {            header = iter.next();            clientCall.addRequestHeader(header.getName(), header.getValue());         }                  // Send the input representation         if(hasInput(call))         {         	if(call.getInput().getSize() > 0)         	{         		clientCall.addRequestHeader(ConnectorCall.HEADER_CONTENT_LENGTH, Long.toString(call.getInput().getSize()));         	}         	         	if(call.getInput().getMetadata().getMediaType() != null)         	{         		clientCall.addRequestHeader(ConnectorCall.HEADER_CONTENT_TYPE, call.getInput().getMetadata().getMediaType().toString());         	}         	         	if(call.getInput().getMetadata().getEncoding() != null)         	{         		clientCall.addRequestHeader(ConnectorCall.HEADER_CONTENT_ENCODING, call.getInput().getMetadata().getEncoding().toString());         	}         	         	if(call.getInput().getMetadata().getLanguage() != null)         	{         		clientCall.addRequestHeader(ConnectorCall.HEADER_CONTENT_LANGUAGE, call.getInput().getMetadata().getLanguage().toString());         	}         }                  // Commit the request headers         clientCall.sendRequestHeaders();         // Send the input representation         if(hasInput(call))         {            clientCall.sendRequestInput(call.getInput());         }         // Get the response status         call.setStatus(new DefaultStatus(clientCall.getResponseStatusCode(), null, clientCall.getResponseReasonPhrase(), null));         // Get the server address         call.setServerAddress(clientCall.getResponseAddress());         // Update the connector call associated with the uniform call         // so that advanced users can read the response headers, etc.         call.setConnectorCall(clientCall);                  // Get the response output         ContentType contentType = null;         Date expires = null;         Date lastModified = null;         Encoding encoding = null;         Language language = null;         Tag tag = null;                  for(Iterator<Parameter> iter = clientCall.getResponseHeaders().iterator(); iter.hasNext(); )         {            header = iter.next();                        if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_CONTENT_TYPE))            {               contentType = new ContentType(header.getValue());            }            else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_EXPIRES))            {               expires = clientCall.parseDate(header.getValue(), false);            }            else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_CONTENT_ENCODING))            {               encoding = new DefaultEncoding(header.getValue());            }            else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_CONTENT_LANGUAGE))            {               language = new DefaultLanguage(header.getValue());            }            else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_LAST_MODIFIED))            {               lastModified = clientCall.parseDate(header.getValue(), false);            }            else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_ETAG))            {               tag = new Tag(header.getValue());            }            else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_LOCATION))            {               call.setRedirectionRef(header.getValue());            }            else if((header.getName().equalsIgnoreCase(ConnectorCall.HEADER_SET_COOKIE)) ||                  (header.getName().equalsIgnoreCase(ConnectorCall.HEADER_SET_COOKIE2)))            {               try               {                  CookieReader cr = new CookieReader(header.getValue());                  call.getCookieSettings().add(cr.readCookieSetting());               }               catch(Exception e)               {                  logger.log(Level.WARNING, "Error during cookie setting parsing. Header: " + header.getValue(), e);               }            }            else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_WWW_AUTHENTICATE))            {               ChallengeRequest request = SecurityUtils.parseRequest(header.getValue());               call.getSecurity().setChallengeRequest(request);            }                        else if(header.getName().equalsIgnoreCase(ConnectorCall.HEADER_SERVER))            {               call.setServerName(header.getValue());            }                     }                  // Set the output representation         if(contentType != null)         {            Representation output = null;            if(clientCall.getResponseStream() != null)            {               output = new InputRepresentation(clientCall.getResponseStream(), contentType.getMediaType());            }            else if(clientCall.getResponseChannel() != null)            {               output = new ReadableRepresentation(clientCall.getResponseChannel(), contentType.getMediaType());            }            if(output != null)            {               if(contentType != null) output.getMetadata().setCharacterSet(contentType.getCharacterSet());               output.getMetadata().setEncoding(encoding);               output.getMetadata().setExpirationDate(expires);               output.getMetadata().setLanguage(language);               output.getMetadata().setModificationDate(lastModified);               output.getMetadata().setTag(tag);               call.setOutput(output);            }         }      }      catch(Exception e)      {         logger.log(Level.WARNING, "An error occured during the handling of an HTTP client call.", e);      }   }