2016-10-18 2 views
0

Я пытаюсь отправить sms через веб-службу Amazon. Я загрузил sd
package com.sms;Исключение в теме «main» java.lang.NoSuchFieldError: INSTANCE в AWS SNS

import java.util.HashMap; 
import java.util.Map; 

import com.sms.AwsClientFactoryDemo; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

import com.amazonaws.services.sns.model.MessageAttributeValue; 
import com.amazonaws.services.sns.model.PublishRequest; 
import com.amazonaws.services.sns.model.PublishResult; 

public class SmsNotificationService { 
    private static final Logger LOG = LoggerFactory.getLogger(SmsNotificationService.class); 

    public PublishResult send(String phoneNumber, String message) { 
     Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>(); 
     smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue() 
       .withStringValue("Lightside") //The sender ID shown on the device (except in US) 
       .withDataType("String")); 
     smsAttributes.put("AWS.SNS.SMS.MaxPrice", new MessageAttributeValue() 
       .withStringValue("0.01") //Sets the max price to 0.01 USD. 
       .withDataType("Number")); 
     smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue() 
       .withStringValue("Promotional") //Sets the type to promotional. 
       .withDataType("String")); 
     PublishResult result = AwsClientFactoryDemo.getSnsClient().publish(new PublishRequest() 
       .withMessage(message) 
       .withPhoneNumber(phoneNumber) 
       .withMessageAttributes(smsAttributes)); 
     LOG.info("Sent SMS message ID: " + result.getMessageId()); 
     return result; 
    } 

} 

Я получаю следующую ошибку в приведенном выше коде при попытке отправить смс через aws sns.

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE 
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144) 
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheConnectionManagerFactory.java:87) 
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:65) 
    at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:58) 
    at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:51) 
    at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:39) 
    at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:300) 
    at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:164) 
    at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:153) 
    at com.amazonaws.services.sns.AmazonSNSClient.<init>(AmazonSNSClient.java:207) 
    at com.amazonaws.services.sns.AmazonSNSClient.<init>(AmazonSNSClient.java:187) 
    at com.amazonaws.services.sns.AmazonSNSClient.<init>(AmazonSNSClient.java:97) 
    at com.sms.sms.main(sms.java:13) 

enter image description here

ответ

1

Это, вероятно, вызвано различными версиями зависимости HTTP клиента на пути к классам. (Reference1, Reference2) Убедитесь, что у вас есть только одна версия на пути к классам.

+0

Я включил следующие файлы jar: –

+0

aws-java-sdk-1.11.41.jar aws-java-sdk-1.11.41-javadoc.jar, aws-java-sdk-1.11.41-sources.jar, jackson-annotations-2.1.2.jar, commons-logging-1.1.2.jar, slf4j.jar, com.fasterxml.jacksoncore.jar, –

+0

com.fasterxml.jackson.databind.jar, com.fasterxml.jackson.core .jar, apache-httpcomponents-httpclient.jar, apache-httpcomponents-httpcore.jar, httpclient-4.4.jar, httpcore-4.3.jar –

Смежные вопросы