use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class LinkHelperTest method setUp.
@Before
public void setUp() {
Current current = new Current();
current.setRoot(URI_ROOT);
current.setPrefix(BASE_PATH);
current.setPath("");
CurrentManager.put(current);
}
use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class AbstractBackendAsyncStatusResource method addLinks.
@Override
protected R addLinks(R model, Class<? extends BaseResource> suggestedParent, String... excludeSubCollectionMembers) {
Current current = CurrentManager.get();
String href = current.getRelativePath();
model.setHref(href);
return model;
}
use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class V3CapabilitiesServer method list.
@GET
public V3Capabilities list() {
// Calculate the prefix that should be added to the "href" attributes:
Current current = CurrentManager.get();
StringBuilder buffer = new StringBuilder();
if (current.getVersionSource() == VersionSource.URL) {
buffer.append("/v");
buffer.append(current.getVersion());
}
buffer.append(current.getPrefix());
String prefix = buffer.toString();
// Load the document into a DOM tree:
Document document;
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
try (InputStream in = this.getClass().getResourceAsStream("/v3/capabilities.xml")) {
document = parser.parse(in);
}
} catch (Exception exception) {
throw new WebApplicationException(exception, Response.Status.INTERNAL_SERVER_ERROR);
}
// Create an XPath engine, we will use it for several things later:
XPath xpath = XPathFactory.newInstance().newXPath();
try {
// Find the 3.6 capabilities:
Element versionElement36 = (Element) xpath.evaluate("/capabilities/version[@major='3' and @minor='6']", document, XPathConstants.NODE);
// Clone capabilities from 3.6 to 4.y:
Element versionElement4y = null;
for (int y = 0; y <= 2; y++) {
versionElement4y = cloneCapabilities(versionElement36, 4, y);
document.getDocumentElement().appendChild(versionElement4y);
}
// Set the "current" flag of the last version capabilities to "true":
Element currentElement = (Element) xpath.evaluate("current", versionElement4y, XPathConstants.NODE);
currentElement.setTextContent("true");
} catch (XPathExpressionException exception) {
throw new WebApplicationException(exception, Response.Status.INTERNAL_SERVER_ERROR);
}
// Modify all the "href" attributes to include the prefix:
try {
NodeList nodes = (NodeList) xpath.evaluate("//@href", document, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
String href = node.getNodeValue();
href = prefix + href;
node.setNodeValue(href);
}
} catch (XPathExpressionException exception) {
throw new WebApplicationException(exception, Response.Status.INTERNAL_SERVER_ERROR);
}
// Create the capabilities object from the DOM tree:
return JAXB.unmarshal(new DOMSource(document), V3Capabilities.class);
}
use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class AbstractBackendBaseTest method setUpBasicUriExpectations.
protected UriInfo setUpBasicUriExpectations(String path) {
UriInfo uriInfo = mock(UriInfo.class);
URI baseUri = URI.create(URI_BASE + '/');
when(uriInfo.getBaseUri()).thenReturn(baseUri);
when(uriInfo.getPath()).thenReturn(path);
Current current = CurrentManager.get();
current.setPath(path);
return uriInfo;
}
Aggregations