private void SendOnPremiseConnectorRequest(Guid linkId, IOnPremiseConnectorRequest request) { PrepareRequestBodyForRelaying((OnPremiseConnectorRequest)request); _logger?.Verbose("Sending on premise connector request. request-id={RequestId}, link-id={LinkId}", request.RequestId, linkId); _backendCommunication.SendOnPremiseConnectorRequest(linkId, request); }
public async Task <IHttpActionResult> PingAsync(Guid id) { var requestId = Guid.NewGuid().ToString(); var onPremiseConnectorRequest = new OnPremiseConnectorRequest { HttpMethod = "PING", Url = "", RequestStarted = DateTime.UtcNow, OriginId = _backendCommunication.OriginId, RequestId = requestId }; await _backendCommunication.SendOnPremiseConnectorRequest(id.ToString(), onPremiseConnectorRequest); var onPremiseTargetReponse = await _backendCommunication.GetResponseAsync(requestId); onPremiseConnectorRequest.RequestFinished = DateTime.UtcNow; _requestLogger.LogRequest(onPremiseConnectorRequest, onPremiseTargetReponse, HttpStatusCode.OK, id, _backendCommunication.OriginId, "invalid/Ping.local/"); return(Ok()); }
public async Task <IHttpActionResult> SendPing(Guid id) { var requestId = Guid.NewGuid().ToString(); var request = new OnPremiseConnectorRequest() { HttpMethod = "PING", Url = String.Empty, RequestStarted = DateTime.UtcNow, OriginId = _backendCommunication.OriginId, RequestId = requestId }; var task = _backendCommunication.GetResponseAsync(requestId); _backendCommunication.SendOnPremiseConnectorRequest(id, request); var response = await task.ConfigureAwait(false); request.RequestFinished = DateTime.UtcNow; _requestLogger.LogRequest(request, response, id, _backendCommunication.OriginId, "DEBUG/PING/", response?.StatusCode); return((response != null) ? (IHttpActionResult)Ok() : new StatusCodeResult(HttpStatusCode.GatewayTimeout, Request)); }
public async Task <HttpResponseMessage> Relay(string path) { _logger.Trace("Relaying http {0} {1}", path, ControllerContext.Request.Method); if (path == null) { _logger.Info("Path is not set."); return(NotFound()); } var pathInformation = _pathSplitter.Split(path); var link = _linkRepository.GetLink(pathInformation.UserName); if (link == null) { _logger.Info("Link for requested path {0} not found", path); return(NotFound()); } if (link.IsDisabled) { _logger.Info("{0}: Link {1} is disabled", link.Id, link.SymbolicName); return(NotFound()); } if (string.IsNullOrWhiteSpace(pathInformation.PathWithoutUserName)) { _logger.Info("{0}: Path without username is not found. Wrong path information: {1}", link.Id, path); return(NotFound()); } if (link.AllowLocalClientRequestsOnly && !Request.IsLocal()) { _logger.Info("{0}: Link {1} only allows local requests.", link.Id, link.SymbolicName); return(NotFound()); } _logger.Trace("{0}: Building on premise connector request. Origin Id: {1}, Path: {2}", link.Id, _backendCommunication.OriginId, path); var onPremiseConnectorRequest = (OnPremiseConnectorRequest) await _onPremiseRequestBuilder.BuildFrom(Request, _backendCommunication.OriginId, pathInformation.PathWithoutUserName); _logger.Trace("{0}: Sending on premise connector request.", link.Id); await _backendCommunication.SendOnPremiseConnectorRequest(link.Id.ToString(), onPremiseConnectorRequest); _logger.Trace("{0}: Waiting for response. Request Id", onPremiseConnectorRequest.RequestId); var onPremiseTargetReponse = await _backendCommunication.GetResponseAsync(onPremiseConnectorRequest.RequestId); if (onPremiseTargetReponse != null) { _logger.Trace("{0}: Response received from {1}", link.Id, onPremiseTargetReponse.RequestId); } else { _logger.Trace("{0}: On Premise Timeout", link.Id); } var response = _httpResponseMessageBuilder.BuildFrom(onPremiseTargetReponse, link); onPremiseConnectorRequest.RequestFinished = DateTime.UtcNow; var currentTraceConfigurationId = _traceManager.GetCurrentTraceConfigurationId(link.Id); if (currentTraceConfigurationId != null) { _traceManager.Trace(onPremiseConnectorRequest, onPremiseTargetReponse, currentTraceConfigurationId.Value); } _requestLogger.LogRequest(onPremiseConnectorRequest, onPremiseTargetReponse, response.StatusCode, link.Id, _backendCommunication.OriginId, path); return(response); }