use of javax.xml.xpath.XPathExpressionException in project cloudstack by apache.
the class PaloAltoResource method login.
private boolean login(String username, String password) throws ExecutionException {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "keygen");
params.put("user", username);
params.put("password", password);
String keygenBody;
try {
keygenBody = request(PaloAltoMethod.GET, params);
} catch (ExecutionException e) {
return false;
}
Document keygen_doc = getDocument(keygenBody);
XPath xpath = XPathFactory.newInstance().newXPath();
try {
XPathExpression expr = xpath.compile("/response[@status='success']/result/key/text()");
_key = (String) expr.evaluate(keygen_doc, XPathConstants.STRING);
} catch (XPathExpressionException e) {
throw new ExecutionException(e.getCause().getMessage());
}
if (_key != null) {
return true;
}
return false;
}
use of javax.xml.xpath.XPathExpressionException in project robovm by robovm.
the class XPathImpl method compile.
/**
* <p>Compile an XPath expression for later evaluation.</p>
*
* <p>If <code>expression</code> contains any {@link XPathFunction}s,
* they must be available via the {@link XPathFunctionResolver}.
* An {@link XPathExpressionException} will be thrown if the <code>XPathFunction</code>
* cannot be resovled with the <code>XPathFunctionResolver</code>.</p>
*
* <p>If <code>expression</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.</p>
*
* @param expression The XPath expression.
*
* @return Compiled XPath expression.
* @throws XPathExpressionException If <code>expression</code> cannot be compiled.
* @throws NullPointerException If <code>expression</code> is <code>null</code>.
*/
public XPathExpression compile(String expression) throws XPathExpressionException {
if (expression == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "XPath expression" });
throw new NullPointerException(fmsg);
}
try {
org.apache.xpath.XPath xpath = new XPath(expression, null, prefixResolver, org.apache.xpath.XPath.SELECT);
// Can have errorListener
XPathExpressionImpl ximpl = new XPathExpressionImpl(xpath, prefixResolver, functionResolver, variableResolver, featureSecureProcessing);
return ximpl;
} catch (javax.xml.transform.TransformerException te) {
throw new XPathExpressionException(te);
}
}
use of javax.xml.xpath.XPathExpressionException in project ddf by codice.
the class TestCatalog method testCswUpdateRemoveAttributesByCqlConstraint.
@Test
public void testCswUpdateRemoveAttributesByCqlConstraint() {
Response response = ingestCswRecord();
String id;
try {
id = getMetacardIdFromCswInsertResponse(response);
} catch (IOException | XPathExpressionException e) {
fail("Could not retrieve the ingested record's ID from the response.");
return;
}
String url = REST_PATH.getUrl() + id;
when().get(url).then().log().all().assertThat().body(hasXPath("//metacard/dateTime[@name='modified']"), hasXPath("//metacard/string[@name='title']"), hasXPath("//metacard/geometry[@name='location']"));
ValidatableResponse validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswUpdateRemoveAttributesByCqlConstraintRequest")).post(CSW_PATH.getUrl()).then();
validatableResponse.body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("1")));
when().get(url).then().log().all().assertThat().body(not(hasXPath("//metacard/string[@name='title']")), not(hasXPath("//metacard/geometry[@name='location']")), // Check that an attribute that was not updated was not changed.
hasXPath("//metacard/dateTime[@name='modified']"), hasXPath("//metacard/string[@name='topic.category']/value", is("Hydrography--Dictionaries")));
deleteMetacard(id);
}
use of javax.xml.xpath.XPathExpressionException in project ddf by codice.
the class TestCatalog method testCswGetRecordsWithHitsResultType.
@Test
public void testCswGetRecordsWithHitsResultType() {
Response response = ingestCswRecord();
String query = getCswQuery("AnyText", "*", "application/xml", "http://www.opengis.net/cat/csw/2.0.2");
String id;
try {
id = getMetacardIdFromCswInsertResponse(response);
} catch (IOException | XPathExpressionException e) {
fail("Could not retrieve the ingested record's ID from the response.");
return;
}
//test with resultType="results" first
ValidatableResponse validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
validatableResponse.body(hasXPath("/GetRecordsResponse/SearchResults/Record"));
//test with resultType="hits"
query = query.replace("results", "hits");
validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
//assert that no records have been returned
validatableResponse.body(not(hasXPath("//Record")));
//testing with resultType='validate' is not
//possible due to DDF-1537, this test will need
//to be updated to test this once it is fixed.
deleteMetacard(id);
}
use of javax.xml.xpath.XPathExpressionException in project ddf by codice.
the class TestCatalog method testCswUpdateByNewRecord.
@Test
public void testCswUpdateByNewRecord() {
Response response = ingestCswRecord();
String requestXml = getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswUpdateRecordRequest");
String id;
try {
id = getMetacardIdFromCswInsertResponse(response);
} catch (IOException | XPathExpressionException e) {
fail("Could not retrieve the ingested record's ID from the response.");
return;
}
requestXml = requestXml.replace("identifier placeholder", id);
ValidatableResponse validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(requestXml).post(CSW_PATH.getUrl()).then();
validatableResponse.body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("1")));
String url = REST_PATH.getUrl() + id;
when().get(url).then().log().all().assertThat().body(hasXPath("//metacard/dateTime[@name='modified']/value", startsWith("2015-08-10")), hasXPath("//metacard/string[@name='title']/value", is("Updated Title")), hasXPath("//metacard/string[@name='topic.category']/value", is("Updated Subject")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[1]", is("1.0 2.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[2]", is("3.0 2.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[3]", is("3.0 4.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[4]", is("1.0 4.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[5]", is("1.0 2.0")));
deleteMetacard(id);
}
Aggregations