title: Issues Connecting to NetSuite Via TBA
body: <p>We were in progress of converting our SSO integration to TBA (vs a username and password).  Since the recent 2016.2 upgrade the java code has completely failed to work (note, this did work before the upgrade).  The current issue is that we receive either a 403 or a bad timestamp error.  Working with NetSutie, I'm not seeing any correlation to when these change.</p>
  
  <p>I'm far from a Java expert, so I'm hoping someone here can assist and tell me what is wrong with this code (I was able to get it working using the NetSuite PHP toolkit, though).</p>
  
  <p>Below is the basic code that I'm trying (most was received from our Java developer, whom I'm trying to fix this for), slightly tweaked by myself using ideas from NetSuite.</p>
  
  <pre><code>public class Main{
  public static void main(String[]args){
      String compID="compID";
      String consumerKey="consumerKey";
      String consumerSecret="consumerSecret";
      String tokenId="tokenId";
      String tokenSecret="tokenSecret";
      String restletURL="https://rest.sandbox.netsuite.com/app/site/hosting/restlet.nl?script=123&amp;deploy=2";
  
      Token token=new Token(tokenId,tokenSecret);
      String nonce=RandomStringUtils.randomNumeric(9);
      long ms=new java.util.Date().getTime();
      ms=(long)Math.floor(ms/1000);
      String time=ms+"";
  
      String baseString=compID+"&amp;"+consumerKey+"&amp;"+tokenId+"&amp;"+nonce+"&amp;"+time;
      String key=consumerSecret+"&amp;"+tokenSecret;
      byte[] bytes=key.getBytes();
      SecretKeySpec secretkey=new SecretKeySpec(bytes,"HmacSHA1");
      Mac keymac=null;
      try{
          keymac=Mac.getInstance("HmacSHA1");
          keymac.init(secretkey);
      }catch(NoSuchAlgorithmException e){
          e.printStackTrace();
      }catch(InvalidKeyException e){
          e.printStackTrace();
      }
      byte[] hash=keymac.doFinal(baseString.getBytes());
      String result=new String(Base64.encodeBase64(hash,false));
      String oauth_timestamp = Instant.now().toEpochMilli()+"";
  
      String headerAuthorization="OAuth realm=\""+compID+"\", oauth_consumer_key=\""+consumerKey+"\", oauth_token=\""+token+"\", oauth_nonce=\""+nonce+"\", oauth_timestamp=\""+oauth_timestamp+"\", oauth_signature_method=\"HMAC-SHA1\", oauth_version=\"1.0\", oauth_signature=\""+result+"\"";
  
      System.out.println(headerAuthorization);
  
      HttpClient httpclient=HttpClientBuilder.create().build();
  
      HttpGet request=new HttpGet(restletURL);
      request.setHeader(HttpHeaders.AUTHORIZATION,headerAuthorization);
  
      String response="";
      try{
          //Handle the response from NetSuite
          ResponseHandler&lt;String&gt; responseHandler=new ResponseHandler&lt;String&gt;(){
              @Override
              public String handleResponse(final HttpResponse response)throws ClientProtocolException,IOException{
                  int status=response.getStatusLine().getStatusCode();
  
                  //If the call is successful
                  if(status&gt;=200 &amp;&amp; status&lt;300){
                      HttpEntity entity=response.getEntity();
                      return entity!=null?EntityUtils.toString(entity):null;
                  }else{
                      throw new ClientProtocolException("Unexpected response status: "+status);
                  }
              }
          };
          response=httpclient.execute(request,responseHandler);
          System.out.println(response);
      }catch(Exception e){
          e.printStackTrace();
      }
    }
  }
  </code></pre>