Search in sources :

Example 11 with Current

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);
}
Also used : Current(org.ovirt.engine.api.restapi.invocation.Current) Before(org.junit.Before)

Example 12 with 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;
}
Also used : Current(org.ovirt.engine.api.restapi.invocation.Current)

Example 13 with Current

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);
}
Also used : XPath(javax.xml.xpath.XPath) DOMSource(javax.xml.transform.dom.DOMSource) WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) XPathExpressionException(javax.xml.xpath.XPathExpressionException) WebApplicationException(javax.ws.rs.WebApplicationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Current(org.ovirt.engine.api.restapi.invocation.Current) GET(javax.ws.rs.GET)

Example 14 with Current

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;
}
Also used : URI(java.net.URI) Current(org.ovirt.engine.api.restapi.invocation.Current) UriInfo(javax.ws.rs.core.UriInfo)

Aggregations

Current (org.ovirt.engine.api.restapi.invocation.Current)14 Before (org.junit.Before)4 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DOMSource (javax.xml.transform.dom.DOMSource)2 XPath (javax.xml.xpath.XPath)2 MessageBundle (org.ovirt.engine.api.restapi.logging.MessageBundle)2 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 IOException (java.io.IOException)1 URI (java.net.URI)1 Locale (java.util.Locale)1 GET (javax.ws.rs.GET)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 PathSegment (javax.ws.rs.core.PathSegment)1 UriInfo (javax.ws.rs.core.UriInfo)1