src/main/java/org/beigesoft/replicator/service/ReplicatorXmlHttps.java
@Override
  public final void replicate(
    final Map<String, Object> pAddParams) throws Exception {
    Writer htmlWriter = (Writer) pAddParams.get("htmlWriter");
    try {
      //URL must be
      String urlSourceStr = "https://" + (String) pAddParams.get("urlSource");
      if (urlSourceStr == null || urlSourceStr.length() < 10) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "Where is no urlSource!!!");
      }
      URL url = new URL(urlSourceStr);
      String authMethod = (String) pAddParams.get("authMethod");
      if ("base".equals(authMethod)) {
        final String userName = (String) pAddParams.get("userName");
        final String userPass = (String) pAddParams.get("userPass");
        Authenticator.setDefault(new Authenticator() {
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, userPass.toCharArray());
          }
        });
      } else if ("form".equals(authMethod)) {
        CookieManager cookieManager = new CookieManager();
        CookieHandler.setDefault(cookieManager);
        cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
        requestCookiesGet(pAddParams);
        authForm(pAddParams, cookieManager);
      }
      Map<String, Integer> classesCounts = makeJob(url, pAddParams);
      if (htmlWriter != null) {
        String statusString = ", replication has been done.";
        htmlWriter.write("<h4>" + new Date().toString()
          + statusString + "</h4>");
        pAddParams.put("statusString", new Date().toString() + ", "
          + ReplicatorXmlHttp.class.getSimpleName()
          + statusString);
        this.logger.info(null, ReplicatorXmlHttp.class, statusString);
        htmlWriter.write("<table>");
        htmlWriter.write("<tr><th style=\"padding: 5px;\">Class</th><th style=\"padding: 5px;\">Total records</th></tr>");
        for (Map.Entry<String, Integer> entry : classesCounts.entrySet()) {
          htmlWriter.write("<tr>");
          htmlWriter.write("<td>" + entry.getKey() + "</td>");
          htmlWriter.write("<td>" + entry.getValue() + "</td>");
          htmlWriter.write("</tr>");
        }
        htmlWriter.write("</table>");
      }
    } catch (ExceptionWithCode ex) {
      if (htmlWriter != null) {
        htmlWriter.write(new Date().toString() + ", "
        + ReplicatorXmlHttp.class.getSimpleName()
          + ", " + ex.getShortMessage());
      }
      this.logger.error(null, ReplicatorXmlHttp.class,
        ex.getShortMessage());
      throw ex;
    }
  }
@Override
  public final void replicate(
    final Map<String, Object> pAddParams) throws Exception {
    Writer htmlWriter = (Writer) pAddParams.get("htmlWriter");
    try {
      //URL must be
      String urlSourceStr = "https://" + (String) pAddParams.get("urlSource");
      if (urlSourceStr == null || urlSourceStr.length() < 10) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "Where is no urlSource!!!");
      }
      URL url = new URL(urlSourceStr);
      String authMethod = (String) pAddParams.get("authMethod");
      if ("base".equals(authMethod)) {
        final String userName = (String) pAddParams.get("userName");
        final String userPass = (String) pAddParams.get("userPass");
        Authenticator.setDefault(new Authenticator() {
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, userPass.toCharArray());
          }
        });
      } else if ("form".equals(authMethod)) {
        CookieManager cookieManager = new CookieManager();
        CookieHandler.setDefault(cookieManager);
        cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
        requestCookiesGet(pAddParams);
        authForm(pAddParams, cookieManager);
      }
      Map<String, Integer> classesCounts = makeJob(url, pAddParams);
      if (htmlWriter != null) {
        String statusString = ", replication has been done.";
        htmlWriter.write("<h4>" + new Date().toString()
          + statusString + "</h4>");
        pAddParams.put("statusString", new Date().toString() + ", "
          + ReplicatorXmlHttp.class.getSimpleName()
          + statusString);
        this.logger.info(null, ReplicatorXmlHttp.class, statusString);
        htmlWriter.write("<table>");
        htmlWriter.write("<tr><th style=\"padding: 5px;\">Class</th><th style=\"padding: 5px;\">Total records</th></tr>");
        for (Map.Entry<String, Integer> entry : classesCounts.entrySet()) {
          htmlWriter.write("<tr>");
          htmlWriter.write("<td>" + entry.getKey() + "</td>");
          htmlWriter.write("<td>" + entry.getValue() + "</td>");
          htmlWriter.write("</tr>");
        }
        htmlWriter.write("</table>");
      }
    } catch (ExceptionWithCode ex) {
      if (htmlWriter != null) {
        htmlWriter.write(new Date().toString() + ", "
        + ReplicatorXmlHttp.class.getSimpleName()
          + ", " + ex.getShortMessage());
      }
      this.logger.error(null, ReplicatorXmlHttp.class,
        ex.getShortMessage());
      throw ex;
    }
  }
@ Override public final void replicate ( final Map < String , Object > pAddParams ) throws Exception { Writer htmlWriter = ( Writer ) pAddParams . get ( "htmlWriter" ) ; try { //URL must be String urlSourceStr = "https://" + ( String ) pAddParams . get ( "urlSource" ) ; if ( urlSourceStr == null || urlSourceStr . length ( ) < 10 ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "Where is no urlSource!!!" ) ; } URL url = new URL ( urlSourceStr ) ; String authMethod = ( String ) pAddParams . get ( "authMethod" ) ; if ( "base" . equals ( authMethod ) ) { final String userName = ( String ) pAddParams . get ( "userName" ) ; final String userPass = ( String ) pAddParams . get ( "userPass" ) ; Authenticator . setDefault ( new Authenticator ( ) { @ Override protected PasswordAuthentication getPasswordAuthentication ( ) { return new PasswordAuthentication ( userName , userPass . toCharArray ( ) ) ; } } ) ; } else if ( "form" . equals ( authMethod ) ) { CookieManager cookieManager = new CookieManager ( ) ; CookieHandler . setDefault ( cookieManager ) ; cookieManager . setCookiePolicy ( CookiePolicy . ACCEPT_ALL ) ; requestCookiesGet ( pAddParams ) ; authForm ( pAddParams , cookieManager ) ; } Map < String , Integer > classesCounts = makeJob ( url , pAddParams ) ; if ( htmlWriter != null ) { String statusString = ", replication has been done." ; htmlWriter . write ( "<h4>" + new Date ( ) . toString ( ) + statusString + "</h4>" ) ; pAddParams . put ( "statusString" , new Date ( ) . toString ( ) + ", " + ReplicatorXmlHttp . class . getSimpleName ( ) + statusString ) ; this . logger . info ( null , ReplicatorXmlHttp . class , statusString ) ; htmlWriter . write ( "<table>" ) ; htmlWriter . write ( "<tr><th style=\"padding: 5px;\">Class</th><th style=\"padding: 5px;\">Total records</th></tr>" ) ; for ( Map . Entry < String , Integer > entry : classesCounts . entrySet ( ) ) { htmlWriter . write ( "<tr>" ) ; htmlWriter . write ( "<td>" + entry . getKey ( ) + "</td>" ) ; htmlWriter . write ( "<td>" + entry . getValue ( ) + "</td>" ) ; htmlWriter . write ( "</tr>" ) ; } htmlWriter . write ( "</table>" ) ; } } catch ( ExceptionWithCode ex ) { if ( htmlWriter != null ) { htmlWriter . write ( new Date ( ) . toString ( ) + ", " + ReplicatorXmlHttp . class . getSimpleName ( ) + ", " + ex . getShortMessage ( ) ) ; } this . logger . error ( null , ReplicatorXmlHttp . class , ex . getShortMessage ( ) ) ; throw ex ; } }
<p>It will clear current database then copy
data from another with XML messages trough HTTPS connection.</p>
@param pAddParams additional params
@throws Exception - an exception
<p > It will clear current database then copy data from another with XML messages trough HTTPS connection . < / p >