C2DM не отправляется - не найдено альтернативного DNS-имени субъекта, соответствующего android.clients.google.com. - PullRequest
0 голосов
/ 21 марта 2012

Привет У меня есть следующий код, который должен c2dm для устройства Android.Когда я запускаю его на своем локальном компьютере, я получаю сообщение об ошибке

: исключение в потоке "main"соответствие имени android.clients.google.com найдено.

Кто-нибудь

public class MessageUtil 
{
    private final static String AUTH = "authentication";
    private static final String UPDATE_CLIENT_AUTH = "Update-Client-Auth";
    public static final String PARAM_REGISTRATION_ID = "registration_id";
    public static final String PARAM_DELAY_WHILE_IDLE = "delay_while_idle";
    public static final String PARAM_COLLAPSE_KEY = "collapse_key";
    private static final String UTF8 = "UTF-8";


    public static void main(String args[]) throws IOException
    {
        String auth_token=AuthenticationUtil.token;
        String registrationId="c2dmregistration id of the device";
        String message_title="Test";
        int response=sendMessage(auth_token, registrationId,message_title);
        System.out.println(response);
    }
    public static int sendMessage(String auth_token, String registrationId,String message_title) throws IOException 
    {

        URL url = new URL("https://android.clients.google.com/c2dm/send");  

        StringBuilder postDataBuilder = new StringBuilder();
        postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(registrationId);
        postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0");
        postDataBuilder.append("&").append("data.payload").append("=").append(URLEncoder.encode(message_title, UTF8));
        byte[] postData = postDataBuilder.toString().getBytes(UTF8);
        HttpURLConnection conn= (HttpURLConnection)url.openConnection(); 
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        conn.setRequestProperty("Content-Length",Integer.toString(postData.length));
        conn.setRequestProperty("Authorization", "GoogleLogin auth="+ auth_token);

        OutputStream out = conn.getOutputStream();
        out.write(postData);
        out.close();

        int responseCode = conn.getResponseCode();
        return responseCode;
    }

}

Когда я запускаю этот код, я получаю следующую ошибку:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching android.clients.google.com found.
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
    at sun.security.ssl.Handshaker.processLoop(Unknown Source)
    at sun.security.ssl.Handshaker.process_record(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
    at com.metalclub.mobile.inbox.MessageUtil.sendMessage(MessageUtil.java:45)
    at com.metalclub.mobile.inbox.MessageUtil.main(MessageUtil.java:24)
Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching android.clients.google.com found.
    at sun.security.util.HostnameChecker.matchDNS(Unknown Source)
    at sun.security.util.HostnameChecker.match(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    ... 14 more

1 Ответ

0 голосов
/ 23 марта 2012

Вы отправляете сообщение на неверную конечную точку API. Правильный URL-адрес https://android.apis.google.com/c2dm/send

...