Hi friends, I am trying to get a reponse of 200 I did all this. If I convert "TLS" to "SSL" its throws exception again which I am getting alwaz. Please anyone help me to get a response and response data. I dont understd where exactly the problem is?
public class Signin extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.signin);
Button signin = (Button) findViewById(R.id.btn_signin1);
signin.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.btn_signin1:
Intent intent = new Intent(this, Password.class);
createNounce();
httpConnect();
startActivity(intent);
break;
}
}
// always verify the host - dont check for certificate
final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
/**
* Trust every server - dont check for any certificate
*/
private static void trustAllHosts() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
boolean isComplete;
InputStream _in;
private StringBuffer msg;
private String responsData;
private String input;
public void httpConnect(){
URL url;
try {
url = new URL("https://rhel-dev4.acclaris.net/benefits/webservices/GetLoginInfoMAService");
HttpURLConnection _httpconn = null;
if (url.getProtocol().toLowerCase().equals("https")) {
trustAllHosts();
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
https.setHostnameVerifier(DO_NOT_VERIFY);
_httpconn = https;
} else {
_httpconn = (HttpURLConnection) url.openConnection();
}
_httpconn.setRequestMethod("POST");
//_httpconn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
_httpconn.setRequestProperty("SOAPAction", "GetLoginInfoMA");
_httpconn.setRequestProperty("Content-Type", "text/xml");
_httpconn.setRequestProperty("User-Agent", "kSOAP/1.0");
String clen = Integer.toString(input.length());
_httpconn.setRequestProperty("Content-Length", clen);
_httpconn.setDoInput(true);
_httpconn.setDoOutput(true);
System.out.println("------------clen--------------------------------");
int rc = _httpconn.getResponseCode();
System.out.println("------------resp code--------------------------------"+rc);
if(rc == HttpsURLConnection.HTTP_OK)
{
isComplete = true;
_in = _httpconn.getInputStream();
msg = new StringBuffer();
byte[] data = new byte[1024];
int len = 0;
int size = 0;
while ( -1 != (len = _in.read(data)) )
{
msg.append(new String(data, 0, len));
size += len;
}
responsData = msg.toString();
System.out.println(""+responsData.toString());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void createNounce() {
try{
String planeTextUsername = "objectsolwsuser";
String planeTextPassword = "local123";
UUID guid = UUID.randomUUID();
String[] txt = TextSplit.split(guid.toString(), "-");
System.out.println(" Guid : " + txt[0]);
String nonce = txt[0] + txt[0];// + guid.toString() + guid.toString();
byte[] arrNounce = nonce.getBytes();
String nonceEncode = new String(Base64.encodeBytes(arrNounce, 0, arrNounce.length));
Date created = new Date();
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
//dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
//dateFormatter.applyPattern("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
String formattedCreated = dateFormatter.format(created);
System.out.println("FormattedCreated : " + formattedCreated);
String totalPassword = nonce + formattedCreated + planeTextPassword;
byte[] theTextToDigestAsBytes = totalPassword.getBytes();
MessageDigest md = MessageDigest.getInstance( "SHA-1" );
md.update( theTextToDigestAsBytes );
// md.update( int ) processes only the low order 8-bits. It actually expects an unsigned byte.
byte[] digest = md.digest();
System.out.print( "Digest: " );
for ( byte b : digest )
{
// print byte as 2 hex digits with lead 0. Separate pairs of digits with space
System.out.printf( "%02X ", b & 0xff );
}
System.out.println();
String encryptPasswordSHA1 = new String(Base64.encodeBytes(digest, 0, digest.length));
input = "<soapenv:Envelope xmlns:ser=\"http://www.acclaris.com/servicetypesma\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
"<soapenv:Header>"+
"<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"+
"<wsse:UsernameToken wsu:Id=\"UsernameToken-26294097\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"+
"<wsse:Username>objectsolwsuser</wsse:Username>"+
"<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">"+encryptPasswordSHA1+"</wsse:Password>"+
"<wsse:Nonce>"+nonceEncode+"</wsse:Nonce>"+
"<wsu:Created>"+formattedCreated+"</wsu:Created>"+
"</wsse:UsernameToken>"+
"</wsse:Security>"+
"</soapenv:Header>"+
"<soapenv:Body>"+
"<ser:GetLoginInfoMA>"+
"<ser:userName>objectone</ser:userName>"+
"<ser:param1/>"+
"<ser:param2/>"+
"<ser:param3/>"+
"<ser:param4/>"+
"</ser:GetLoginInfoMA>"+
"</soapenv:Body>"+
"</soapenv:Envelope>";
System.out.println("EncryptPasswordSHA1 : " + encryptPasswordSHA1);
System.out.println("Nounce : " + nonceEncode);
}catch(Exception ex){}
}
}
Thansk ROckOn