I'm now developing a json-rpc project in C++. I've not decided yet how I handle rpc's requests. From the client side, server receives jsons like below.
{"method":"App1hoge", ...}
{"method":"App1fuga", ...}
{"method":"App2foo", ...}
The server side handles some applications, App1, App2, etc. So I think I should design ApplicationRule class for each class. In this case, App1Rule and App2Rule classes are needed. And I should also design ApplicationRuleManager for handle each rule. But I'm not sure how I design ApplicationRuleManager.
In general, how should I design the relationship between ApplicationRuleManager and each ApplicationRule? Strategy pattern is familiar with this case?
Any help would be appreciated.
Related
I want to create an application that consists of a web based front-end and a c++ back-end. My choice is to use websocket protocol in order to achieve data transfer between them.Specifically the front end will trigger some measurements that will be done in the back-end and eventually return and store the relevant values in the front-end. I decided for the websocket protocol implementation to use poco library and specifically I came across the following example https://github.com/pocoproject/poco/blob/develop/Net/samples/WebSocketServer/src/WebSocketServer.cpp. However since I haven't totally grasped the factory concept in C++ I haven't figured out the role of class RequestHandlerFactory.Is it possible for someone to explain what is the role of the aforementioned class and regarding my implementation (front-end -> trigger back-end -> back-end do measurements ->back-end returns the value to front-end in order to be depicted in a web-based gui) do I need to make any modifications to make this work for my case ?
As you might have read in the sample, there are two implementations derived from HTTPServer. So depending on the type of connection requested by the client (WebsocketRequest, PageRequest) one can return the appropriate HTTPServer. The work of factory class is to handle the incoming request, decide which class should handle it (depending on the connection requested).
Since you would be requesting to exchange data and not a request to display a HTML document, you should go for WebSocketRequestHandler. Yes it can be done. You might want to remove the PageRequestHandler since you wouldn't be using it.
I have an application which has the following structure:
(Removed image, I don't have permission to post images. See here: http://s15.postimg.org/98qc3p7uz/Capture.png)
So 'App' holds Manager instance, Manager holds a vector of 'Connection', each of them holds a Protocol, and each Protocol holds a communication class. All the communication classes reference a single HAL class.
At the moment, the communication class constructor obtains a HAL instance as a singleton, eg. hal = HAL::GetInstance().
To make development and testing easier, I'd like to remove this dependency. Dependency Injection pattern seems ideal for this as it would allow me to use a fake HAL.
However, I don't think the Communication classes should have to do anything with HAL, likewise the protocol classes and the connections.
The main 'App' class DOES have a reference however, but I'm not sure about passing that to Manager->Connections[x]->Protocol->Communication.
Maybe I can abstract it out and let Manager have a reference to the HAL, and then each connection can have a parent pointer to the Manager, but it all seems to be getting messy and overcomplicated just for the sake of providing a HAL class reference to the communication.
Is there a better way to do this?
You could let the Manager create instances of Connection, Protocol, Communication and HAL. Then the Manager connects all of them. Very simple example in C++:
Manager::createEverything()
{
Connection connection;
Protocol protocol;
Communication communication;
HAL hal;
communication.setHal(hal);
protocol.setCommunication(communication);
connection.setProtocol(protocol);
}
You could also use dependency injection for creating different HAL-implementations that way. A class design could look like the following:
YUML diagram
YUML Edit Link
The above is quite simple but should give you an idea. Some more thoughts:
Use a Factory to create the different types of IHAL
Use the Builder Pattern to do the whole creation and aggregation thing
This is the Documentation from Oracle Docs. I want to clarify certain jargon based questions.
On the server side, the developer specifies the web service operations by defining methods in an interface written in the Java programming language. The developer also codes one or more classes that implement those methods. Client programs are also easy to code. A client creates a proxy (a local object representing the service) and then simply invokes methods on the proxy.
In The first Bold lettered sentence,
Are these classes, the Implementation classes of the Web service ?
Second Bold lettered,
will the client create the object of those service implementation classes? If yes, how come? Will JAX WS transport the complete service implementation class code which is # server to the client?
I am very new to the concept of web services. if my doubt is silly please bear with me. Thanks!
First point. Yes you code the implementation of the web service. However this is just limited to the business logic you wish to execute you don't have to go code the low level boiler plate code like creating a HTTP socket etc.
A simple class that is exposed as a web service will look like this:
#Webservice()
public class CalculatorWS()
{
#WebMethod(#operationame="add")
public int add(#WebParam(name="i") int i, WebParam(name="j") int j)
{
//this is where you code your implementation
return i+ j;
}
}
A client proxy class does NOT transfer the implementation across the wire. It just creates a proxy that you can use to call the implementation.
You can learn all about it step by step by following this tutorial. It is easy one to understand and follow and will answer all of your questions.
I use cwebpage_src code and I need to update some HTTP request headers while clicking on links. As I understand it can be done with self implementation of IHttpNegotiate->BeginTransaction. But how to get my IHttpNegotiate implementation called??
Thanks!
Although I have no experience of writing one, I believe that you need to write an asynchronous pluggable protocol, as recommended in this thread.
Details of how and why to do this are scattered around the web in various places, but the best exposition that I've read is in this post by Igor Tandetnik (abridged here for brevity):
There are several technology layers
that support the download and
navigation in Internet Explorer and
WebBrowser control. At the top, there
is WebBrowser itself and MSHTML object
that provides HTML parsing and
rendering. The client uses such
interfaces as IWebBrowser2 and
IHTMLDocument2 to communicate with
these high-level objects.
WebBrowser and MSHTML use URL Monikers
library to perform actual downloads.
URLMon exposes its services via
IMoniker and IBinding interfaces, and
the client (say MSHTML) implements
IBindStatusCallback and a number of
associated interfaces, e.g.
IHttpNegotiate or IAuthenticate.
Next down is an Asynchronous Pluggable
Protocol handler. An APP encapsulates
the details of a particular protocol,
such as http, file or res.
...
Most of the time, an application
hosting a WebBrowser control (or a BHO
running inside IE) uses high-level
services provided by WebBrowser and
MSHTML objects. However, sometimes
these services are insufficient, and a
lower-level hook is required.
...
It would be nice to be able to hook
into the communication sequence
between WebBrowser/MSHTML and URL
Monikers. Unfortunately, there does
not seem to be any way to do that - at
least, none that I know of. So, we
look at the next level - a
communication between a URL moniker
and an APP.
...
Now, it is rarely necessary to
implement a full-blown APP from
scratch - after all, how often do new
protocols actually get defined? But
for our purposes, it is useful to
implement a so-called passthrough APP
(pAPP). A pApp is an object that
implements both sides of URL
moniker-to-APP communication, that is,
it implements both IInternetProtocol
and IInternetProtocolSink /
IInternetBindInfo. We register it as a
temporary handler for a standard
protocol, such as HTTP. Now whenever
an HTTP request needs to be sent, URL
moniker will create an instance of our
pAPP and ask it to do the job. The
pAPP then creates an instance of a
standard APP for the protocol in
question (I call it a target APP, or
tAPP, but be aware that I've invented
the terminology myself, it's not
widely accepted, suggestions for a
better naming convention are welcome)
and acts as its client. At this point,
our pAPP becomes a proverbial
man-in-the-middle. In the simplest
case, any method call made by URL
Moniker on pAPP is forwarded to tAPP,
and any method call made by tAPP on
pAPP is forwarded back to URL Moniker.
The pAPP gets to observe and, if
desired, modify every bit of
information relevant to this request
passing back and forth between the
moniker and the tAPP.
Igor has a couple of sample projects that should help in writing your own pAPP:
PassthruApp.zip
PassthruAppBeta.zip
What are the best-practice / industry standard technologies for the folowing requirements
Allow transfer of business objects from one client / server to another
Language and platform independent
Supports Streaming to alow passing large data (e.g. a connected statefull conversation)
Is Asynchronous in nature (doesn't block, allows monitoring progress)
SOAP workaround
1,2 point on SOAP web services, but 3 and 4 make it a little hard to implement (don't they?)
I was thinking of the following "hack", but I both don't like it, and I'm sure there is a better solution.
To support 3 and 4 the SOAP web service can have methods that pass the data in chunks, e.g.
void startObjTransfer(String objectId);
void addObjChunk(String objectId, ObjData currentChunk);
void endObjTransfer(String objectId);
Where ObjData contains a partial graph of the data, and knowledge of its location in the graph.
to better support 4 a method like this can be used to ask how much progress was made
void getObjTransferProgress(String objectId);
What do you think about the above? isn't there (hopefully there is) a better one? (even non SOAP)
RMI / COM / .NET Remoting / DCOM
Not language independed
CORBA
Well, no.
REST
Not answering 3 and 4, (SOAP + Buzz?)
AJAX / COMETD
Related to question: Asynchronous web service streaming
Not sure how this will work, please explain
Message Queue?
Will that work for this purpose?
I think Coucho Hessian should fulfill your needs (including streaming, platform independence...). You might also take a look Thrift from the Facebook guys.