8000 GitHub - sinch/sinch-sdk-java: Sinch Java SDK
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sinch/sinch-sdk-java

Repository files navigation

Sinch Java SDK

Here you'll find documentation related to the Sinch Java SDK, including how to install it, initialize it, and start developing code using Sinch services.

To use Sinch services, you'll need a Sinch account and access keys. You can sign up for an account and create access keys at dashboard.sinch.com.

For more information on the Sinch APIs on which this SDK is based, refer to the official developer documentation portal.

Table of contents:

Prerequisites

Installation

Add to your pom.xml file the dependency to SDK:

<dependencies>
    <dependency>
      <groupId>com.sinch.sdk</groupId>
      <artifactId>sinch-sdk-java</artifactId>
      <version>${sdk.version}</version>
    </dependency>
    ...
</dependencies>

Note the ${sdk.version} need to be set according to released version to be used (see available versions from Maven Repository)

Getting started

Once the SDK is installed, you must start by initializing the main client class.

Client initialization

To initialize communication with the Sinch servers, credentials obtained from the Sinch dashboard must be provided to the main client class of this SDK.

It's highly recommended to not hardcode these credentials and to load them from environment variables instead.

Sample:

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.models.Configuration;

...
Configuration configuration = Configuration.builder()
                                .setKeyId(PARAM_KEY_ID)
                                .setKeySecret(PARAM_KEY_SECRET)
                                .setProjectId(PARAM_PROJECT_ID)
                                .build();
...
SinchClient client = new SinchClient(configuration);

Supported APIs

Here is the list of the Sinch products and their level of support by the Java SDK:

API Category API Name Status
Conversation Conversation API (javadoc)
SMS SMS API (javadoc)
Numbers & Connectivity Numbers API (javadoc)
Verification Verification API (javadoc)
Voice and Video Voice API (javadoc)

Logging

The SDK uses the Java 8 logging feature (java.util.logging)

When using java logging, Loggers and severity can be configured by using a logging.properties file like:

# java.util.logging configuration sample
# See https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html#package.description

#
# Layers logging severity configuration
#

# Sinch SDK 
com.sinch.level = INFO

# Apache HTTP Client
# org.apache.hc.level = 


#
# console output handler sample
#
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s %2$s] %5$s %n
java.util.logging.ConsoleHandler.level = FINEST

If you are using a different logging framework (such as SLF4J or Spring), please refer to the documentation for your specific framework.

Onboarding

To enhance the onboarding experience, the following resources are available:

Third-party dependencies

The SDK relies on the following third-party dependencies:

Jackson/Java EE/jaxrs/Jakarta Compatibility Consideration

The transition from javax to jakarta namespaces with the Java EE to Jakarta EE migration may cause compatibility issues. Refer to Oracle's note about the transition for additional details.

Jackson maintainers provide two variants of the library:

(*) NOTE: Jakarta-RS is the package under jakarta.ws.rs, replacing older JAX-RS which lived under javax.ws.rs. For JAX-RS variant, see repo jackson-jaxrs-providers

By default, the Sinch Java SDK uses the "new" jackson-jakarta-rs-providers. However, you can switch to the "older" jackson-jaxrs-providers if required.

Switching to jackson-jaxrs-providers

Depending on your use case, you may need to adjust dependencies to enable jaxrs usage.

Add the following dependency to your configuration: Note: Replace VERSION-YOU-WANT-TO-BE-USED by a Jackson version of at least 2.15.2.

...
    <dependency>
      <groupId>com.sinch.sdk</groupId>
      <artifactId>sinch-sdk-java</artifactId>
      <version>${sinch.sdk.java.version}</version>
      <exclusions>
        <exclusion>
          <groupId>com.fasterxml.jackson.jaxrs</groupId>
          <artifactId>jackson-jakarta-rs-json-provider</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jakarta.rs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>VERSION-YOU-WANT-TO-BE-USED</version>
    </dependency>
...
< 6FCC div class="markdown-heading" dir="auto">

Migration guides

Find migration guides in the developer documentation portal:

License

This project is licensed under the Apache License.

See the LICENSE file for the license text.

0