Java https post gets "No peer certificate" from app engine server

0 views
Skip to first unread message

Jjang via StackOverflow

unread,
Jun 4, 2014, 2:49:49 PM6/4/14
to google-appengin...@googlegroups.com

I've tried reading alot about similar problems here in StackOverflow but nothing resolved my problem.

Few days ago I upgraded my app engine server to work with secure HTTP requests only (HTTPS). (Since I do not use custom domain, this procedure involved one line for each url in the app.yaml file stating 'secure: always').

Everything worked fine, I indeed manage to get response from my app engine server using my android client, but today, I started getting this errors sometimes:

06-04 20:11:29.501: W/System.err(21158): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
06-04 20:11:29.504: W/System.err(21158):    at com.android.org.conscrypt.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:146)
06-04 20:11:29.505: W/System.err(21158):    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
06-04 20:11:29.505: W/System.err(21158):    at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:388)
06-04 20:11:29.505: W/System.err(21158):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
06-04 20:11:29.506: W/System.err(21158):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
06-04 20:11:29.506: W/System.err(21158):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
06-04 20:11:29.506: W/System.err(21158):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
06-04 20:11:29.507: W/System.err(21158):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-04 20:11:29.507: W/System.err(21158):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-04 20:11:29.507: W/System.err(21158):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

This is the code in the client:

static private HttpClient createHttpClient()
{
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    return new DefaultHttpClient(conMgr, params);
}

static private String getJson(String json,String url){
    ///HttpClient httpClient = new DefaultHttpClient();
    HttpClient httpClient = createHttpClient();
    String responseString="";
    try {
        HttpPost request = new HttpPost("https://XXXXXX.appspot.com/XXXX/XXXX");
        StringEntity params =new StringEntity(json, "UTF-8");
        request.addHeader("content-type", "application/json");
        request.setEntity(params);
        HttpResponse response = httpClient.execute(request);
        HttpEntity entity = response.getEntity();
        responseString = EntityUtils.toString(entity, "UTF-8");


    }catch (Exception ex) {
        ex.printStackTrace();
        // handle exception here
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
    return responseString;
}

Any ideas why?

P.S I've added the createHttpClient() method because I saw some people here whom it solved their problem... I tried using this and using the defaulHttpClient, but none works good.

Thanks alot!



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/24045259/java-https-post-gets-no-peer-certificate-from-app-engine-server
Reply all
Reply to author
Forward
0 new messages