SuperSocket - Get the full message appServer_NewRequestReceived event - supersocket.net

How do I get the full message appServer_NewRequestReceived event. For example, if I send a message "0000858 5521113 GT855500" in requestInfo.Key is "0000858" and requestInfo.Body comes "5521113 GT855500".
I wonder if there is a way where you can get the complete message passed on telnet?
Thanks

I managed to solve as follows:
public class MyAppServer : AppServer
public class CustomStringParser : IRequestInfoParser<StringRequestInfo>
{
public StringRequestInfo ParseRequestInfo(string source)
{
return new StringRequestInfo("", source, new []{""});
}
}
Thank you all

Related

ASP.NET Some service register after mediator

We are working on service which collect data from AWS SQS then send batch to client. We are using mediator to publish notifications. The diagram of program looks like:
The problem is in first NotificationHandler from Mediatr.
private readonly EventCollectorHostedService _collector;
public CollectIncomingEventNotificationHandler(EventCollectorHostedService collector)
{
_collector = collector;
}
Class EventCollectorHostedService is register after Mediator so is not visible during registering this NotificationHandler and additionally it use Mediator to publish notification that batch is ready to send.
The error is that cannot construct CollectIncomingEventNotificationHandler because -> Unable to resolve service for type 'Api.Services.HostedServices.EventCollectorHostedService'.
services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
services.AddHostedService<EventCollectorHostedService>();
The ugly solution is to declare some functionality in EventCollectorHostedService as static or instead of injecting EventCollectorHostedService, inject IServiceProvider.
But these solution don't look clean for me so do you have any other better solution ?
Thanks in advance.
Maybe someone encountered with similar problem so finally i have a brilliant solution.
Background services have to be treat like separate microservices based on event driven architecture so we have to make internal message broker mechanism.
The very simple solution which cover my case is:
public class NotificationChannel : INotificationChannel
{
public event EventHandler<IncomingEventNotificataionEventArgs> IncomingEventReceived;
public void Publish<T>(T notification)
{
if(notification is IncomingEventNotification incomingEventNotification)
{
OnIncomingEventReceived(incomingEventNotification);
}
}
protected virtual void OnIncomingEventReceived(IncomingEventNotification notification)
{
if(IncomingEventReceived != null)
{
var args = new IncomingEventNotificataionEventArgs(notification);
IncomingEventReceived(this, args);
}
}
}

404 Not Found when accessing a Web API method

I need this method to return an integer value:
[Route("api/[controller]")]
public class ValuesController : Controller
{
[HttpPost("ByPayment")]
public int Payment(string accountId, string mount, string shenase)
{
return 21;
}
}
When I go to the following address:
http://localhost:1070/api/values/Payment/ByPayment?accountId=258965&mount=85694&shenase=85456
I get the following error:
What's the problem? And how can I solve it?
I thing you wanted to send Get request with query string parameters.
1. Change the 'HttpPost' to 'HttpGet'
[HttpPost("ByPayment")] to [HttpGet("ByPayment")]
2. Also change your request url, Its not correct.
http://localhost:1070/api/values/Payment/ByPayment?accountId=258965&mount=85694&shenase=85456
to
http://localhost:1070/api/Values/ByPayment?accountId=258965&mount=85694&shenase=85456
Updated code
[Route("api/[controller]")]
public class ValuesController : Controller
{
[HttpGet("ByPayment")]
public int Payment(string accountId, string mount, string shenase)
{
return 21;
}
}
I suggest please read this tutorial to understand the basic of webapi.
There could be more reasons why you get the 404. But there is one thing that's definitely wrong - you are sending GET requests to a method that's marked with [HttpPost("ByPayment")] (which means it only responds to POST requests.
I don't know what you intended to do but you either have to change it to [HttpGet("ByPayment")] or use a REST client that can make POST requests (e.g. REST Easy.
Other reason could be that your controller has a wrong name. It should be called PaymentController.

how to update search results using signalR

I've just started learning signalR and I'm trying to implement a search feature.
How would i go about periodically updating a user's search result. My initial idea is to run a timed job via IRegisteredObject to trigger a check from client with search params like so:
public class BackgroundTimer : IRegisteredObject
{
private Timer taskTimer;
private IHubContext hub;
public BackgroundTimer()
{
HostingEnvironment.RegisterObject(this);
hub = GlobalHost.ConnectionManager.GetHubContext<SearchHub>();
taskTimer = new Timer(OnTimerElapsed, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5));
}
private void OnTimerElapsed(object sender)
{
hub.Clients.All.checkForUpdates();
}
}
public class SearchHub : Hub
{
public void Search(string searchText)
{
string jsonResult = string.Empty;
//TODO save result to jsonResult
Clients.Caller.broadcastMessage(jsonResult);
}
}
However i can't help but think there are much more efficient ways to accomplish this. Any advice pls
With this code you are just doing what the clients could instead, poll the server each second. Either publish a message on all actions that alter the search result and act on that. Or use SqlDependency.

This method cannot be called once the request has fully transitioned to a WebSocket request

I've been trying to call HttpContext.Current.Server.Execute in OnMessage event implemented in a subclass of WebSocketHandler:
public class MySocketService : WebSocketHandler
{
public override void OnMessage(string message)
{
// some activity which decides to update an area in client browser
var html = HttpContext.Current.Server.Execute("Login.ascx", writer, true);
Send(html);
}
}
But I always receive the same exception. Is there any way to make this call? Or maybe I will have to consider using WebClient?
Thanks for your help.

Spring form binding - use IllegalArgumentException message as error message

I have a custom domain class with a single constructor that takes a String, as well as a toString() method. The constructor decodes the input string, performs validations on it and throws IllegalArgumentException if invalid.
I want to bind directly to this field, as described here: http://blog.springsource.org/2009/11/17/spring-3-type-conversion-and-validation/ (see 'Convention Over Configuration' section).
That is working fine & I am displaying the error message resolved by Spring (typeMismatch on barcodeInfo).
I know that I can customize this error message using a messageSource entry, e.g.
typeMismatch.barcodeInfo=Invalid format
However, the error message that I want to display isn't always the same, it depends on the value of the input string. Hence, I want to display the error message that I originally used in the IllegalArgumentException that I threw from the constructor. Is this possible?
I am specifically looking for a solution which will work with Spring WebFlow.
You might want to check BindingErrorProcessor used by WebDataBinder. There you can implement your own custom logic for translating exceptions to validation errors.
Notes:
You should implement your own exception (to be able to distinguish it from IllegalArgumentException thorwn by other components).
You can initialize WebDataBinder with your custom BindingErrorProcessor within your #InitBinder method (or set specific WebBindingInitializer to your handler adapter).
As Pavel mentioned in his answer, you can achieve this by implementing BindingErrorProcessor.
It should look like this:
...
import org.springframework.validation.DefaultBindingErrorProcessor;
...
#Controller
public class YourController {
...
#InitBinder
public void initBinder(WebDataBinder binder) {
binder.setBindingErrorProcessor(new DefaultBindingErrorProcessor() {
#Override
public void processPropertyAccessException(
PropertyAccessException ex, BindingResult bindingResult) {
if (ex.getPropertyName().equals("fieldInQuestion")) {
Throwable cause = ex.getMostSpecificCause();
FieldError fieldError;
fieldError = new FieldError(
bindingResult.getObjectName(),
"fieldInQuestion",
cause.getMessage());
bindingResult.addError(fieldError);
} else {
super.processPropertyAccessException(ex, bindingResult);
}
}
});
}
}

Resources