org.basex.http.ws.WsResponse Maven / Gradle / Ivy
The newest version!
package org.basex.http.ws;
import static org.basex.http.web.WebText.*;
import java.io.*;
import java.nio.*;
import java.util.*;
import org.basex.http.*;
import org.basex.http.web.*;
import org.basex.io.out.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.ann.*;
import org.basex.query.expr.*;
import org.basex.query.iter.*;
import org.basex.query.value.item.*;
import org.eclipse.jetty.websocket.api.*;
/**
* Creates WebSocket responses.
*
* @author BaseX Team 2005-24, BSD License
* @author Johannes Finckh
*/
public final class WsResponse extends WebResponse {
/** WebSocket. */
private final WebSocket ws;
/** Function. */
private WsFunction func;
/**
* Constructor.
* @param ws WebSocket instance
*/
WsResponse(final WebSocket ws) {
super(ws.context);
this.ws = ws;
}
@Override
protected Expr[] init(final WebFunction function, final Object data)
throws QueryException {
qc = function.module.qc(ctx);
qc.jc().type(WEBSOCKET);
ctx.setExternal(ws);
ctx.setExternal(new RequestContext(ws.request));
func = new WsFunction(function.function, function.module, qc);
func.parseAnnotations(ctx);
return func.bind(data, ws.headers, qc);
}
@Override
public Response serialize(final boolean body) throws QueryException, IOException {
qc.register(ctx);
try {
final ArrayList