I am trying to getting access token from salesforce using below java(Version JDK 7u45) snippet but I am getting this message:
Internal server error (Error code : 500) and the Sales force Error ID as 1366385420-22703 (1478489697).
An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience.
But the same code I am Trying in Java 1.8 its working fine am getting proper response.
The Jars I am using is "httpclient-4.3.3.jar,httpcore-4.3.2.jar
".
import javax.net.ssl.SSLContext;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
import org.apache.http.message.BasicNameValuePair;
public class ChatterHelper
{
public static void main(String[] args) {
postOnChatterGroup();
}
public static void postOnChatterGroup()
{
HttpHost proxy;
DefaultProxyRoutePlanner routePlanner;
RequestConfig requestConfig;
CloseableHttpClient httpClient = null;
InputStream is;
try
{
String clientId ="3MVG9**********************************************";
String clientSecret ="*****************";
String environment = "https://*****.salesforce.com";
String authURL = "/services/oauth2/token";
String userName = "**********************************";
String pwd = "*******";
StringBuffer sbf = new StringBuffer();
String baseUrl = environment+authURL;
System.setProperty("https.protocols", "TLSv1.1,SSLv3");
proxy = new HttpHost("***.***.com", 80);
routePlanner = new DefaultProxyRoutePlanner(proxy);
requestConfig = RequestConfig.custom().setConnectTimeout(20000)
.setConnectionRequestTimeout(10000).setSocketTimeout(20000)
.build();
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(
requestConfig).setRoutePlanner(routePlanner).build();
HttpPost oauthPost = new HttpPost(baseUrl);
oauthPost.setConfig(requestConfig);
List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>();
// keep this as it is
parametersBody.add(new BasicNameValuePair("grant_type", "password"));
parametersBody.add(new BasicNameValuePair("username", userName));
parametersBody.add(new BasicNameValuePair("password", pwd));
parametersBody.add(new BasicNameValuePair("client_id", clientId));
parametersBody.add(new BasicNameValuePair("client_secret", clientSecret));
oauthPost.setEntity(new UrlEncodedFormEntity(parametersBody));
// Execute the request.
HttpResponse response = httpClient.execute(oauthPost);
HttpEntity entity = response.getEntity();
int code = response.getStatusLine().getStatusCode();
System.out.println( ", Result Code >> " + code);
if (entity != null)
{
BufferedReader rd = new BufferedReader(new InputStreamReader(
entity.getContent(), "UTF-8"));
String line = "";
while ((line = rd.readLine()) != null)
{
sbf.append(line);
System.out.println(line);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}