當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletUpgradeResponse.sendError方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse.sendError方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletUpgradeResponse.sendError方法的具體用法?Java ServletUpgradeResponse.sendError怎麽用?Java ServletUpgradeResponse.sendError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse的用法示例。


在下文中一共展示了ServletUpgradeResponse.sendError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ReaderHandler

import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
public ReaderHandler(WebSocketService service, HttpServletRequest request, ServletUpgradeResponse response) {
    super(service, request, response);
    this.subscription = "";
    this.conf = getReaderConfiguration();
    this.maxPendingMessages = (conf.getReceiverQueueSize() == 0) ? 1 : conf.getReceiverQueueSize();
    this.numMsgsDelivered = new LongAdder();
    this.numBytesDelivered = new LongAdder();

    if (!authResult) {
        return;
    }

    try {
        this.reader = service.getPulsarClient().createReader(topic, getMessageId(), conf);
        this.subscription = ((ReaderImpl)this.reader).getConsumer().getSubscription();
        if (!this.service.addReader(this)) {
            log.warn("[{}:{}] Failed to add reader handler for topic {}", request.getRemoteAddr(),
                    request.getRemotePort(), topic);
        }
    } catch (Exception e) {
        log.warn("[{}:{}] Failed in creating reader {} on topic {}", request.getRemoteAddr(),
                request.getRemotePort(), subscription, topic, e);
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create reader");
        } catch (IOException e1) {
            log.warn("[{}:{}] Failed to send error: {}", request.getRemoteAddr(), request.getRemotePort(),
                    e1.getMessage(), e1);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:31,代碼來源:ReaderHandler.java

示例2: ProducerHandler

import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
public ProducerHandler(WebSocketService service, HttpServletRequest request, ServletUpgradeResponse response) {
    super(service, request, response);
    this.numMsgsSent = new LongAdder();
    this.numBytesSent = new LongAdder();
    this.numMsgsFailed = new LongAdder();
    this.publishLatencyStatsUSec = new StatsBuckets(ENTRY_LATENCY_BUCKETS_USEC);

    if (!authResult) {
        return;
    }

    try {
        ProducerConfiguration conf = getProducerConfiguration();
        this.producer = service.getPulsarClient().createProducer(topic, conf);
        if (!this.service.addProducer(this)) {
            log.warn("[{}:{}] Failed to add producer handler for topic {}", request.getRemoteAddr(),
                    request.getRemotePort(), topic);
        }
    } catch (Exception e) {
        log.warn("[{}:{}] Failed in creating producer on topic {}", request.getRemoteAddr(),
                request.getRemotePort(), topic, e);
        boolean configError = e instanceof IllegalArgumentException;
        int errorCode = configError ? HttpServletResponse.SC_BAD_REQUEST
                : HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        String errorMsg = configError ? "Invalid query-param " + e.getMessage() : "Failed to create producer";
        try {
            response.sendError(errorCode, errorMsg);
        } catch (IOException e1) {
            log.warn("[{}:{}] Failed to send error: {}", request.getRemoteAddr(), request.getRemotePort(),
                    e1.getMessage(), e1);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:34,代碼來源:ProducerHandler.java

示例3: ConsumerHandler

import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
public ConsumerHandler(WebSocketService service, HttpServletRequest request, ServletUpgradeResponse response) {
    super(service, request, response);
    this.subscription = extractSubscription(request);
    this.conf = getConsumerConfiguration();
    this.maxPendingMessages = (conf.getReceiverQueueSize() == 0) ? 1 : conf.getReceiverQueueSize();
    this.numMsgsDelivered = new LongAdder();
    this.numBytesDelivered = new LongAdder();
    this.numMsgsAcked = new LongAdder();

    if (!authResult) {
        return;
    }

    try {
        this.consumer = service.getPulsarClient().subscribe(topic, subscription, conf);
        if (!this.service.addConsumer(this)) {
            log.warn("[{}:{}] Failed to add consumer handler for topic {}", request.getRemoteAddr(),
                    request.getRemotePort(), topic);
        }
    } catch (Exception e) {
        log.warn("[{}:{}] Failed in creating subscription {} on topic {}", request.getRemoteAddr(),
                request.getRemotePort(), subscription, topic, e);
        boolean configError = e instanceof IllegalArgumentException;
        int errorCode = configError ? HttpServletResponse.SC_BAD_REQUEST
                : HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        String errorMsg = configError ? "Invalid query-param " + e.getMessage() : "Failed to subscribe";
        try {
            response.sendError(errorCode, errorMsg);
        } catch (IOException e1) {
            log.warn("[{}:{}] Failed to send error: {}", request.getRemoteAddr(), request.getRemotePort(),
                    e1.getMessage(), e1);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:35,代碼來源:ConsumerHandler.java

示例4: badRequest

import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
private void badRequest(ServletUpgradeResponse resp, String message) {
    try {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
    } catch (IOException e) {
        log.info("Error sending error message on upgrade: ", e);
    }
}
 
開發者ID:trvedata,項目名稱:trvedb,代碼行數:8,代碼來源:EventsServlet.java

示例5: createWebSocket

import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
@Override
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse res) {
  String requester = req.getRemoteAddress() + ":" + req.getRemotePort();
  if (isShuttingDown()) {
    LOG.debug("Shutting down, discarding incoming request from '{}'", requester);
    res.setStatusCode(HttpServletResponse.SC_GONE);
    return null;
  }

  try {
    if (validateRequest(req, res)) {
      LOG.debug("Request accepted from '{}'", requester);
      return new WebSocketReceiverSocket(
          requester,
          receiver,
          errorQueue,
          requestMeter,
          invalidRequestMeter,
          errorRequestMeter,
          requestTimer
      );
    }
  } catch (Exception ex) {
    errorQueue.offer(ex);
    errorRequestMeter.mark();
    LOG.warn("Error while processing request payload from '{}': {}", requester, ex.toString(), ex);
    try {
      res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.toString());
    } catch (IOException e) {
      LOG.warn("Error while sending WebSocket error message: {}", ex.toString(), ex);
    }
  }
  invalidRequestMeter.mark();
  return null;
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:36,代碼來源:WebSocketReceiverServlet.java

示例6: validateAppId

import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; //導入方法依賴的package包/類
private boolean validateAppId(ServletUpgradeRequest req, ServletUpgradeResponse res) throws ServletException, IOException {
  boolean valid = false;
  String ourAppId = null;
  try {
    ourAppId = getReceiver().getAppId().get();
  } catch (StageException e) {
    throw new IOException("Cant resolve credential value", e);
  }

  String requester = req.getRemoteAddress() + ":" + req.getRemotePort();
  String reqAppId = req.getHeader(HttpConstants.X_SDC_APPLICATION_ID_HEADER);

  if (reqAppId == null && receiver.isAppIdViaQueryParamAllowed()) {
    Map<String,List<String>> parameterMap = req.getParameterMap();
    if (parameterMap != null && parameterMap.containsKey(HttpConstants.SDC_APPLICATION_ID_QUERY_PARAM)) {
      List<String> values = parameterMap.get(HttpConstants.SDC_APPLICATION_ID_QUERY_PARAM);
      if (values != null && values.size() > 0) {
        reqAppId = values.get(0);
      }
    }
  }

  if (reqAppId == null) {
    // Since it is not possible to pass headers in some of the WebSockets client (example: browser WebSocket API)
    // http://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api
    // check sub-protocol header for APP ID
    List<String> subProtocols = req.getSubProtocols();
    if (subProtocols != null && subProtocols.contains(ourAppId)) {
      reqAppId = ourAppId;
      res.setAcceptedSubProtocol(reqAppId);
    }
  }

  if (reqAppId == null) {
    LOG.warn("Request from '{}' missing appId, rejected", requester);
    res.sendError(HttpServletResponse.SC_FORBIDDEN, "Missing 'appId'");
  } if (reqAppId != null && !ourAppId.equals(reqAppId)) {
    LOG.warn("Request from '{}' invalid appId '{}', rejected", requester, reqAppId);
    res.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid 'appId'");
  } else {
    valid = true;
  }
  return valid;
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:45,代碼來源:WebSocketReceiverServlet.java


注:本文中的org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse.sendError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。