有什么方法可以将在 httpAdapter 中创建的会话转换为适配器中的 java 类?我正在使用 httpadapter 连接到https://jazz.net/,但我现在想使用一些 java 代码连接到适配器中的相同 url。所以我不知道如何访问已经创建的会话。
这是我的连接代码:
In javaScript,
function login(){
var lpath = getLoginPath();
var input = {
method : 'post',
returnedContentType : 'html',
path : lpath,
parameters : {
j_password : passwd,
j_username : username
}
};
var request = WL.Server.getClientRequest();
UserSession = request.getHeader("Cookie"); // here i am setting the value for a global variable UserSession.
return WL.Server.invokeHttp(input);
}
function getConnection(){
var instance = new com.worklight.customcode.PostRequest();
var rspath = getRootServicesPath();
var input = {
method : 'get',
returnedContentType : 'xml',
path : rspath
};
return {
result : instance.getXml(UserSession) // Here i am passing the value of session cookie into the java class
};}
在 Java 类中,
class PostRequest{
public String getXml(String cookieString){
String params = "?offlineData={'projectAreaItemId':'_iTuLUmxfEeKR3t32SVbLKQ','executables':[{'terItemId':'_TNoyQW6qEeKR3t32SVbLKQ','scriptItemId':'_DF89AW6qEeKR3t32SVbLKQ'}]}";
String url = "https://jazz.net/sandbox02-qm/secure/service/com.ibm.rqm.execution.common.service.IOfflineExecutionRestService"
+ params;
URLConnection connection = new URL(url).openConnection();
connection = new URL(url).openConnection();
connection.setRequestProperty("User-Agent", "yes");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setRequestProperty("Accept-Encoding", "gzip");
connection.setRequestProperty("Accept", "application/xml");
connection.setRequestProperty("Cookie", cookieString);
connection.setDoInput(true);
connection.setDoOutput(true);
((HttpURLConnection) connection).setRequestMethod("POST");
connection.setDoOutput(true);
String result = "";
InputStream resp = connection.getInputStream();
StringBuilder s = inputStreamToString(resp);
return s;
}
}