I have a question about authentication in the REST API of SalesForce. I have created an API that I can access using hurl.it in combination with RuneScope Token Generator. This works fine and I can access the code but when I try to do the same in a Java applcation, it doesn't work.I think it's because my redirect url is at fault but I don't know how to use it; it says https://localhost:8443/RestTest/oauth/_callback on the SalesForce REST authentication page but what am I looking at here? An app called RestTest, that is accepting calls on port 8443 and has a class called oath and a method called _callback? I'm lost here, please some help.
I fill in everything like I don int the RuneScope Token Generator but always get a 400 - bad request.
Any ideas?
here's my code
public String getAccessToken( ) throws IOException
{
try
{
URL url = new URL( "https://eu3.salesforce.com/services/oauth2/token" );
OutputStreamWriter out = null;
try
{
HttpURLConnection connection = ( HttpURLConnection )url.openConnection( );
connection.setUseCaches( false );
connection.setDoOutput( true );
connection.setDoInput( true );
connection.setRequestProperty("charset", "utf-8");
connection.addRequestProperty( "grant_type", "authorization_code" );
connection.addRequestProperty( "response_type", "code" );
connection.addRequestProperty( "Accept", "*/*" );
connection.addRequestProperty( "Accept-Encoding", "gzip, deflate, compress" );
connection.addRequestProperty( "clientId", client_id );
connection.addRequestProperty( "clientSecret", client_secret );
connection.addRequestProperty( "username", username );
connection.addRequestProperty( "password", password );
connection.setRequestMethod( "POST" );
connection.setConnectTimeout(1000 * 5);
connection.connect( );
//out = new OutputStreamWriter( connection.getOutputStream( ) );
System.out.print( connection.getResponseCode( ) + " - " );
System.out.println( connection.getResponseMessage( ) );
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder builder = new StringBuilder( );
String line = "";
while( ( line = in.readLine( ) ) != null )
{
builder.append( line + '\n' );
}
System.out.println( builder.toString( ) );
} catch ( IOException ioExc )
{
System.out.println( "IOException while opening connection" );
} finally
{
//out.close( );
}
} catch ( MalformedURLException exc )
{
System.out.println( "URL is malformed." );
}
return "";
}