Пример #1
0
    protected AhcWebSocketWrappedOutputStream(
        Message message,
        boolean possibleRetransmit,
        boolean isChunking,
        int chunkThreshold,
        String conduitName,
        URI url) {
      super(message, possibleRetransmit, isChunking, chunkThreshold, conduitName, url);

      entity = message.get(AhcWebSocketConduitRequest.class);
      // REVISIT how we prepare the request
      String requri = (String) message.getContextualProperty("org.apache.cxf.request.uri");
      if (requri != null) {
        // jaxrs speicfies a sub-path using prop org.apache.cxf.request.uri
        if (requri.startsWith("ws")) {
          entity.setPath(requri.substring(requri.indexOf('/', 3 + requri.indexOf(':'))));
        } else {
          entity.setPath(url.getPath() + requri);
        }
      } else {
        // jaxws
        entity.setPath(url.getPath());
      }
      entity.setId(UUID.randomUUID().toString());
      uncorrelatedRequests.put(entity.getId(), new RequestResponse(entity));
    }
Пример #2
0
 @Override
 protected void handleNoOutput() throws IOException {
   connect();
   Map<String, String> headers = new HashMap<String, String>();
   headers.put(requestIdKey, entity.getId());
   websocket.sendMessage(
       WebSocketUtils.buildRequest(entity.getMethod(), entity.getPath(), headers, null, 0, 0));
 }
Пример #3
0
 @Override
 protected OutputStream createOutputStream(
     Message message, boolean needToCacheRequest, boolean isChunking, int chunkThreshold)
     throws IOException {
   AhcWebSocketConduitRequest entity = message.get(AhcWebSocketConduitRequest.class);
   AhcWebSocketWrappedOutputStream out =
       new AhcWebSocketWrappedOutputStream(
           message,
           needToCacheRequest,
           isChunking,
           chunkThreshold,
           getConduitName(),
           entity.getUri());
   return out;
 }
Пример #4
0
    protected AhcWebSocketWrappedOutputStream(
        Message message,
        boolean possibleRetransmit,
        boolean isChunking,
        int chunkThreshold,
        String conduitName,
        URI url) {
      super(message, possibleRetransmit, isChunking, chunkThreshold, conduitName, url);

      entity = message.get(AhcWebSocketConduitRequest.class);
      // REVISIT how we prepare the request
      entity.setPath(
          url.getPath() + (String) message.getContextualProperty("org.apache.cxf.request.uri"));
      entity.setId(UUID.randomUUID().toString());
      uncorrelatedRequests.put(entity.getId(), new RequestResponse(entity));
    }
Пример #5
0
 @Override
 protected void setProtocolHeaders() throws IOException {
   Headers h = new Headers(outMessage);
   entity.setContentType(h.determineContentType());
   // REVISIT may provide an option to add other headers
   //          boolean addHeaders =
   // MessageUtils.isTrue(outMessage.getContextualProperty(Headers.ADD_HEADERS_PROPERTY));
 }
Пример #6
0
  @Override
  protected void setupConnection(Message message, URI currentURL, HTTPClientPolicy csPolicy)
      throws IOException {

    String s = currentURL.getScheme();
    if (!"ws".equals(s) && !"wss".equals(s)) {
      throw new MalformedURLException("unknown protocol: " + s);
    }

    message.put("http.scheme", currentURL.getScheme());
    String httpRequestMethod = (String) message.get(Message.HTTP_REQUEST_METHOD);
    if (httpRequestMethod == null) {
      httpRequestMethod = "POST";
      message.put(Message.HTTP_REQUEST_METHOD, httpRequestMethod);
    }

    final AhcWebSocketConduitRequest request =
        new AhcWebSocketConduitRequest(currentURL, httpRequestMethod);
    final int rtimeout = determineReceiveTimeout(message, csPolicy);
    request.setReceiveTimeout(rtimeout);
    message.put(AhcWebSocketConduitRequest.class, request);
  }
Пример #7
0
 Response getResponse() throws IOException {
   if (response == null) {
     String rid = entity.getId();
     RequestResponse rr = uncorrelatedRequests.get(rid);
     synchronized (rr) {
       try {
         long timetowait = entity.getReceiveTimeout();
         response = rr.getResponse();
         if (response == null) {
           rr.wait(timetowait);
           response = rr.getResponse();
         }
       } catch (InterruptedException e) {
         // ignore
       }
     }
     if (response == null) {
       throw new SocketTimeoutException("Read timed out while invoking " + entity.getUri());
     }
   }
   return response;
 }