Source:
<code>public void editEndpoint(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, LanguageException { try { String serverName = request.getParameter("serverName"); String id = request.getParameter("identifier"); PublishingEndPoint existingServer = APILocator.getPublisherEndPointAPI().findEndPointByName(serverName); if(existingServer!=null && !id.equals(existingServer.getId())) { Logger.info(getClass(), "Can't save EndPoint. An Endpoint with the given name already exists. "); User user = getUser(); response.getWriter().println("FAILURE: " + LanguageUtil.get(user, "publisher_Endpoint_name_exists")); return; } final String protocol = request.getParameter("protocol"); <START> final PublishingEndPointFactory factory = new PublishingEndPointFactory(); <END> PublishingEndPoint endpoint = factory.getPublishingEndPoint(protocol); endpoint.setId(id); endpoint.setServerName(new StringBuilder(request.getParameter("serverName"))); endpoint.setAddress(request.getParameter("address")); endpoint.setPort(request.getParameter("port")); endpoint.setProtocol(request.getParameter("protocol")); endpoint.setAuthKey(new StringBuilder(PublicEncryptionFactory.encryptString(request.getParameter("authKey")))); endpoint.setEnabled(null!=request.getParameter("enabled")); endpoint.setSending("true".equals(request.getParameter("sending"))); endpoint.setGroupId(request.getParameter("environmentId")); endpoint.validatePublishingEndPoint(); PublishingEndPointAPI peAPI = APILocator.getPublisherEndPointAPI(); peAPI.updateEndPoint(endpoint); } catch (DotDataException e) { Logger.info(getClass(), "Error editing EndPoint. Error Message: " + e.getMessage()); response.getWriter().println("FAILURE: " + e.getMessage()); } }</code><technical_language>factory instance a instance variable re-use</technical_language>

Target:
public void editEndpoint(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, LanguageException { try { String serverName = request.getParameter("serverName"); String id = request.getParameter("identifier"); PublishingEndPoint existingServer = APILocator.getPublisherEndPointAPI().findEndPointByName(serverName); if(existingServer!=null && !id.equals(existingServer.getId())) { Logger.info(getClass(), "Can't save EndPoint. An Endpoint with the given name already exists. "); User user = getUser(); response.getWriter().println("FAILURE: " + LanguageUtil.get(user, "publisher_Endpoint_name_exists")); return; } final String protocol = request.getParameter("protocol"); PublishingEndPoint endpoint = factory.getPublishingEndPoint(protocol); endpoint.setId(id); endpoint.setServerName(new StringBuilder(request.getParameter("serverName"))); endpoint.setAddress(request.getParameter("address")); endpoint.setPort(request.getParameter("port")); endpoint.setProtocol(request.getParameter("protocol")); endpoint.setAuthKey(new StringBuilder(PublicEncryptionFactory.encryptString(request.getParameter("authKey")))); endpoint.setEnabled(null!=request.getParameter("enabled")); endpoint.setSending("true".equals(request.getParameter("sending"))); endpoint.setGroupId(request.getParameter("environmentId")); try { endpoint.validatePublishingEndPoint(); } catch (PublishingEndPointValidationException e){ throw new DotDataException(handlePublishingEndPointValidationException(e)); } PublishingEndPointAPI peAPI = APILocator.getPublisherEndPointAPI(); peAPI.updateEndPoint(endpoint); } catch (DotDataException e) { Logger.info(getClass(), "Error editing EndPoint. Error Message: " + e.getMessage()); response.getWriter().println("FAILURE: " + e.getMessage()); } }