need help on https (code for http included)

by Marco Schmitz » Sat, 05 Sep 2009 02:17:38 GMT


Sponsored Links
 hank you droidin,

unfortunately I didnt need the httpclient but the stream.

well, I found a solution :)

btw: this is sdk 1.1 r1 code:

greetings,
marco

------------------------------------------------------------------------
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import lgpl.haustein.Base64Encoder;

import org.apache.log4j.Appender;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.spi.LoggingEvent;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

/**
* Hyper
*/
public class Hyper extends Activity {

private static Logger logger = Logger.getLogger(Hyper.class);

private static final String HTTP = "http://www.gmx.de";
private static final String HTTPS = "https://www.verisign.com/";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
logger.debug("START");

try {
SSLContext sc = SSLContext.getInstance("TLS");
scinit(null, new TrustManager[] { new MyTrustManager()
}, new
SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new
MyHostnameVerifier());
HttpsURLConnection con = (HttpsURLConnection) new
URL(HTTPS).openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.connect();

BufferedReader br = new BufferedReader(new
InputStreamReader(con.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null)
sb.append(line);

logger.debug("InputStream: " + sb.toString());

logger.debug("END");
} catch (Exception e) {
logger.error(e);
}
}

/**
* MyHostnameVerifier
*/
private class MyHostnameVerifier implements HostnameVerifier {

@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}

/**
* MyTrustManager
*/
private class MyTrustManager implements X509TrustManager {

@Override
public void checkClientTrusted(X509Certificate[] chain, String
authType) {
}

@Override
public void checkServerTrusted(X509Certificate[] chain, String
authType) {
}




Other Threads

1. glTexImage2D is too slow,who can help me,please

when draw YUV frame use opengl 2.0 and shader on nexus one,but the
function  glTexImage2D is too slow ,cost 40-60 ms
who can fix it ? the key codes:
-------------------------------------------------

int CreateSimpleTexture2D()
       {
               int err, i;



               for (i=0; i<3;i++)
               {
                       glGenTextures(1, &userData.textureId[i]);
                       if (err = glGetError()) {
                       //      NSLog(@"Error: Could not generate
texture: %d", err);

__android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error:
Could not generate texture: %d", err);
                               return 0;
                       }

                       glBindTexture(GL_TEXTURE_2D, userData.textureId[i]);
                       if (err = glGetError()) {
                       //      NSLog(@"Error: Could not bind texture: %d", err);

__android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error:
Could not bind texture: %d", err);
                               return 0;
                       }
               }

               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
               if (err = glGetError()) {
                       //NSLog(@"Error: Could not set texture
minimization filter: %d", err);

__android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error:
Could not set texture minimization filter: %d", err);
                       return 0;
               }

               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
               if (err = glGetError()) {
               //      NSLog(@"Error: Could not set texture
magnification filter: %d", err);
               
__android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error:
Could not set texture magnification filter: %d", err);
                       return 0;
               }

               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
               glGenerateMipmap(GL_TEXTURE_2D);
               return 1;
       }


---------------------------------------render frame
-------------------------------------------------
               glViewport ( 0, 0, g_WindowsWidth, g_WindowsHeight );
               checkGlError("glViewport");
               //glDrawBuffer(GL_COLOR_ATTACHMENT0);
               // Clear the color buffer
               glClear ( GL_COLOR_BUFFER_BIT );
               checkGlError("glClear");
               // Use the program object
               glUseProgram ( userData.programObject );
               checkGlError("glUseProgram");
               // Load the vertex position
               glVertexAttribPointer ( userData.positionLoc, 3, GL_FLOAT,
                                                          GL_FALSE, 5
* sizeof(GLfloat), vVertices );
               // Load the texture coordinate
               glVertexAttribPointer ( userData.texCoordLoc, 2, GL_FLOAT,
                                                          GL_FALSE, 5
* sizeof(GLfloat), &vVertices[3] );

               glEnableVertexAttribArray ( userData.positionLoc );
               glEnableVertexAttribArray ( userData.texCoordLoc );

               long long  ttttttt=av_gettime();
               // Bind the texture
               glActiveTexture ( GL_TEXTURE1 );
               glBindTexture ( GL_TEXTURE_2D, userData.textureId[1] );
               glUniform1i ( userData.samplerLocU, 1);
               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
               //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
               //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
               //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

               //glPixelStorei(GL_UNPACK_ALIGNMENT,1);

               glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width/2,
height/2, 0,
GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[1]);
               checkGlError("glTexImage2D....pict->data[1]");
               //glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width*0.5,
height*0.5, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[1]);


               // Bind the texture
               glActiveTexture ( GL_TEXTURE2 );
               glBindTexture ( GL_TEXTURE_2D, userData.textureId[2] );
               glUniform1i ( userData.samplerLocV, 2);
               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
               //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
               //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
               //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
               //glPixelStorei(GL_UNPACK_ALIGNMENT,1);


               glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,width/2, height/2, 0,
GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[2]);

               checkGlError("glTexImage2D....pict->data[2]");
               // Set the sampler texture unit to 0
               glActiveTexture ( GL_TEXTURE0 );
               glBindTexture ( GL_TEXTURE_2D, userData.textureId[0] );
               glUniform1i ( userData.samplerLocY, 0);
               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
               glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
               //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
               //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
               //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
               //glPixelStorei(GL_UNPACK_ALIGNMENT,1);


               glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[0]);
               
__android_log_print(ANDROID_LOG_ERROR,"GPU","%lld",(av_gettime()-ttttttt)/1000);
               checkGlError("glTexImage2D....pict->data[0]");
               glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Update WTS: Desire + Nexus seken

Sori saya update di milis..
Karena banyak yang japri. 
Yang deal pertama langsung deal
Yang minat tapi pake tanya sori kena skip :)


@yopiesuryadi
hope for a better future 
http://bit.ly/9KHYOI

-----Original Message-----
From: "yopie suryadi" <yo...@anjroid.net>
Date: Fri, 19 Nov 2010 00:15:57 
To: Idandroid<id-android@googlegroups.com>; 
Isat-android<isat-andr...@googlegroups.com>
Reply-To: yo...@anjroid.net
Subject: WTS: Desire + Nexus seken

Permisi...
Saya mau jualan ni

- desire seken supermulus komplit 4jt aja
- nexus supermulus (mint condition) 4,1jt aja
- motorola backflip supermulus 2,3jt aja

Bnib:
- htc desire
- motorola backflip

Harga sudah nett. 
No nego sama sekali. 
Yang nego saya skip...

Minat harap japri ke yo...@ratjoen.com atau telp langsung (no sms). 

Thanks


@yopiesuryadi
hope for a better future 
http://bit.ly/9KHYOI

-- 
===============
"Indonesian Android Community [id-android]"

PING'S mobile
Email: sa...@pings-mobile.com  Ph. (021) 96087100
---------------------
Yopie Ratjoen
Email: yo...@ratjoen.com  Ph. 08977726681
--------------------
Gila original
Email: i...@gilaoriginal.com  Ph. (031) 91555898
--------------------

Aturan Jual/Kloteran ID-Android  http://goo.gl/azW7

3. This Weekend Prize

4. (WTA n Share) tanya2 seputar samsung epic 4g

5. ClassNotFoundException for a compiled class

6. System.nanoTime() for Dual Core processors

7. Pendatang baru nih