I have one module which consumes a webservice and fetches a response from it. The response which I am getting contains a value inside it on which I need to set it value. I am using XPath for that. Now when I am running this functionality on my local system I am getting the desired output, but when I am using that in my ear, it's not working.
The code in ear:
private static String stResponsePath="//Envelope//Body//AddNoteResponse//Response//";
private static String Fault_Path="//Envelope/Body/Fault/detail/CSIApplicationException/ServiceProviderEntity/";
/**
* Construct AddNoteResponse bean from
*
* #param addNote response SOAP XML
*/
public AddNoteResponse createAddNoteResponseFromSoapString(String soapString)throws EDDSystemException
{
try
{
Document soapDocument =AddNoteDomParserHelper.convertStringToDoc(soapString);
// EDDLog.outLog.info("soapDocument " + soapDocument.getFirstChild());
// EDDLog.outLog.info("soapDocument " + soapDocument.getLastChild());
EDDLog.outLog.info("soapString :" +soapString );
AddNoteResponse addNoteResponse= new AddNoteResponse();
addNoteResponse.setCode(AddNoteDomParserHelper.**getElementValue**(stResponsePath + "code", soapDocument));
addNoteResponse.setDescription(AddNoteDomParserHelper.**getElementValue**(stResponsePath + "description", soapDocument));
} .....
.....
}
public static String **getElementValue**(String elementName, Document doc) throws Exception
{
String value = "";
XPath xPath = XPathFactory.newInstance().newXPath();
if(xPath ==null)
{
EDDLog.outLog.info(" xpath is null");
}
EDDLog.outLog.info("doc " + doc.getFirstChild());
NodeList docNodes = (NodeList) xPath.evaluate(elementName,doc, XPathConstants.NODESET);
// NodeList docNodes = (NodeList) xPath.evaluate("/Envelope/Body/AddNoteResponse/Response/code",doc, XPathConstants.NODESET);
EDDLog.outLog.info("elementName :" +elementName );
//NodeList docNodes = doc.getElementsByTagNameNS("*", elementName);
if (docNodes == null || docNodes.getLength() == 0) {
docNodes = doc.getElementsByTagName(elementName);
EDDLog.outLog.info("docNodes.getLength() :"+docNodes.getLength());
}
Output of this is:
11 Jun 2013 13:47:40,644 INFO soapString :<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header> <MessageHeader xmlns:cng="http://csi.cingular.com/CSI/Nam
espaces/Types/Public/CingularDataModel.xsd" xmlns="http://csi.cingular.com/CSI/Namespaces/Types/Public/MessageHeader.xsd"><TrackingMessageHeader><cng:version>v68</cng:version><cng:originalVersion>v
68</cng:originalVersion><cng:messageId>46178</cng:messageId><cng:timeToLive>120000</cng:timeToLive><cng:conversationId>EDD~CNG-CSI~5bfa2f5f-103d-4056-b775-cb2028357a5c</cng:conversationId><cng:date
TimeStamp>2013-06-08T12:44:18.418Z</cng:dateTimeStamp><cng:uniqueTransactionId>ServiceGateway19121#q25csg1c1_4f771d65-41de-4c40-b4cc-0be179d3677c</cng:uniqueTransactionId></TrackingMessageHeader><S
ecurityMessageHeader><cng:userName>EDD</cng:userName><cng:userPassword>EDDtest</cng:userPassword></SecurityMessageHeader><SequenceMessageHeader><cng:sequenceNumber>1</cng:sequenceNumber><cng:totalInSequence>1</cng:totalInSequence></SequenceMessageHeader></MessageHeader></SOAP-ENV:Header> <SOAP-ENV:Body> <AddNoteResponse xmlns:cng="http://csi.cingular.com/CSI/Namespaces/Types/Public/CingularDataModel.xsd" xmlns="http://csi.cingular.com/CSI/Namespaces/Container/Public/AddNoteResponse.xsd"><Response><cng:code>0</cng:code><cng:description>Success</cng:description></Response></AddNoteResponse></SOAP-ENV:Body> </SOAP-ENV:Envelope>
11 Jun 2013 13:47:42,028 INFO doc [SOAP-ENV:Envelope: null]
11 Jun 2013 13:47:44,236 INFO elementName ://Envelope//Body//AddNoteResponse//Response//code
11 Jun 2013 13:47:44,236 INFO docNodes.getLength() :0
11 Jun 2013 13:47:44,243 INFO doc [SOAP-ENV:Envelope: null]
11 Jun 2013 13:47:44,254 INFO elementName ://Envelope//Body//AddNoteResponse//Response//description
11 Jun 2013 13:47:44,254 INFO docNodes.getLength() :0
But when I am trying the same code on my local system it is working fine:
Entering .convertStringToDoc()...
Exiting .convertStringToDoc()...
soapDocument [SOAP-ENV:Envelope: null]
9
xpath is not null
elementName :/Envelope/Body/AddNoteResponse/Response/code
docNodes length:1
value :0
docNodes length2:1
addNoteResponse.getCode
xpath is not null
elementName :/Envelope/Body/AddNoteResponse/Response/description
docNodes length:1
value :Success
docNodes length2:1
This is the response on which I am working with:
<SOAP-ENV:Envelope >
<SOAP-ENV:Header>
<MessageHeader >
<TrackingMessageHeader>
<cng:version>v68</cng:version>
<cng:originalVersion>v68</cng:originalVersion>
<cng:messageId>45266</cng:messageId>
<cng:timeToLive>120000</cng:timeToLive>
<cng:conversationId>xxx</cng:conversationId>
<cng:dateTimeStamp>2013-06-05T10:01:41.09Z</cng:dateTimeStamp>
<cng:uniqueTransactionId>xasas</cng:uniqueTransactionId>
</TrackingMessageHeader>
<SecurityMessageHeader>
<cng:userName>ass</cng:userName>
<cng:userPassword>asas</cng:userPassword>
</SecurityMessageHeader>
<SequenceMessageHeader>
<cng:sequenceNumber>1</cng:sequenceNumber>
<cng:totalInSequence>1</cng:totalInSequence>
</SequenceMessageHeader>
</MessageHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<AddNoteResponse >
<Response>
<cng:code>0</cng:code>
<cng:description>Success</cng:description>
</Response>
</AddNoteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Value I am interested in is:
<cng:code>0</cng:code>
<cng:description>Success</cng:description>
Related
I tried to compress Inputmask.js file. Here is my code to work
public class JSFileMinifyTest {
public static void main(String[] args) throws Exception {
String sourceFileName = "D:\\temp\\jquery.inputmask.bundle.js";
String outputFilename = "D:\\temp\\combined.min.js";
com.google.javascript.jscomp.Compiler.setLoggingLevel(Level.INFO);
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
CompilerOptions options = new CompilerOptions();
CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(options);
options.setAggressiveVarCheck(CheckLevel.OFF);
options.setRuntimeTypeCheck(false);
options.setCheckRequires(CheckLevel.OFF);
options.setCheckProvides(CheckLevel.OFF);
options.setReserveRawExports(false);
WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
// To get the complete set of externs, the logic in
// CompilerRunner.getDefaultExterns() should be used here.
SourceFile extern = SourceFile.fromCode("externs.js", "function alert(x) {}");
SourceFile jsFile = SourceFile.fromFile(sourceFileName);
compiler.compile(extern, jsFile, options);
for (JSError message : compiler.getWarnings()) {
System.err.println("Warning message: " + message.toString());
}
for (JSError message : compiler.getErrors()) {
System.err.println("Error message: " + message.toString());
}
FileWriter outputFile = new FileWriter(outputFilename);
outputFile.write(compiler.toSource());
outputFile.close();
}
}
But error occured while compressing this js file.
Apr 09, 2018 11:29:18 AM com.google.javascript.jscomp.parsing.ParserRunner parse
INFO: Error parsing D:\temp\jquery.inputmask.bundle.js: Compilation produced 3 syntax errors. (D:\temp\jquery.inputmask.bundle.js#1)
Apr 09, 2018 11:29:18 AM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: D:\temp\jquery.inputmask.bundle.js:1002: ERROR - Parse error. identifier is a reserved word
static || null !== test.fn && void 0 !== testPos.input ? static && null !== test.fn && void 0 !== testPos.input && (static = !1,
^
Apr 09, 2018 11:29:18 AM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: D:\temp\jquery.inputmask.bundle.js:1003: ERROR - Parse error. syntax error
maskTemplate += "</span>") : (static = !0, maskTemplate += "<span class='im-static''>");
^
Apr 09, 2018 11:29:18 AM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: D:\temp\jquery.inputmask.bundle.js:1010: ERROR - Parse error. missing variable name
var maskTemplate = "", static = !1;
^
Apr 09, 2018 11:29:18 AM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 3 error(s), 0 warning(s)
Error message: JSC_PARSE_ERROR. Parse error. identifier is a reserved word at D:\temp\jquery.inputmask.bundle.js line 1002 : 16
Error message: JSC_PARSE_ERROR. Parse error. syntax error at D:\temp\jquery.inputmask.bundle.js line 1003 : 29
Error message: JSC_PARSE_ERROR. Parse error. missing variable name at D:\temp\jquery.inputmask.bundle.js line 1010 : 39
Has there anyways to skip syntax validations or ignore errors and continue to compress ?
The compiler by default, parses code as 'use strict'. 'static' is a reserved word in strict mode. You can either change the language mode or simply renamed the variable from 'strict' to something else.
The strict mode reserve words are documented here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Paving_the_way_for_future_ECMAScript_versions
Hello I have below SOAP reponse.
`
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWeatherResponse xmlns="http://www.webserviceX.NET">
<GetWeatherResult><![CDATA[<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
<Location>Cape Town, Cape Town International Airport, South Africa (FACT) 33-59S 018-36E 0M</Location>
<Time>Jun 04, 2016 - 05:00 AM EDT / 2016.06.04 0900 UTC</Time>
<Wind> from the SE (130 degrees) at 21 MPH (18 KT):0</Wind>
<Visibility> greater than 7 mile(s):0</Visibility>
<SkyConditions> mostly clear</SkyConditions>
<Temperature> 60 F (16 C)</Temperature>
<DewPoint> 44 F (7 C)</DewPoint>
<RelativeHumidity> 55%</RelativeHumidity>
<Pressure> 30.39 in. Hg (1029 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather>]]></GetWeatherResult>
</GetWeatherResponse>
</soap:Body>
</soap:Envelope>"`
for the following request: http://www.webservicex.net/globalweather.asmx.
I want to read XML Data in above response using script. but it is giving null.
I have tried script as below
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)
holder.namespaces["ns"] = "http://www.webserviceX.NET/" def
weatherinfo= holder.getNodeValue("//ns:GetWeatherResult/text()")
log.info weatherinfo
bit Instead of getting above reponse I am getting NULL. I have read the SOAPUI documentation on CDATA but its not working.
I got answer. It was just one extra slash in namespace that was giving me null.
Both the below scripts are working now.
> def respXmlHolder = new
> com.eviware.soapui.support.XmlHolder(messageExchange.getResponseContentAsXml())
> respXmlHolder.namespaces["ns1"] ="http://www.webserviceX.NET" def
> CDATAXml= respXmlHolder.getNodeValue("//ns1:GetWeatherResult/text()")
> log.info CDATAXml
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)
holder.namespaces["ns"] = "http://www.webserviceX.NET"
def weatherinfo= holder.getNodeValue("//ns:GetWeatherResult/text()")
log.info weatherinfo
I am not able to change the quantity of commerceItem using handleSetOrderByCommerceId.PFB.
I am using Art Technology Group web commerce platform.
Here is my code snippet:
for (CommerceItem cI : commerceItems) {
if (isLoggingDebug()) {
logDebug("inside handleRemoveItemFromOrder : commerceItems iteration : "+cI.getId() +" : "+ cI.getCatalogRefId());
}
request.setParameter(cI.getId(), cI.getQuantity());
if(cI.getCatalogRefId().equals(dealTobeDeleted)){
long quantity = cI.getQuantity();
//String currentSku = cI.getCatalogRefId();
if(quantity > 1){
// Set the new quantity for the commerce item being updated.
request.setParameter(cI.getCatalogRefId(), quantity-1);
setCheckForChangedQuantity(true);
result = super.handleSetOrderByCommerceId(request, response);
if (isLoggingDebug()) {
logDebug("inside handleRemoveItemFromOrder : after super call handleSetOrderByCommerceId : "+result);
}
}else{
String[] dealArray = new String[]{cI.getId()};
repoItemIdOfCommerceItemGettingRemoved = cI.getCatalogRefId();
setRemovalCommerceIds(dealArray);
if (isLoggingDebug()) {
logDebug("inside handleRemoveItemFromOrder : before super call handleRemoveItemFromOrder : "+repoItemIdOfCommerceItemGettingRemoved +" : "+getRemovalCommerceIds().length);
}
break;
}
}
}
The logs says :
**** debug Fri Sep 18 15:49:55 CAT 2015 1442584195886 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-37/atg/commerce/order/purchase/CartModifierFormHandler no form errors - staying on same page.
**** debug Fri Sep 18 15:49:55 CAT 2015 1442584195886 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-37/atg/commerce/order/purchase/CartModifierFormHandler no form errors - staying on same page.
**** info Fri Sep 18 15:49:55 CAT 2015 1442584195889 /com/cellc/online/commerce/pricing/calculators/OrderMonthlyCostCalculator monthlyPrice::::::::::::::509.0
**** debug Fri Sep 18 15:49:55 CAT 2015 1442584195889 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-37/atg/commerce/order/purchase/CartModifierFormHandler runProcess skipped because chain ID is null
**** debug Fri Sep 18 15:49:55 CAT 2015 1442584195889 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-37/atg/commerce/order/purchase/CartModifierFormHandler no form errors - staying on same page.
**** debug Fri Sep 18 15:49:55 CAT 2015 1442584195889 /atg/commerce/order/OrderManager Order: o8950004 Version in object: 183 Version in repItem: 183
**** debug Fri Sep 18 15:49:56 CAT 2015 1442584196206 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-37/atg/commerce/order/purchase/CartModifierFormHandler no form errors - staying on same page.
I am trying to parse the following xml, but getting repeated first sub tag [] on each iteration instead of getting the values of next sub tags [i.e ]. Kindly provide your help.
<error_code_rules enabled="true">
<errors>
<error>
<error_source>ldap</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-1</oms_error_code>
<priority>3</priority>
</error>
<error>
<error_source>nagravision</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-2</oms_error_code>
<priority>1</priority>
</error>
<error>
<error_source>hitexpress</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-3</oms_error_code>
<priority>2</priority>
</error>
<error>
<error_source>netinventory</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-4</oms_error_code>
<priority>2</priority>
</error>
<error>
<error_source>seachangeeventis</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-5</oms_error_code>
<priority>2</priority>
</error>
<error>
<error_source>embratel</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-6</oms_error_code>
<priority>2</priority>
</error>
<error>
<error_source>siemens</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-7</oms_error_code>
<priority>2</priority>
</error>
<error>
<error_source>netsiemens</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-8</oms_error_code>
<priority>2</priority>
</error>
<error>
<error_source>nokiaonends</error_source>
<error_code>ALL</error_code>
<oms_error_code>OMS-9</oms_error_code>
<priority>2</priority>
</error>
</errors>
</error_code_rules>
The code for parsing the xml doc is as follows
private void populateKsuRulesList() {
logger.trace(3, "Populating ksuRulesList");
logger.log("populter ksu rule list");
CachedXPathAPI xPathAPI = new CachedXPathAPI();
try {
NodeList components = xPathAPI.eval(doc, KSU_RULES_COMPONENT_PATH)
.nodelist();
logger.log("components.getLength()" + components.getLength());
for (int i = 0; i < components.getLength(); i++) {
Node component = components.item(i);
// NodeIterator nodeItr = xPathAPI.selectNodeIterator(component,
// KSU_RULES_COMPONENT_CATEGORY_PATH);
String componentCategory = xPathAPI.eval(components.item(i),
KSU_RULES_COMPONENT_CATEGORY_PATH).toString();
String componentType = xPathAPI.eval(component,
KSU_RULES_COMPONENT_TYPE_PATH).toString();
String mandatory = xPathAPI.eval(component,
KSU_RULES_MANDATORY_PATH).toString();
logger.log("componentCategory" + componentCategory);
logger.log("componentType" + componentType);
logger.log("mandatory" + mandatory);
String ruleParms[] = { componentCategory, componentType,
mandatory };
ksuRulesList.add(ruleParms);
}
} catch (TransformerException te) {
logger.log("Exception: ", te);
}
}
Try this one .
NodeList components = xPathAPI.eval(doc, "//errors/error").nodelist();
System.out.println("components.getLength()" + components.getLength());
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
for (int i = 0; i < components.getLength(); i++) {
Node component = components.item(i);
Element product = (Element) component;
NodeList nodes = (NodeList) xpath.compile("error_source").evaluate(product, XPathConstants.NODESET);
System.out.println(nodes.item(0).getTextContent());
}
I want to read following XML file using DOM Parser.
<?xml version="1.0" encoding="UTF-8"?>
<CCL>
<COUNTRY>
<COUNTRYNAME>INDIA</COUNTRYNAME>
<CITY>
<CITYNAME>NOIDA</CITYNAME>
<LOCALITY>SEC 22^SEC 24^SEC 55</LOCALITY>
</CITY>
<CITY>
<CITYNAME>DELHI</CITYNAME>
<LOCALITY>MAYUR VIHAR^PATPARGANJ^CHANDNI CAHUK</LOCALITY>
</CITY>
</COUNTRY>
<COUNTRY>
<COUNTRYNAME>SINGAPORE</COUNTRYNAME>
<CITY>
<CITYNAME>TIONG BAHRU</CITYNAME>
<LOCALITY>BLK 150^BLK 154^BLK 129</LOCALITY>
</CITY>
<CITY>
<CITYNAME>TANJONG PAGAR</CITYNAME>
<LOCALITY>MAXWELL ROAD^CECILL STREET^AXA TOWER</LOCALITY>
</CITY>
</COUNTRY>
</CCL>
and my java code is
public void ReadXMlFile(File f) throws ParserConfigurationException, SAXException, IOException
{
log.info("Reading log file" + f.getName() + ", from: "+ f.getAbsolutePath());
File fXmlFile = f;
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
log.info("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("COUNTRY");
log.info("-----------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
log.info("COUNTRYNAME: " + getTagValue("COUNTRYNAME", eElement));
NodeList nodel= eElement.getChildNodes();
for(int tempcity=0; tempcity< nodel.getLength() ; tempcity++)
{
Node nNode_1 = nodel.item(tempcity);
if (nNode_1.getNodeType() == Node.ELEMENT_NODE) {
Element eElement_1 = (Element) nNode_1;
log.info("CITYNAME: " + getTagValue("CITYNAME", eElement));
log.info("LOCALITY: " + getTagValue("LOCALITY", eElement));
}
}
}
}
}
private static String getTagValue(String sTag, Element eElement) {
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
I m getting followin output
INFO [http-8080-1] (UtilityClass.java:41) - Root element :CCL
INFO [http-8080-1] (UtilityClass.java:43) - -----------------------
INFO [http-8080-1] (UtilityClass.java:52) - COUNTRYNAME: INDIA
INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: NOIDA
INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: SEC 22^SEC 24^SEC 55
INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: NOIDA
INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: SEC 22^SEC 24^SEC 55
INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: NOIDA
INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: SEC 22^SEC 24^SEC 55
INFO [http-8080-1] (UtilityClass.java:52) - COUNTRYNAME: SINGAPORE
INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: TIONG BAHRU
INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: BLK 150^BLK 154^BLK 129
INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: TIONG BAHRU
INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: BLK 150^BLK 154^BLK 129
INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: TIONG BAHRU
INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: BLK 150^BLK 154^BLK 129
I want to read all entries in CITY tag for every country.
**
I am able to read the country tag, but I am not sure how to read CITY,
CITYNAME for every entry of country. Please help me
**
Can any one help me to resolve this issue
It looks like you're just referencing the wrong Element from your CITYNAME & LOCALITY log messages..
Try changing from:
if (nNode_1.getNodeType() == Node.ELEMENT_NODE) {
Element eElement_1 = (Element) nNode_1;
log.info("CITYNAME: " + getTagValue("CITYNAME", eElement));
log.info("LOCALITY: " + getTagValue("LOCALITY", eElement));
}
To:
if (nNode_1.getNodeType() == Node.ELEMENT_NODE) {
Element eElement_1 = (Element) nNode_1;
log.info("CITYNAME: " + getTagValue("CITYNAME", eElement_1));
log.info("LOCALITY: " + getTagValue("LOCALITY", eElement_1));
}
I can't be sure because I can't see the definition of getTagValue(..), but it looks very likely
HTH