Ok, this is the scenario: I've developed a webapp running Java at backend, everything is working pretty well, but now I have to integrate a PHP module (boss requirement) within the whole system.
So, I need to know if both backends can co-exist in a single application and how can I accomplish that.
Yes, you can do it using GwtPhp.
Unlike most of the other frameworks, GwtPHP is a framework for both client and server part. Server part uses PHP 5 - the most used web scripting language today.
It does not sound as if your boss is being reasonable!
There are some possibilities, though:
You could have the server-side entirely in PHP. Obviously you'd still have Java for the client-side because GWT requires it, but GWT can communicate via HTTP to any type of server using XML. You just can't use GWT's RMI-like interface if it's not a Java server.
Alternatively, you could have a separate PHP layer in your app, and the server-side Java itself can call it using HTTP.
Finally, (and more difficult, and experimental) there is a project to allow PHP to run in a Servlet Container, which may give you the ability to mix Java and php: see http://www.php.net/manual/en/intro.java.php
Two things spring to mind.
1) If the PHP app supports JSONP you could run it on a separate server and interact with it that way.
2) Stick the servlet container behind apache and proxy to the servlet container using something like the AJP connector. This would mean that apache forwards the GWT requests to tomcat/jetty whatever and serves the PHP itself.
Related
I am developing a php based application which has java as middleware for web services. Is there any frameowork/middleware available in php stack which allows me to write services in php and also hosted on php based app server, lets say Zend?
Thanks
Typically I'd expect the middleware to be the webservices - are you consuming or providing webservices using PHP?
Not that it makes much difference, PHP supports both.
You can roll your own solution, or use PHP Soap, the nuSoap PHP lib and xmlrpc. There's also the php/java bridge which implements a socket based abstraction for both ends (but obviously this is not strictly a web service).
I'm starting to study GWT now, and have a very general question, I could maybe teach myself with a little more experience, but I don't want to start it wrong, so I decided to ask you.
I always develop using JSF, having separate packages for beans, controllers and managedbeans.
However, as the GWT uses RPC, I will not have managedbeans, right?
So, GWT automatically handles user session for me, or do I have to do it myself?
What is the best package structure for the project?
It is best to use RPC, or create a webservice and access the webservice in GWT?
It's hard to host the application on a tomcat server?
Is there a test saying which server is faster for GWT?
Thank you.
However, as the GWT uses RPC, I will not have managedbeans, right?
True, GWT RPC uses POJOs.
So, GWT automatically handles user session for me, or do I have to do it myself?
GWT is pure AJAX APP - client code (normally) runs in one browser window (similar to gmail) and does not reload the web page. This means that the application state is always there - no need for sessions (as a means of saving state). You still might need sessions for user authentication, but this is usually handled by servlet container.
What is the best package structure for the project?
Three packages: client, server and shared. Client for GWT client code, server for server (also RPC) code and shared for POJOs that are used by both client and server.
It is best to use RPC, or create a webservice and access the webservice in GWT?
Go with GWT-RPC or (better, newer) with RequestFactory.
It's hard to host the application on a tomcat server?
It's straightforward: GWT client code is compiled to JS/html and is hosted as any static content. RPC server code is just Servlets - normal web.xml registration.
Is there a test saying which server is faster for GWT?
No clue, but IMHO does not matter, because most of the latency will come from database and network.
Also have a look at http://code.google.com/p/gwt-platform/
This framework is really great and follow all suggested best practices(e.g. MVP) by google and give you as well great support for gin, gwt dispatcher, website crawling, history with tokens, code splitting via gwt async etc.
If you want to set up a good project structure try to use the maven gwt plugin(http://mojo.codehaus.org/gwt-maven-plugin/) it helps you a lot with setting up an initial structure and manage your build process.
How to expose a C++ program as a Web Service?
Or is it a better idea to invoke C++ from Java and expose the resultant Java as a Web Service.
In any case, the C++ program should not undergo any changes.
Consume C++ program in Java WebService end point and expose java webservice
Use JNI to consume C++ program
Nice article from JavaWorld
Interestingly, webservices work on http protocol, which means that you can't "host" a webservice written in C++ without having an http server. Since each web server will have it's own mechanism of writing "hooks" or extensions, the next obvious question is which web server would you like to chose.
Let's say you want IIS on Windows. It's possible to use ISAPI extensions; so you need to know how to write one, which complies with web services standards. Or, alternatively, it's better to learn how to do it in C++ with Visual Studio, which will have lots of built-in stuff to help you get started.
In short, there is no "standard" way of exposing a web service in C++ and you have to be "platform" specific. Windows with IIS has one way of doing it. Apache Axis C++ has another.
You can try c-sevice-interface https://github.com/Taymindis/c-service-interface.
It create a C/C++ program as a service port and listening to NGINX fcgi.
This is a small bridge engine which can handle high load of request, any segfault will not break the engine, it will catch and free the thread, it is built on top NGINX, FCGI. You can setup the proxy, load balance, authentication via NGINX before reach to your interface.
The link shown as below is a wiki to Guide you how to startup from scratch.
https://github.com/Taymindis/backcurl/wiki/How-to-build-BackCurl-for-cpp-Android-development
I don't think this is quite possible or if it is recommended to do... but is there a way to connect or comunicate or deploy Java and .NET application for method beside Web Services. I mean I understand there are Messaging server that allows Java application communicate to each other but I dont know if this can cross development environment, any suggestion about it or thoughts about this?
I'm limited to web and desktop environments.
Apache Thrift is a way to go. You will need to write a service definition like this:
serivce helloworld{
string sayHello(1:string name)
}
Thrift then will generate RPC interface with network layer already implemented, It support many others language such as Java, C#, PHP, Python. Thrift support binary protocol over TCP/IP, so it's very fast.
for more, go to its wiki page http://wiki.apache.org/thrift/
You can use something like Apache ActiveMQ which uses JMS on the Java side and the .NET Messaging API on the .NET side.
We ended up writing our own implementation of Java-.Net communication protocol based on Hessian (later added JSON as well), but Thrift is a valid option.
The virtual machines (JVM vs CLR) are not going to talk to each other except through some OS level open standard. Shared Files (yuck), Sockets and Web Services come to mind. There is nothing that would allow you to call a .net subroutine from java or vice-versa.
Are servlets the only way one can write web applications in Java ?
No. Servlets are just the most convenient way to write a Web application in Java. If you think about it: what is a Web application? Quite simply it is an application that can receive an HTTP request and send back an HTTP response. Common models for achieving this are:
To use some kind of wrapper that invokes a script for each request. This was the first model and has a standard called CGI (Common Gateway Interface). The wrapper in this case is a Web server; or
To have persistent code within such a wrapper that can service HTTP requests (rather than being transient like CGI scripts).
There are variations upon this theme (eg FastCGI for (1)). Servlets are an example of (2). The reason 99% of all Java Web applications and frameworks use servlets is because servlets are standard (they have a specification endorsed by Sun and a reference implementation) and they're so low-level that pretty much whatever you want can be built on top of them.
That servlets are most convenient way to write Web apps in Java is arguable. They certainly have been around for a long time, but there are alternatives; take a look at restlets for example: http://www.restlet.org/