Search in sources :

Example 6 with XMLWriter

use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.

the class SearchRendererAdaptor method simpleRenderErrorHit.

/**
 * Renders this hit as XML, disregarding the given template.
 * The main error will be rendered first, the all the following errors.
 */
public boolean simpleRenderErrorHit(Writer writer, com.yahoo.search.result.ErrorHit errorHit) throws IOException {
    XMLWriter xmlWriter = (writer instanceof XMLWriter) ? (XMLWriter) writer : new XMLWriter(writer, 10, -1);
    xmlWriter.openTag("errordetails");
    for (Iterator i = errorHit.errorIterator(); i.hasNext(); ) {
        ErrorMessage error = (ErrorMessage) i.next();
        rendererErrorHitMessageMessage(xmlWriter, errorHit, error);
    }
    xmlWriter.closeTag();
    return true;
}
Also used : Iterator(java.util.Iterator) ErrorMessage(com.yahoo.processing.request.ErrorMessage) XMLWriter(com.yahoo.text.XMLWriter)

Example 7 with XMLWriter

use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.

the class SyncDefaultRenderer method render.

/**
 * Renders this result
 */
public void render(Writer writer, Result result) throws IOException {
    XMLWriter xmlWriter = wrapWriter(writer);
    context.put("context", context);
    context.put("result", result);
    context.setBoldOpenTag(defaultTemplate.getBoldOpenTag());
    context.setBoldCloseTag(defaultTemplate.getBoldCloseTag());
    context.setSeparatorTag(defaultTemplate.getSeparatorTag());
    try {
        header(xmlWriter, result);
    } catch (Exception e) {
        handleException(e);
    }
    if (result.hits().getError() != null || result.hits().getQuery().errors().size() > 0) {
        error(xmlWriter, result);
    }
    if (result.getConcreteHitCount() == 0) {
        emptyResult(xmlWriter, result);
    }
    if (result.getContext(false) != null) {
        queryContext(xmlWriter, result.getContext(false), result.getQuery());
    }
    renderHitGroup(xmlWriter, result.hits(), result.hits().getQuery().getOffset() + 1);
    endResult(xmlWriter, result);
}
Also used : XMLWriter(com.yahoo.text.XMLWriter) IOException(java.io.IOException)

Example 8 with XMLWriter

use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.

the class SyncDefaultRenderer method queryContext.

public void queryContext(XMLWriter writer, QueryContext queryContext, Query owner) throws IOException {
    try {
        if (owner.getTraceLevel() != 0) {
            XMLWriter xmlWriter = XMLWriter.from(writer);
            xmlWriter.openTag("meta").attribute("type", QueryContext.ID);
            TraceNode traceRoot = owner.getModel().getExecution().trace().traceNode().root();
            traceRoot.accept(new RenderingVisitor(xmlWriter, owner.getStartTime()));
            xmlWriter.closeTag();
        }
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : TraceNode(com.yahoo.yolean.trace.TraceNode) XMLWriter(com.yahoo.text.XMLWriter) IOException(java.io.IOException)

Example 9 with XMLWriter

use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.

the class StatusResponse method render.

@Override
public void render(OutputStream stream) throws IOException {
    XMLWriter writer = new XMLWriter(new OutputStreamWriter(stream));
    writer.openTag("status");
    if (verbosity >= 2) {
        writer.attribute(new Utf8String("description"), "Metrics since start");
    }
    if (snapshotTime == 0) {
        MetricSnapshot snapshot = (new MetricSnapshot("Total metrics from start until current time", 0, manager.getActiveMetrics().getMetrics(), false));
        manager.getTotalMetricSnapshot().addToSnapshot(snapshot, (int) (System.currentTimeMillis() / 1000), false);
        snapshot.printXml(manager, "", verbosity, writer);
    } else {
        try {
            manager.getMetricSnapshotSet(snapshotTime).getSnapshot().printXml(manager, "", verbosity, writer);
        } catch (Exception e) {
            writer.openTag("error");
            writer.attribute(new Utf8String("details"), "No metric snapshot with period " + snapshotTime + " was found. Legal snapshot periods are: " + manager.getSnapshotPeriods());
            writer.closeTag();
        }
    }
    writer.closeTag();
    writer.flush();
}
Also used : Utf8String(com.yahoo.text.Utf8String) OutputStreamWriter(java.io.OutputStreamWriter) XMLWriter(com.yahoo.text.XMLWriter) MetricSnapshot(com.yahoo.metrics.MetricSnapshot) IOException(java.io.IOException)

Example 10 with XMLWriter

use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.

the class FeedResponse method render.

@Override
public void render(OutputStream outputStream) throws IOException {
    if (!errorMessages.isEmpty())
        setStatus(VespaHeaders.getStatus(false, errorMessages.get(0), errorMessages.iterator()));
    XMLWriter writer = new XMLWriter(new OutputStreamWriter(outputStream));
    writer.openTag("result");
    if (metrics != null) {
        metrics.printXml(writer, 0, 0);
    }
    if (traces.length() > 0) {
        writer.openTag("trace");
        writer.append(traces);
        writer.closeTag();
    }
    if (!errors.isEmpty()) {
        writer.openTag("errors");
        writer.attribute(new Utf8String("count"), errors.size());
        for (int i = 0; i < errors.size() && i < 10; ++i) {
            writer.openTag("error");
            writer.attribute(new Utf8String("message"), errors.get(i));
            writer.closeTag();
        }
        writer.closeTag();
    }
    writer.closeTag();
    writer.flush();
    outputStream.close();
}
Also used : Utf8String(com.yahoo.text.Utf8String) OutputStreamWriter(java.io.OutputStreamWriter) XMLWriter(com.yahoo.text.XMLWriter)

Aggregations

XMLWriter (com.yahoo.text.XMLWriter)14 IOException (java.io.IOException)4 StringWriter (java.io.StringWriter)4 TraceNode (com.yahoo.yolean.trace.TraceNode)3 OutputStreamWriter (java.io.OutputStreamWriter)3 ErrorMessage (com.yahoo.processing.request.ErrorMessage)2 Utf8String (com.yahoo.text.Utf8String)2 Iterator (java.util.Iterator)2 Test (org.junit.Test)2 LoadBalancer (com.yahoo.documentapi.messagebus.protocol.LoadBalancer)1 Mirror (com.yahoo.jrt.slobrok.api.Mirror)1 MetricSnapshot (com.yahoo.metrics.MetricSnapshot)1 DefaultRenderer (com.yahoo.search.rendering.DefaultRenderer)1 DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)1 ErrorHit (com.yahoo.search.result.ErrorHit)1 PrintWriter (java.io.PrintWriter)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1