BeanShell 脚本错误:bsh.ParseException:在第 126 行,第 23 列解析错误.遇到:, [英] BeanShell script error: bsh.ParseException: Parse error at line 126, column 23. Encountered: ,
问题描述
我有一个在 Eclipse 上运行良好的代码,但是当我在 Sailpoint 工具(它是一个 beanshell 环境)上运行它时出现以下错误:
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"/>
每次遇到Java集合初始化时都会发生错误,例如:
The Error occurs every time the it encounters Java Collection initialization, For eg:
- 映射<字符串,对象>requestContext = wsdlProvider.getRequestContext();
- 映射<字符串,对象>字典 = (Map
)javaScriptSerializer.readValue(input, new TypeReference
我是否需要根据 Beanshell 以其他语法声明变量?List
在 Beanshell 中工作正常.请告知或建议我如何初始化 Map
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?
代码是:
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;
}
推荐答案
去除 Java 的 菱形运算符的使用 <>
Beanshell 不支持
Remove the usage of Java's diamond operator <>
which isn't supported by Beanshell
例如创建没有泛型的地图:
For example create map without generics:
Map map = new HashMap();
或者你的情况
Map requestContext = wsdlProvider.getRequestContext();
这篇关于BeanShell 脚本错误:bsh.ParseException:在第 126 行,第 23 列解析错误.遇到:,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!