Thursday, March 31, 2011

Xcode version 4.0.1 and iOS sdk 4.3 is available.

I was continuing with Xcode v3.2.5 because  Xcode 4.0 was buggy..
Today I started using Xcode version 4.0.1 ..its very good and no issues..  :))


WARNING! Creating precompiled collator because collator is out of date. This is expensive!

This is a warning in a console when running an iPhone application.. :(

This warning is appearing immediately after showing a UIAlertView 

Wednesday, January 19, 2011

Java- Connect MS CRM Using CrmDiscoveryService



TypeValueDescription
AD0Specifies Active Directory authentication.
Passport1Specifies Windows Live ID authentication.
Spla2Specifies Internet-Facing Deployment authentication

1. Active Directory authentication.
Sample code
  try{

String username = "domain\\user";
String password = "password";
String authType = "AD";
String OrganizationName = "orgName";
String hostBame = "http://xxx.xxx.x.xxx";
String CrmDiscoveryURL = hostBame + "/MSCRMServices/2007/"+ authType + "/CrmDiscoveryService.asmx";


CrmDiscoveryURL = CrmDiscoveryURL.toLowerCase();

CrmDiscoveryServiceLocator discoveryServiceLoc = new CrmDiscoveryServiceLocator();
discoveryServiceLoc.setCrmDiscoveryServiceSoapEndpointAddress(CrmDiscoveryURL);
CrmDiscoveryService discoveryService = (CrmDiscoveryService) discoveryServiceLoc;
CrmDiscoveryServiceSoapStub discoveryServiceSoap = (CrmDiscoveryServiceSoapStub) discoveryService.getCrmDiscoveryServiceSoap();


discoveryServiceSoap.setUsername(username);
discoveryServiceSoap.setPassword(password);

RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
orgRequest.setUserId(username);
orgRequest.setPassword(password);
RetrieveOrganizationsResponse orgResp = (RetrieveOrganizationsResponse) discoveryServiceSoap.execute(orgRequest);

OrganizationDetail orgInfo = null;
com.microsoft.schemas.crm._2007.CrmDiscoveryService.ArrayOfOrganizationDetail arrayOfDetail=  orgResp.getOrganizationDetails();
OrganizationDetail[] orgdetails = arrayOfDetail.getOrganizationDetail();


for (int i = 0; i < orgdetails.length; i++) {


System.out.println("orgdetails[i].getOrganizationName() = "+ orgdetails[i].getOrganizationName());
if (orgdetails[i].getOrganizationName().equalsIgnoreCase(OrganizationName)) {

orgInfo = orgdetails[i];
break;
}
}

int AD = 0;
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.setAuthenticationType(AD);
token.setOrganizationName(OrganizationName);


String CrmServiceUrl = orgInfo.getCrmServiceUrl();




CrmServiceSoapStub adminBinding = (CrmServiceSoapStub) new CrmServiceLocator().getCrmServiceSoap(new URL(CrmServiceUrl));

adminBinding.setHeader("http://schemas.microsoft.com/crm/2007/WebServices","CrmAuthenticationToken", token);

adminBinding.setUsername(username);
adminBinding.setPassword(password);

WhoAmIRequest whoRequest = new WhoAmIRequest();
WhoAmIResponse whoResp = (WhoAmIResponse) adminBinding.execute(whoRequest);

String UserId = whoResp.getUserId();

System.out.println("userid = "+ UserId);

}catch(Exception e){
e.printStackTrace();
}

2. Passport Authentication 
Sample code  

String authType = "Passport";
CrmDiscoveryServiceLocator discoveryServiceLoc = new CrmDiscoveryServiceLocator();
discoveryServiceLoc.setCrmDiscoveryServiceSoapEndpointAddress("http://" + hostName + "/MSCRMServices/2007/" + authType + "/CrmDiscoveryService.asmx");

CrmDiscoveryService discoveryService = (CrmDiscoveryService) discoveryServiceLoc;
CrmDiscoveryServiceSoapStub discoveryServiceSoap = (CrmDiscoveryServiceSoapStub) discoveryService.getCrmDiscoveryServiceSoap();

// Retrieve Policy Request
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse) discoveryServiceSoap.execute(policyRequest);

String passportTicket = getPassportTicket(policyResponse.getPolicy(),userName, password);

RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
crmTicketRequest.setOrganizationName(organization);
crmTicketRequest.setPassportTicket(passportTicket);
crmTicketResponse = (RetrieveCrmTicketResponse) discoveryServiceSoap.execute(crmTicketRequest);

if (crmTicketResponse != null) {

        CrmAuthenticationToken token = new CrmAuthenticationToken();

        int PASSPORT = 1;
        token.setAuthenticationType(PASSPORT);
token.setCallerId("00000000-0000-0000-0000-000000000000");
token.setOrganizationName(crmTicketResponse.getOrganizationDetail().getOrganizationName());
token.setCrmTicket(crmTicketResponse.getCrmTicket());
String crmServiceUrl = crmTicketResponse.getOrganizationDetail().getCrmServiceUrl();// we can store it in db w.r.t user,pass,org  and  retrieve
CrmServiceSoapStub crmServiceSoapStub = (CrmServiceSoapStub) new CrmServiceLocator().getCrmServiceSoap(new URL(crmServiceUrl));


crmServiceSoapStub.setHeader("http://schemas.microsoft.com/crm/2007/WebServices","CrmAuthenticationToken", token);

WhoAmIRequest whoRequest = new WhoAmIRequest();
whoRequest.setOptionalParameters(new OptionalParameter[] {});

WhoAmIResponse whoResp = (WhoAmIResponse) crmServiceSoapStub.execute(whoRequest);
System.out.println("----------getUserId()----------------->"+ whoResp.getOrganizationId());
}

private String getPassportTicket(String policy, String userName, String password) {

String ticket= null;


try{

String passportDomain = "crm.dynamics.com";//partner
String environment = "Production";
ticket = new MSLogonManager().logon(userName, password, passportDomain, policy, environment);
System.out.println("ticket = "+ticket);

}catch(Exception e){

e.printStackTrace();
}
return ticket;


3. IFD Authentication 

String hostBame = "https://xx.xxxx.xxx";
String OrganizationName = "orgName";
String username = "usernam";
String password = "password";

String CrmDiscoveryURL = hostBame+"/mscrmservices/2007/spla/crmdiscoveryservice.asmx";

CrmDiscoveryServiceLocator discoveryServiceLoc = new CrmDiscoveryServiceLocator();
discoveryServiceLoc.setCrmDiscoveryServiceSoapEndpointAddress(CrmDiscoveryURL);
CrmDiscoveryService discoveryService = (CrmDiscoveryService) discoveryServiceLoc;
CrmDiscoveryServiceSoapStub discoveryServiceSoap = (CrmDiscoveryServiceSoapStub) discoveryService.getCrmDiscoveryServiceSoap();

discoveryServiceSoap.setUsername(username);
discoveryServiceSoap.setPassword(password);

RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
orgRequest.setUserId(username);
orgRequest.setPassword(password);
RetrieveOrganizationsResponse orgResp = (RetrieveOrganizationsResponse) discoveryServiceSoap.execute(orgRequest);

OrganizationDetail orgInfo = null;
com.microsoft.schemas.crm._2007.CrmDiscoveryService.ArrayOfOrganizationDetail arrayOfDetail = orgResp.getOrganizationDetails();
OrganizationDetail[] orgdetails = arrayOfDetail.getOrganizationDetail();


for (int i = 0; i < orgdetails.length; i++) {

System.out.println(" getIFDBindingToCrm orgdetails[i].getOrganizationName()  "+ orgdetails[i].getOrganizationName());

if (orgdetails[i].getOrganizationName().equalsIgnoreCase(OrganizationName)) {

orgInfo = orgdetails[i];
break;
}
}

RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
crmTicketRequest.setOrganizationName(OrganizationName);//orgInfo.getOrganizationName());
crmTicketRequest.setUserId(username);
crmTicketRequest.setPassword(password);
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse) discoveryServiceSoap.execute(crmTicketRequest);

if (crmTicketResponse != null) {//

int IFD = 2;
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.setAuthenticationType(IFD);
token.setOrganizationName(orgInfo.getOrganizationName());
token.setCrmTicket(crmTicketResponse.getCrmTicket());

String CrmServiceUrl = orgInfo.getCrmServiceUrl();
System.out.println("CrmServiceUrl-" + CrmServiceUrl);

CrmServiceSoapStub adminBinding = (CrmServiceSoapStub) new CrmServiceLocator().getCrmServiceSoap(new URL(CrmServiceUrl));

adminBinding.setHeader("http://schemas.microsoft.com/crm/2007/WebServices","CrmAuthenticationToken", token);

adminBinding.setUsername(username);
adminBinding.setPassword(password);

WhoAmIRequest whoRequest = new WhoAmIRequest();
        WhoAmIResponse whoResp = (WhoAmIResponse) adminBinding.execute(whoRequest);
String UserId = whoResp.getUserId();

System.out.println("UserId="+UserId);



--------
Edited: Mar 20, 2013

In the above code, we have used the MSLogonManager class(its the bridge to dll file which is created using .net sdk) to get the ticket.

 
Another way to get the ticket is:

#2. we can  create a proxy service that handles auth and the connection and get the ticket using the CRM services in .NET and then you define your web service SOAP interface you want Java to use.  

#3. Use the following xml request.. this is get by http tracker


private String getPassportTicket(String policy, String userName, String password) {
String ticket = null;
        try{
            URL url = new URL( "https://login.live.com/RST2.srf" );
            HttpURLConnection rc = (HttpURLConnection)url.openConnection();

            rc.setRequestMethod("POST");
            rc.setDoOutput( true );
            rc.setDoInput( true );
            rc.setRequestProperty( "Content-Type", "text/xml; charset=utf-8" );

            String reqStr = new String("                                        "xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"> "+
                                        " "+
                                        "http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue"+
                                        "HTTPS://login.live.com:443//RST2.srf"+
                                        ""+
                                        ""+userName+""+
                                        ""+password+""+
                                        "
"+
                                        "
"+
                                        "
"+
                                        ""+
                                        ""+
                                        "http://schemas.xmlsoap.org/ws/2005/02/trust/Issue"+
                                        ""+

                                        ""+
                                        "passportDomain"+
                                        "
"+

                                        "
"+

                                        ""+
                                        "
"+
                                        "
"+
                                        "
");
            int len = reqStr.length();
            rc.setRequestProperty( "Content-Length", Integer.toString( len ) );

           
             rc.connect();   
            
             OutputStreamWriter out = new OutputStreamWriter( rc.getOutputStream() );
             out.write( reqStr, 0, len );
             out.flush();

            InputStreamReader read = new InputStreamReader( rc.getInputStream() );
            

            StringBuffer  sb = new StringBuffer();  
            int ch = read.read();
            while( ch != -1 ){
              sb.append((char)ch);
              ch = read.read();
             }
            String response = sb.toString();
            read.close();
            rc.disconnect();
           
           
            ticket = response.substring(response.indexOf("")+ "".length(),
                    response.indexOf("
"));
            System.out.println("passportTicket = "+result);

 
 return ticket;
}

 

Monday, January 17, 2011

Microsoft Dynamics CRM 2011 beta (5.0) Released

Version is 05.00.9585.101

Date Published :  9/17/2010

The Microsoft Dynamics CRM 2011 Beta is available for download and evaluation. Product keys are provided in the Readme file.

More Details  Go To Microsoft Dynamics CRM 2011 Beta

Wednesday, January 12, 2011

Blackberry failed to associate with the network

This error comes when try to set up WiFi on a blackberry bold device.

Solved by applying the following solution from blackberry forums
"the first thing to do is a battery pop reboot. With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes. See if things have returned to good operation."

Blackberry device failed to acquire an IP address

This error comes when try to set up WiFi on a blackberry bold device.

Solved by applying the following solution from blackberry forums
"the first thing to do is a battery pop reboot. With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes. See if things have returned to good operation."


Edit: Feb 9, 2011
Today I faced this same issue again and the above solution didn't work for me :(


After few tries, I tried with restarting the wifi modem and try to connect wifi from device.. Then its connected sucessfully..:))





How to restart blackberry bold



ALT + Right aA^ + DEL 



Tuesday, December 28, 2010

Application loader is currently unavailable. Directory Services reported the following error: Your Apple ID or password was entered incorrectly. (-20101)

We're having trouble connecting to the iTunes Store. Please try again later

When launch Application loader, its showing the above error message .

Edited:

Hi its fixed.

1. Quit the Application Loader
2. Launch the "Keychain Access"
3. Delete the itunes email entry from the Password Category.
4. Lauch the Application Loader -
       It just appeared with no error message and prompted the password on next screen.

How to set a tabbarcontroller as rootview controller of UISplitViewController

When I try to do this, 8 tabitems are displaying without "More" button. so its overlapping items title. And it will display More button if more than 8 tab items.
As it is using width 320, How to set only 5 tabs visible at a time.


I have posted this question in stackoverflaw.com http://stackoverflow.com/questions/4459634/how-to-set-a-tabbarcontroller-as-rootview-controller-of-uisplitviewcontroller

its still an open question. So I think its better to use tabbar instead of tabbarcontroller. But this will change my whole design. :(

Monday, December 27, 2010

How to change Tomcat default character encoding

We faced an issue last week on linux machine,

In a tomcat deployed server, The non-english characters getting from web services are not displaying correctly.

We write a main program in java and retrieved the data through web-service. its parsed well and correctly displayed the non-english character.

So the issue is with tomcat, after investigation we found this.


In the catalina.bat (catalina.sh) add the java args...

set JAVA_OPTS=-Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8

then all encodings seem to come across as UTF-8 by default.. 
This resolved the problem.

source: http://marc.info/?l=tomcat-user&m=108576957301771&w=3

----------------------
+20110113
Added some more info:

Configuring Tomcat's URI encoding

By default, Tomcat uses ISO-8859-1 character encoding when decoding URLs received from a browser. This can cause problems when Confluence's encoding is UTF-8, and you are using international characters in attachment or page names.
  1. Edit conf/server.xml and find the line where the Coyote HTTP Connector is defined. It will look something like this, possibly with more parameters:
    <Connector port="8080"/>
  2. Add a URIEncoding="UTF-8" property to the connector:
    <Connector port="8080" URIEncoding="UTF-8"/>
  3. Restart Tomcat
-------------------
Also check this

Friday, December 17, 2010

How to change MySql Data folder location - Windows machine

1. Stop/Exit the MySql service.
2.  Go to the Data folder location which we see while doing the installation. Usually it is
    C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data
3. delete all files which names begins like ib_log*
4. Go to the mysql installed location . The default location is C:\Program files\MySQL\MySQL Server 5.0
    open/edit the my.ini file
5. find the section
   #path to the database root
   and change the value of datadir
6. save the my.ini file
7. start the MySQL service
  

How to install MySql on a specified path/location on Windows machine

1. Run mysql-essential-5.1.51-win32.msi
2.  in the Setup type screen, select "Custom"
3. next screen, change the location to be installed.

On the next screen, we can see the Destination folder location is changed with what we given
But the Data folder location remains unchanged..

no worries, we can change the Data folder location after installation.

click install.

How to change the Data folder location

How to get motherboard and processor details from windows

#. Type "dxdiag" command in Run (Start -> Run), we can see all System informations like Motherboard Model, DirectX, Display,  and Sound, information

Monday, December 13, 2010

iPhone Core Data Encryption - encrypt your sqlite databse




in IOS4 Apple introduced a new feature NSFileProtectionComplete to encrypt the filesystem.

I found very useful article. 

Remember that we can apply this only with Device not with simulator.

And on device you should enable the passcode security under Settings -> General

If you have iTunes login, see the apple video about security
session 209 securing application data in category : Core OS 
https://developer.apple.com/videos/wwdc/2010/

-------------

We need to prompt a message to the user if file system is not protected, So
How to know the device is password protected ? or How to know the filesystem(database) is encrypted.?