arpit91
arpit91

Reputation: 1

BeanShell script error: bsh.ParseException: Parse error at line 126, column 23. Encountered: ,

I have a code which works fine on Eclipse but when I run it on the Sailpoint tool (which is a beanshell environment) gives following error:

Message key="sailpoint.tools.GeneralException: BeanShell script error: bsh.ParseException: Parse error at line 126, column 23.  Encountered: , BSF info: script at line: 0 column: columnNo" type="Error"/>

The Error occurs every time the it encounters Java Collection initialization, For eg:

  1. Map<String, Object> requestContext = wsdlProvider.getRequestContext();
  2. Map<String, Object> dictionary = (Map<String, Object>)javaScriptSerializer.readValue(input, new TypeReference<Map<String,Object>>(){})

Do I need to declare the variables in some other syntax according in Beanshell? The simple initialization like List<String> roleNameValues = new ArrayList<String>(); works fine in Beanshell. Please advise or suggest how do I initialize something like Map<String, Object> in Beanshell?

The code is :

public void configureServiceSession(BindingProvider wsdlProvider, String strServiceURL)
            throws MalformedURLException, IOException
    {
        // configure requestContext - WSDL URL and Session attribute
        Map<String, Object> requestContext = wsdlProvider.getRequestContext();

        requestContext.put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
                                            "http://" + server + ":" + port + strServiceURL );
        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
        
        // Handle OAUTH2 Client
        TSSWSAPIHandler tssWSAPIHandler = new TSSWSAPIHandler();
        tssWSAPIHandler.setOAuthBearerToken(getOAuthToken("http://" + server + ":" + port + strSpotfireServerBase));
    
        List<Handler> handlerChain = new ArrayList<Handler>();
        handlerChain.add(tssWSAPIHandler);
        Binding bindObj = wsdlProvider.getBinding();
        bindObj.setHandlerChain(handlerChain);
    }

public String getOAuthToken(String strServerURL)
    {
        // config register-api-client --name APIImpersonateClient -Sapi.soap.impersonate
        // possible Scopes from com.spotfire.server.security.oauth.OAuthScopes class
        // "api.soap.library-service", "api.soap.update-analysis-service", "api.soap.information-model-service"
        // "api.soap.license-service", "api.soap.user-directory-service", "api.soap.impersonate";
        /*
        C:\tibco\tss\7.13.0\tomcat\bin>config register-api-client -n TestAPIClient -Sapi.soap.library-service -Sapi.soap.user-directory-service
        
        C:\tibco\tss\7.13.0\tomcat\bin>config register-api-client -n TestAPIClient -Sapi.soap.library-service -Sapi.soap.user-directory-service
        Tool password:
        Successfully registered a new API client with the display name 'TestAPIClient':
        <CLIENT ID and CLIENT SECRET OUTPUT>
        To view the full client configuration, please use the 'show-oauth2-client' command.
        */

        // New with api.soap.impersonate
        String oAuthClientID = clientID;
        String oAuthClientSecret = clientSecret;
        String accessToken = null;

        String urlOAuth = strServerURL + "/oauth2/token";

        try
        {
            System.out.println("Retrieving OAuth Token from: " + urlOAuth);

            URL wrOAuth = new URL(urlOAuth);
            HttpURLConnection wrInitial = (HttpURLConnection)wrOAuth.openConnection();

            String oAuthClientInfo = URLEncoder.encode(oAuthClientID, "UTF-8") + ":" + URLEncoder.encode(oAuthClientSecret, "UTF-8");
            String base64OAuth = Base64.getEncoder().encodeToString(oAuthClientInfo.getBytes("UTF-8"));

            wrInitial.setRequestProperty ("Authorization", "Basic " + base64OAuth);
            wrInitial.setRequestMethod("POST");
            wrInitial.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
            
            String strScopeInfo = "grant_type=client_credentials&scope=" + URLEncoder.encode("api.soap.library-service api.soap.user-directory-service", "UTF-8");
            byte[] postBytes = strScopeInfo.getBytes("UTF-8"); 

            wrInitial.setRequestProperty("Content-Length", "" + postBytes.length);
            wrInitial.setUseCaches(false);
            wrInitial.setDoInput(true);
            wrInitial.setDoOutput(true);   
            wrInitial.getOutputStream().write(postBytes);

            // read response information from request
            InputStreamReader responseStream = new InputStreamReader(wrInitial.getInputStream(), "UTF-8");

            Scanner sc = new Scanner(responseStream).useDelimiter("\\A");
            String input = sc.hasNext() ? sc.next() : "";
            // parse out JSON return data
            ObjectMapper javaScriptSerializer = new ObjectMapper();

            Map<String, Object> dictionary = (Map<String, Object>)javaScriptSerializer.readValue(input, new TypeReference<Map<String,Object>>(){});
            for (Map.Entry<String, Object> current : dictionary.entrySet())
            {
                String key;
                if ((key = current.getKey()) != null)
                {
                    if (key.equalsIgnoreCase("access_token"))
                    {
                        accessToken = (String)current.getValue();
                        continue;
                    }
                    if (key.equalsIgnoreCase("token_type"))
                    {
                        continue;
                    }
                    if (key.equalsIgnoreCase("expires_in"))
                    {
                        continue;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            System.err.println("Exception calling OAuth Token URL, " + urlOAuth + ": " + ex.getMessage());
        }
        return accessToken;
    }
    
 public List<String> getInitialCookies(String strServerURL) 
            throws IOException, MalformedURLException
    {
        List<String> listStrings = new ArrayList<String>();
        String strURLCalled = strServerURL + "/manifest";
        
        try 
        {
            URL urlCalled = new URL(strURLCalled);

            HttpURLConnection wrInitial = (HttpURLConnection) urlCalled.openConnection();
            wrInitial.setRequestMethod("GET");

            Map<String,List<String>> reqProps = wrInitial.getHeaderFields();

            listStrings = reqProps.get("Set-Cookie");
        }
        catch (Exception ex)
        {
            System.out.println("Exception calling initial URL, " + strURLCalled + ": " + ex.getMessage());
            throw ex;
        }

        return listStrings;
    }  

Upvotes: 0

Views: 5563

Answers (2)

tinku_jai
tinku_jai

Reputation: 33

You could either not use diamond operator or you can use CDATA to in the SOURCE TAG of XML file and import it. This will convert the java-supported syntaxes to beanshell one's.

 <Source><![CDATA[
      //your code     
    List<String> roleNameValues = new ArrayList<String>(); 
  ]]></Source>

Upvotes: 0

Ori Marko
Ori Marko

Reputation: 58872

Remove the usage of Java's diamond operator <> which isn't supported by Beanshell

For example create map without generics:

 Map map = new HashMap();

Or in your case

Map requestContext = wsdlProvider.getRequestContext();

Upvotes: 2

Related Questions