> ## Documentation Index
> Fetch the complete documentation index at: https://plivo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Upgrade from Java Legacy to v4.8.0 or Latest Version

> Migrate your Java messaging app from legacy to active SDK

## Introduction

This is a major application update. Plivo recommends you always use the latest or an active version of our SDKs for guaranteed security, stability, and uptime. The active SDK versions are designed to handle intermittent and regional failures of API requests. In addition, they offer a host of security features, such as protection against DoS attacks and bot detection for suspicious user agents.

<Warning>
  <p><strong>Deprecation notice:</strong> We’re deprecating Plivo Java SDK legacy versions lower than v4.8.0 on January 31, 2022. If you use a deprecated version of our SDK after that date, your API requests and messaging may fail intermittently.  Plivo will no longer provide bug fixes to these versions, and our support team may ask you to upgrade before debugging issues.</p>
</Warning>

## Migrate your applications

### Java version support

The Plivo Java SDK supports OpenJDK 8 and 11 and OracleJDK 8 and 11.

Use the command `Update-Package Plivo -Version 4.10.0` to upgrade to the active version of the SDK, or upgrade to the latest version.

After you upgrade to the latest version of the SDK, you should check every program that depends on it and make changes to the syntax for several kinds of operations. Here are examples of how coding differs between the deprecated legacy version of the SDK and the latest active versions.

### Import the SDK

<table>
  <tr>
    <td>
      **Legacy**
    </td>

    <td>
      **Latest**
    </td>
  </tr>

  <tr>
    <td>
      <div>
        ```java theme={null}
        import com.plivo.helper.api.client.*;
        import com.plivo.helper.xml.elements.Dial;
        ```
      </div>
    </td>

    <td>
      <div>
        ```java theme={null}
        import com.plivo.api.Plivo;
        import com.plivo.api.xml.Dial;
        ```
      </div>
    </td>
  </tr>
</table>

### Initialize

<table>
  <tr>
    <td>
      **Legacy**
    </td>

    <td>
      **Latest**
    </td>
  </tr>

  <tr>
    <td>
      <div>
        ```java theme={null}
        RestAPI api = new RestAPI("<auth_id>","<auth_token>", "v1");
        ```
      </div>
    </td>

    <td>
      <div>
        ```java theme={null}
        Plivo.init("<auth_id>","<auth_token>");
        ```
      </div>
    </td>
  </tr>
</table>

### Access resources

<table>
  <tr>
    <td>
      **Legacy**
    </td>

    <td>
      **Latest**
    </td>
  </tr>

  <tr>
    <td>
      <div>
        ```java theme={null}
        Message resp = api.makeCall(parameters);
        ```
      </div>
    </td>

    <td>
      <div>
        ```java theme={null}
        MessageCreateResponse response = Message.creator(parameters)
            .create();
        ```
      </div>
    </td>
  </tr>
</table>

### Send a message

<table>
  <tr>
    <td>
      **Legacy**
    </td>

    <td>
      **Latest**
    </td>
  </tr>

  <tr>
    <td>
      <div>
        ```java theme={null}
        package com.plivo.test;

        import java.util.LinkedHashMap;
        import com.plivo.helper.api.client.*;
        import com.plivo.helper.api.response.message.MessageResponse;
        import com.plivo.helper.exception.PlivoException;

        public class SendMessage {
            public static void main(String[] args) {
                String authId = "<auth_id>";
                String authToken = "<auth_token>";
                RestAPI api = new RestAPI(authId, authToken, "v1");

                LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
                parameters.put("src", "12025551212"); 
                parameters.put("dst", "12025552323"); 
                parameters.put("text", "Hello, this is a test message"); 
                parameters.put("url", "https://<yourdomain>.com/sms_status/");
                try {
                    MessageResponse msgResponse = api.sendMessage(parameters);
                    System.out.println(msgResponse);
                } catch (PlivoException e) {
                    System.out.println(e.getLocalizedMessage());
                }
            }
        }
        ```
      </div>
    </td>

    <td>
      <div>
        ```java theme={null}
        import java.io.IOException;
        import java.net.URL;
        import java.util.Collections;

        import com.plivo.api.Plivo;
        import com.plivo.api.exceptions.PlivoRestException;
        import com.plivo.api.models.message.Message;
        import com.plivo.api.models.message.MessageCreateResponse;

        class MessageCreate
        {
            public static void main(String [] args)
            {
                Plivo.init("<auth_id>","<auth_token>");
                try
                {
                    MessageCreateResponse response = Message.creator("+12025551212","+12025552323",
                            "Hello, this is a test message")
                            .url(new URL("https://<yourdomain>.com/sms_status/") )
                            .create();
                    System.out.println(response);
                }
                catch (PlivoRestException | IOException e)
                {
                    e.printStackTrace();
                }
            }
        }
        ```
      </div>
    </td>
  </tr>
</table>

### Retrieve a message

<table>
  <tr>
    <td>
      **Legacy**
    </td>

    <td>
      **Latest**
    </td>
  </tr>

  <tr>
    <td>
      <div>
        ```java theme={null}
        package com.plivo.test;

        import java.util.LinkedHashMap;
        import com.plivo.helper.api.client.*;
        import com.plivo.helper.api.response.message.MessageResponse;
        import com.plivo.helper.exception.PlivoException;

        public class GetDetails {
            public static void main(String[] args) {
                String authId = "<auth_id>";
                String authToken = "<auth_token>";
                RestAPI api = new RestAPI(authId, authToken, "v1");

                LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
                parameters.put("record_id", "<your_message_uuid>");
                try {
                    Message msg = api.getMessage(parameters);
                    System.out.println(msg);
                } catch (PlivoException e) {
                    System.out.println(e.getLocalizedMessage());
                }
            }
        }
        ```
      </div>
    </td>

    <td>
      <div>
        ```java theme={null}
        import java.io.IOException;
        import com.plivo.api.Plivo;
        import com.plivo.api.exceptions.PlivoRestException;
        import com.plivo.api.models.message.Message;

        class MessageGet
        {
            public static void main(String [] args)
            {
                Plivo.init("<auth_id>", "<auth_token>");
                try
                {
                    Message response = Message.getter("<your_message_uuid>")
                            .get();

                    System.out.println(response);
            
                }
                catch (PlivoRestException | IOException e)
                {
                    e.printStackTrace();
                }
            }
        }
        ```
      </div>
    </td>
  </tr>
</table>

### List all messages

<table>
  <tr>
    <td>
      **Legacy**
    </td>

    <td>
      **Latest**
    </td>
  </tr>

  <tr>
    <td>
      <div>
        ```java theme={null}
        package com.plivo.test;

        import java.util.LinkedHashMap;
        import com.plivo.helper.api.client.*;
        import com.plivo.helper.api.response.message.MessageResponse;
        import com.plivo.helper.exception.PlivoException;

        public class GetAllDetails {
            public static void main(String[] args) {
                String authId = "<auth_id>";
                String authToken = "<auth_token>";
                RestAPI api = new RestAPI(authId, authToken, "v1");
                try {
                    MessageFactory msg = api.getMessages();

                    System.out.println(msg);
                } catch (PlivoException e) {
                    System.out.println(e.getLocalizedMessage());
                }
            
                LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
                parameters.put("limit", "5"); 
                parameters.put("offset", "0"); 
                try {
                    MessageFactory msg = api.getMessages(parameters);
                    System.out.println(msg);
                } catch (PlivoException e) {
                    System.out.println(e.getLocalizedMessage());
                }
            }
        }
        ```
      </div>
    </td>

    <td>
      <div>
        ```java theme={null}
        import java.io.IOException;

        import com.plivo.api.Plivo;
        import com.plivo.api.exceptions.PlivoRestException;
        import com.plivo.api.models.message.Message;
        import com.plivo.api.models.base.ListResponse;


        class GetAllMessageList
        {
            public static void main(String [] args)
            {
                Plivo.init("<auth_id>","<auth_token>");
                try
                {
                    ListResponse<Message> response = Message.lister()
                            .limit(5)
                            .offset(0)
                            .list();
                    System.out.println(response);
                }
                catch (PlivoRestException | IOException e)
                {
                    e.printStackTrace();
                }
            }
        }
        ```
      </div>
    </td>
  </tr>
</table>
