문제

I am trying to concatenate string in JMeter BeanShell PostProcessor but somehow its not working, it seems like the way java handles multiple line string doesn't work here:

String poXML="<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Header/><S:Body><ns7:NewPORequest " +    "xmlns:ns2=\"http://services.portal.com/pro/common\" xmlns:ns5=\"http://services.portal.com/pro/po\" + "xmlns:ns7=\"http://services.portal.com/proc/ws\">" +
"<ns7:tracingLevel>OFF</ns7:tracingLevel><ns7:userId>TestUtil</ns7:userId><ns7:applicationId>RF</ns7:applicationId>" +
"<ns7:userType>Buyer</ns7:userType><ns5:PurchaseOrder><ns5:poExternalId>XXX-930220</ns5:poExternalId>" +
"<ns5:repairOrderNumber>vars.get("OrderNumber")</ns5:repairOrderNumber>";

I can concatenate simple one line but when it comes to multiple line its not working.
Single line:

print("PO XML="+"<ns5:repairOrderNumber>"+vars.get("OrderNumber")+"</ns5:repairOrderNumber>");
도움이 되었습니까?

해결책

Nothing special but:

  1. missing closing quotes near ...xmlns:ns5=\"http://services.portal.com/pro/po\" + "xmlns... - should be ...xmlns:ns5=\"http://services.portal.com/pro/po\"" + "xmlns...;
  2. missing escape character in repairOrderNumber>vars.get("OrderNumber")</ns5: - use >vars.get(\"OrderNumber\")< if you want to have string itself in result (i.e. vars.get("OrderNumber")) or concatenate separately + vars.get("OrderNumber") + to resolve expression to variable's value (as in your second sample).

    String poXML="<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Header/><S:Body><ns7:NewPORequest"+" xmlns:ns2=\"http://services.portal.com/pro/common\""+" xmlns:ns5=\"http://services.portal.com/pro/po\""+" xmlns:ns7=\"http://services.portal.com/proc/ws\">"+"<ns7:tracingLevel>OFF</ns7:tracingLevel><ns7:userId>TestUtil</ns7:userId><ns7:applicationId>RF</ns7:applicationId>"+"<ns7:userType>Buyer</ns7:userType><ns5:PurchaseOrder><ns5:poExternalId>XXX-930220</ns5:poExternalId>"+"<ns5:repairOrderNumber>"+vars.get("OrderNumber")+"</ns5:repairOrderNumber>";
    

As well looks like usage of StringBuilder.append() is a bit better way.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top