private String lookupObject(final String contextKey) {

    WebClient client =
        getWebClient()
            .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON)
            .path(CALL_PATH, contextKey);

    String object = null;
    try {
      object = client.get(String.class);
    } catch (NotFoundException e) {
      return null;
    } catch (WebApplicationException e) {
      handleWebException(e);
    } catch (Throwable e) {
      if (e instanceof ConnectException || e instanceof ClientException) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        return lookupObject(contextKey);
      }
    } finally {
      if (null != client) {
        client.reset();
      }
    }

    return object;
  }
  private void deleteObject(final String key) {

    WebClient client =
        getWebClient()
            .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON)
            .path(CALL_PATH, key);

    try {
      client.delete();
    } catch (NotFoundException e) {
      return;
    } catch (WebApplicationException e) {
      handleWebException(e);
    } catch (Throwable e) {
      if (e instanceof ConnectException || e instanceof ClientException) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        deleteObject(key);
      }
    } finally {
      if (null != client) {
        client.reset();
      }
    }
  }
 public String execute(
     HttpServletRequest request, HttpServletResponse response, WebClient client) {
   log.debug("Update person");
   String result = "/searchPerson.jsp";
   String firstName = (String) request.getParameter("name");
   String lastName = (String) request.getParameter("surname");
   String date = (String) request.getParameter("date");
   String login = (String) request.getParameter("log");
   String email = (String) request.getParameter("mail");
   Person person = new Person(firstName, lastName, date);
   person.setLogin(login);
   person.setEmail(email);
   int i = client.path("/PersonService/updatePerson").put(person).getStatus();
   client.reset();
   if (i == Response.Status.OK.getStatusCode()) {
     request.setAttribute("person", person);
     return result;
   }
   if (i == Response.Status.NOT_FOUND.getStatusCode()) {
     log.debug("Person with login " + person.getLogin() + " not found");
     request.setAttribute("error", "Person with login " + person.getLogin() + " not found");
     result = "/error.jsp";
   }
   if (i == Response.Status.CONFLICT.getStatusCode()) {
     log.debug("Error occured while updating person");
     request.setAttribute("error", "Error occured while updating person");
     result = "/error.jsp";
   }
   return result;
 }
  @Override
  public String saveObject(E ctx) {

    String key = findAuxiliaryObjectFactory().createObjectKey(ctx);

    WebClient client =
        getWebClient()
            .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON)
            .path(CALL_PATH, key);

    try {
      Response resp = client.put(findAuxiliaryObjectFactory().marshalObject(ctx));
      if (resp.getStatus() == 404) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        return saveObject(ctx);
      }

      return key;
    } catch (WebApplicationException e) {
      handleWebException(e);
    } catch (Throwable e) {
      if (e instanceof ConnectException || e instanceof ClientException) {
        if (null != client) {
          client.reset();
        }
        switchServerURL(client.getBaseURI().toString());
        return saveObject(ctx);
      }
    } finally {
      if (null != client) {
        client.reset();
      }
    }
    return null;
  }