/*
(non-Javadoc)
@see javax.sip.ClientTransaction#sendRequest()
340198
public void sendRequest() throws SipException {
        //hack to add this tx as cancelable, in case someone use x send, instead of dialog.send(ctx);
        validateWrappedTransaction();
        final String method = this.wrappedTransaction.getRequest().getMethod();
        final DialogWrapper dw = getDialogWrapper();
        if ((method.equals(Request.INVITE) || method.equals(Request.SUBSCRIBE)) && dw != null) {
            dw.lastCancelableTransactionId = this.activityHandle;
        }
        if (tracer.isInfoEnabled()) {
            tracer.info(toString() + " sending request:\n" + getRequest());
        }
        wrappedTransaction.sendRequest();
    }
1120435
protected void sendConfigureRequest(MemberState member, ConfigureRequest request) {
    logger.debug("{} - Configuring {}", context.getCluster().member().address(), member.getMember().address());

    // Start the configure to the member.
    member.startConfigure();

    context.getConnections().getConnection(member.getMember().serverAddress()).whenComplete((connection, error) -> {
      context.checkThread();

      if (open) {
        if (error == null) {
          sendConfigureRequest(connection, member, request);
        } else {
          // Complete the configure to the member.
          member.completeConfigure();

          // Trigger reactions to the request failure.
          handleConfigureRequestFailure(member, request, error);
        }
      }
    });
  }
502158
@Override
	public final void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
    {
    	if (this.destination == null)
    		throw new UnsupportedOperationException("Destination was not set at creation time");

        // Setup message fields
    	setupMessage(destination,message,deliveryMode,priority,timeToLive);
    	
    	// Handle foreign message implementations
        message = MessageTools.normalize(message);
        
    	sendToDestination(destination,false,message,deliveryMode,priority,timeToLive);
    }
288519
public void sendRequest(Message request, Object context, Message.Builder responseBuilder,
                          Duration timeout) {
    // Pack it as a no-timeout request and send it!
    final REQID rid = REQID.generate();
    contextMap.put(rid, context);
    responseMessageMap.put(rid, responseBuilder);

    // Add timeout for this request if necessary
    if (timeout.getSeconds() > 0) {
      registerTimerEvent(timeout, new Runnable() {
        @Override
        public void run() {
          handleTimeout(rid);
        }
      });
    }

    OutgoingPacket opk = new OutgoingPacket(rid, request);
    socketChannelHelper.sendPacket(opk);
  }
167100
public void sendRequest(String host, int port, int timeout, String func, String funcArg)
    {
        DRPCClient client = null;

        try
        {
            client = createClient(host, port, timeout);
        }
        catch (Exception ex)
        {
            logger.error("DRPCClient connect failed.", ex);
            return;
        }

        String result = null;

        try
        {
            result = client.execute(func, funcArg);
            logger.info("DRPCRequest result is " + result);
        }
        catch (Exception ex)
        {
            logger.error("DRPCRequest failed.", ex);
        }
        finally
        {
            client.close();
        }
    }
200893
async def send_request(self, method, args=()):
        ''''''
        message, event = self.connection.send_request(Request(method, args))
        return await self._send_concurrent(message, event, 1)
1054455
protected function sendRequest()
    {
        try {
            $this->response = $this->client->send($this->request);
        } catch (RequestException $e) {
            $this->response = $e->getResponse();

            if (null === $this->response) {
                if ($this->throwsRequestException) {
                    throw $e;
                }
            }

            if ($this->throwsRequestException) {
                throw new \Exception((string)$this->response->getBody());
            }
        }
    }
70416
public void sendObjectRequest(HttpURLConnection httpURLConnection, Object request) throws Exception {
		try {

			// send the request query object to the server
			ObjectOutputStream oos = new ObjectOutputStream(httpURLConnection.getOutputStream());
			oos.writeObject(request);
			oos.close();
		} catch (Exception ex) {
			Debug.logError(ex, module);
			throw new Exception(ex);
		}
	}
1070631
@Override
  public void sendRegistrationTerminationRequest(JRegistrationTerminationRequest request)
      throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    send(Event.Type.SEND_MESSAGE, request, null);
  }
910441
protected void sendConfigureRequest(Connection connection, MemberState member, ConfigureRequest request) {
    logger.trace("{} - Sending {} to {}", context.getCluster().member().address(), request, member.getMember().serverAddress());
    connection.<ConfigureRequest, ConfigureResponse>sendAndReceive(request).whenComplete((response, error) -> {
      context.checkThread();

      // Complete the configure to the member.
      member.completeConfigure();

      if (open) {
        if (error == null) {
          logger.trace("{} - Received {} from {}", context.getCluster().member().address(), response, member.getMember().serverAddress());
          handleConfigureResponse(member, request, response);
        } else {
          logger.warn("{} - Failed to configure {}", context.getCluster().member().address(), member.getMember().serverAddress());
          handleConfigureResponseFailure(member, request, error);
        }
      }
    });
  }
771090
protected void sendRequest(HttpURLConnection connection, Request request) throws IOException {
        // Set up the request.
        connection.setRequestMethod(request.method);
        connection.setRequestProperty("Accept", "application/json");
        connection.setRequestProperty("Authorization", request.authorization);

        // If a different HttpHandler is used, we won't get this header. We would need to refactor
        // to a delegation pattern to give the client code's HttpHandler a chance to process the
        // Request first, then attach our custom headers, which would likely be a breaking change.
        connection.setRequestProperty("Keen-Sdk", "java-" + KeenVersion.getSdkVersion());

        // If the request has a body, send it. Otherwise just connect.
        if (request.body != null) {
            if (HttpMethods.GET.equals(request.method) ||
                HttpMethods.DELETE.equals(request.method)) {
                throw new IllegalStateException("Trying to send a GET request with a request " +
                                                "body, which would result in sending a POST.");
            }

            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type", "application/json");
            request.body.writeTo(connection.getOutputStream());
        } else {
            connection.connect();
        }
    }
373302
private void sendRequest(String header, byte[] body) throws IOException {
        // Send entire message in one write, else suffer the fate of weird TCP/IP stacks.
        byte[] headerBytes = Utils.toBytes(header);
        byte[] requestBytes = headerBytes;
        if (body != null && body.length > 0) {
            requestBytes = new byte[headerBytes.length + body.length];
            System.arraycopy(headerBytes, 0, requestBytes, 0, headerBytes.length);
            System.arraycopy(body, 0, requestBytes, headerBytes.length, body.length);
        }
        
        // Send the header and body (if any) and flush the result.
        m_outStream.write(requestBytes);
        m_outStream.flush();
    }
855998
public SendRequest getSendRequest() {
        Transaction tx = new Transaction(params);
        for (Protos.Output output : paymentDetails.getOutputsList())
            tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(output.getAmount()), output.getScript().toByteArray()));
        return SendRequest.forTx(tx).fromPaymentDetails(paymentDetails);
    }
881086
private boolean send(String request)
    {
        needRateLimit = !client.send(request, false);
        attemptedToSend = true;
        return !needRateLimit;
    }
1109898
private <T extends Request, U> void sendRequest(T request, BiFunction<Request, Connection, CompletableFuture<U>> sender, Connection connection, Throwable error, CompletableFuture<U> future) {
    if (open) {
      if (error == null) {
        if (connection != null) {
          LOGGER.trace("{} - Sending {}", id, request);
          sender.apply(request, connection).whenComplete((r, e) -> {
            if (e != null || r != null) {
              handleResponse(request, sender, connection, (Response) r, e, future);
            } else {
              future.complete(null);
            }
          });
        } else {
          future.completeExceptionally(new ConnectException("Failed to connect to the cluster"));
        }
      } else {
        LOGGER.trace("{} - Resending {}: {}", id, request, error);
        resendRequest(error, request, sender, connection, future);
      }
    }
  }
506359
private void send(final byte[] buffer, final Session destination) {
        synchronized (connections) {
            // execute asynchronously to avoid slower clients from interfering with faster clients
            final ExecutorService connectionThread = connectionThreads.get(destination);
            if (connectionThread == null) {
                // Maybe the client has disconnected in the mean time.
                return;
            }
            connectionThread.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        // for the case that the runnable was committed shortly before the connection was closed.
                        if (destination.isOpen()) {
                            // FIXME replace with getAsyncRemote and removeconnectionThreads as soon as
                            // getAsyncRemote on tomcat is thread-safe
                            destination.getBasicRemote().sendBinary(ByteBuffer.wrap(buffer));
                        }
                    } catch (final IOException e) {
                        try {
                            if (destination.isOpen()) {
                                destination.close(new CloseReason(CloseCodes.PROTOCOL_ERROR, "Failed to send data."));
                            }
                        } catch (final IOException e1) {
                            // The outer exception already indicated that something went wrong.
                            ignore(e1);
                        }
                        handleClientError(destination, e);
                        connectionCloses(destination);
                    }
                }
            });
        }
    }
634346
@SuppressWarnings("unchecked")
	public Request createRequest(Request origRequest) throws SipException {

		final SleeSipProviderImpl provider = ra.getProviderWrapper();
		
		final SIPRequest request = (SIPRequest) origRequest.clone();

		// note: no need to work on dialog tags, since remote tag remains the same and
		// local tag will be ensured when sending

		/*
		 * If the B2BUA decides to relay the received request, its associated
		 * UAC generates a new downstream SIP request with its new Via, Max-
		 * Forwards, Call-ID, CSeq, and Contact header fields, as described in
		 * RFC3261.
		 */
		final String transport = request.getTopmostViaHeader().getTransport();
		final ListeningPointImpl listeningPointImpl = (ListeningPointImpl) provider.getListeningPoint(transport);


		final ViaList viaList = new ViaList();
		viaList.add((Via) listeningPointImpl.createViaHeader());
		request.setVia(viaList);
		
		try {
			request.setHeader(provider.getHeaderFactory().createMaxForwardsHeader(70));
		} catch (InvalidArgumentException e) {
			throw new SipException("Failed to create max forwards header",e);
		}
		request.setHeader((Header) getCallId().clone());
		// note: cseq will be set by dialog when sending
		// set contact if the original response had it

        URI requestURI = request.getRequestURI();
        if (requestURI != null && requestURI.isSipURI()) {
            SipURI sipURI = (SipURI) requestURI;
            if (sipURI.getHost().equals(listeningPointImpl.getIPAddress()) && sipURI.getPort() == listeningPointImpl.getPort()) {
                // set remote target as request uri
                request.setRequestURI(getRemoteTarget().getURI());
            }
        }

        if (origRequest.getHeader(ContactHeader.NAME) != null) {
			request.setHeader(listeningPointImpl.createContactHeader());
		}
		
		/*
		 * Route header fields of the upstream request MAY be copied in the
		 * downstream request, except the topmost Route header if it is under
		 * the responsibility of the B2BUA. Additional Route header fields MAY
		 * also be added to the downstream request.
		 */
		if (getState() == null || !wrappedDialog.getRouteSet().hasNext()) {
			// no route recorded
			final RouteList routeList = request.getRouteHeaders();
			if (routeList != null) {
				final RouteHeader topRoute = routeList.get(0);
				final URI topRouteURI = topRoute.getAddress().getURI();
				if (topRouteURI.isSipURI()) {
					final SipURI topRouteSipURI = (SipURI) topRouteURI;
					if (topRouteSipURI.getHost().equals(listeningPointImpl.getIPAddress())
							&& topRouteSipURI.getPort() == listeningPointImpl.getPort()) {
						if (routeList.size() > 1) {
							routeList.remove(0);
						}
						else {
							request.removeHeader(RouteHeader.NAME);
						}					
					}
				}
			}
		}
		else {
			// replace route in orig request with the one in dialog
			request.removeHeader(RouteHeader.NAME);
			final RouteList routeList = new RouteList();
			for (Iterator<Route> it = wrappedDialog.getRouteSet(); it.hasNext();) {
				Route route = it.next();				
				routeList.add(route);								
			}
			if (!routeList.isEmpty()) {
				request.addHeader(routeList);
			}
		}
		
		/*
		 * Record-Route header fields of the upstream request are not copied in
		 * the new downstream request, as Record-Route is only meaningful for
		 * the upstream dialog.
		 */
		request.removeHeader(RecordRouteHeader.NAME);

		return request;		
	}