3
我構建了一個Java類並將其導出爲JAR。我已經成功地將它導入到JMeter($ JMETER_HOME/lib)中,並且我可以成功地將它導入到Beanshell採樣器和JSR233採樣器中。在JMeter BeanShell或JSR233中使用POJO
我都遵循類似Running Java class with JMeter (Bean Shell)幾個指示,但我仍然得到錯誤:
「找不到命令:MyItem(java.lang.String中,java.lang.String中)」試圖使用類的構造函數時。
「使用任何方法時嘗試解決方法:getDescription()未定義的變量...」。
class MyJavaItem{
//XML
String title;
String link;
String description;
String pubDate;
String guid;
String dcDate;
//JSON
int code;
String message;
String reference;
String documentId;
String documentType;
public MyJavaItem(String title, String description) {
this.title = title;
this.description = description;
//
JSONObject jsonObject = new JSONObject(description);
try {
message = jsonObject.getString("message");
} catch (JSONException e){
}
try {
code = jsonObject.getInt("code");
} catch (JSONException e){
}
try {
reference = jsonObject.getString("reference");
} catch (JSONException e){
}
try {
documentType = jsonObject.getString("documentType");
} catch (JSONException e){
}
try {
documentId = jsonObject.getString("documentId");
} catch (JSONException e){
}
}
public boolean containsReference(String ref){
return
StringUtils.containsIgnoreCase(message,ref) ||
StringUtils.containsIgnoreCase(documentId,ref) ||
StringUtils.containsIgnoreCase(reference,ref);
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPubDate() {
return pubDate;
}
public void setPubDate(String pubDate) {
this.pubDate = pubDate;
}
public String getGuid() {
return guid;
}
public void setGuid(String guid) {
this.guid = guid;
}
public String getDcDate() {
return dcDate;
}
public void setDcDate(String dcDate) {
this.dcDate = dcDate;
}
public String getDocumentId() {
return documentId;
}
public void setDocumentId(String documentId) {
this.documentId = documentId;
}
public String getDocumentType() {
return documentType;
}
public void setDocumentType(String documentType) {
this.documentType = documentType;
}
public static MyJavaItem findByNumAtCard(ArrayList<MyJavaItem> activeMQArray, String numAtCard) {
for (MyJavaItem item : activeMQArray){
if (item.containsReference(numAtCard)){
return item;
}
}
return null;
}
}
,這是我的BeanShell/JSR233採樣:
import MyJavaItem;
import ParseXML;
import java.util.List;
String staging = ParseXML.staging;
String returns = ParseXML.magentoReturnsResponses;
ArrayList items = ParseXML.parseXML(staging,returns);
log.info("" + bsh.shared.items.size());
for (Object item : items){
MyJavaItem item = items.get(i); // VALID
MyJavaItem myItem = (MyJavaItem) item; //VALID
MyJavaItem aaaa = MyJavaItem("title","description"); //INVALID
aaa.getDescription(); //INVALID
}