Can we use php web services in java? - java

I have a web application in JAVA (Spring MVC framework) and I want to connect to a website and use its web services which wrote in php, is it possible ? if yes how can I do that?

It doesn't matter what language one used to create a webservice. You can talk to any webservice by agreeing on how it exchanges messages.

Yes, Spring integrates well with Apache Axis: http://axis.apache.org/axis2/java/core/docs/spring.html
To consume web services with Spring you can use JaxWsPortProxyFactoryBean to create a client proxy: http://musingsofaprogrammingaddict.blogspot.com/2009/03/writing-and-testing-jax-ws-clients.html
From Spring in Action, here's how you'd configure an example web service proxy bean:
<bean id="spitterService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"
p:wsdlDocumentUrl="http://localhost:8080/services/SpitterService?wsdl"
p:serviceName="spitterService" p:portName="spitterServiceHttpPort"
p:serviceInterface="com.habuma.spitter.service.SpitterService"
p:namespaceUri="http://spitter.com"/>

The beautiful thing about web services, and web services are beautiful things, their hosts are made with wsdl's, their client is made in Spring! (Totally stole that from the mouse (just a warning, as per the comments, this rhyme is not to be used as an authoritative anything. It is an attempt at humor by someone who was excessively tired at 3 AM because of Win 7 issues))
Web services are language agnostic -- the only thing which matters is that they are up and running (and serving valid outputs), not that they are using technology X, Y, or Z. Theoretically, you could even have a webservice running on something written in Piet or Brainf*ck.
A tutorial on how to create a client can be found here.

Use CWSDLGeneratorDocument.php for generate WSDL file in DOCUMENT/LITERAl style and use standart library JAX-WS in java 1.7.

Related

Solution for easy generating rest services?

We have a application which works with MySql database.
Now we are implementing mobile version of our application and I'm looking for java solution for easy generating rest services from already ready sql queries.
Details on security and performance:
Security is required (LDAP).
Performance - working time of rest request should be approximately equals working time of sql request.
What solutions can be used for it?
I think the best solution is REST4Enterprise
also can take a look on and restSQL
I suggest using spring roo very easy to use
I recommend using netbeans to generate rest webservices from database tables.
Netbeans also offers the ability to generate REST webservices from entity beans (JPA entities).
Have a look at this link.
If you are looking for just CRUD REST services - one of the above tools suggested by others can help.
But for something more check - Dropwizard
my 2c
For Mobile applications, REST is the best recommended architecture. But you have to ensure the session handling at the client side (recommended).
Eclipse -> Webservice -->Create a Sample Rest Webservice will be a good starting point
You can use spring-rest or grails to develop rest services.
Consider doing web services in PHP. No need for anything other than Tomcat, and offers LDAP verification. It is very quick time to market, and PHP works with MySql pretty seamlessly.
You can give a look at Developing REST Web Services Tutorial.. not sure if it's the best solution but could be one... I used it twice and found it usefull and really easy.
In the Java™ world, you can build a RESTful web service in several ways: Some folks use JSR 311(JAX-RS) and its reference implementation Jersey, others use the Restlet framework, and some might even implement from scratch. Spring framework for building Java EE applications, also supports REST in its MVC layer.
http://www.ibm.com/developerworks/webservices/library/wa-spring3webserv/index.html
Below article also covers RESTful web services api using java and mysql
http://www.9lessons.info/2012/09/restful-web-services-api-using-java-and.html

What is the WCF correspondent for Java?

Is there a unique service centralizer like WCF for Java where I can create and host services for different media?
Change:
It seems it has a different concept in the java world, is it called application server?
JAX-WS / Metro
allows you to annotate your web service class and methods and generates a WSDL from those annotations, just like WCF.
allows you to generate a service wsdl-first, just like WCF
allows you to generate a web service client, just like WCF
allows you to host your web service in any Java EE container. This is comparable to WCF's IIS hosting.
allows you to host your web services using the Endpoint api. This is comparable to WCFs self-hosting.
allows you to choose between SOAP or Fast InfoSet over HTTP or TCP protocols, like the WCF transport options. (Though I don't think it allows named pipes...)
So in many ways it corresponds to WCF. It is more focussed on Web Services than WCF is, though. Like the names say.
I have found some blog, it is pretty old, but it explained very well about java jax-ws and .net-wcf.
Hope this helps..!
The options I've found are
Netty
http://netty.io/
Apache MINA
http://mina.apache.org/
Yes, and it's pretty simple to use it's called java webservices, and it uses wsdl files like WCF and everything. refer to this: http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
It seems you want to host your application locally ...For that there are several application server's like Jboss,Glassfish,Tomcat,IBM Web sphere ...

Consume .NET web services in Java

I have created .NET web services. I want to run it on a remote server and have the Java Applications (clients) contact the server for data. How should I implement the Server such that the Clients can make use of the org.apache.xmlrpc.client.XmlRpcClient package?
I just want the clients to generate a request for data and does not want to have any other dependencies.
Here is a good material on using eclipse for this purpose: http://wso2.org/library/tutorials/creating-web-service-client-3-steps-using-eclipse
Thanks.
Although both are rightfully called "web services" the SOAP based web services usually created in .net are incompatible with web services following the older XML-RPC standard.
In my opinion you can follow 2 routes to solve your problem:
either you go the SOAP route under Java, one of the most common API's for that purpose would be jax-ws - some excellent pointers to tutorials here, in Pascal Thivent's answer
or you transform your .net webservices to XMl-RPC by using xml-rpc.net
Both routes have advantages and disadvantages, it's hard to make that choice for you without knowing more about your project. A priori choosing the SOAP route might look "safer" as there the entire communication will be based on standard components.
If you have the Web Services on the .NET side, you must have a Web Service Description Language (WSDL) (if you are not talking about REST), you can easily create the client classes to consume this Web Service using an IDE, check this link here: http://netbeans.org/kb/docs/websvc/client.html
If you are using Eclipse I suggest you this tutorial to build a simple WS client.
You can adapt this example application to your real needs.
NOTE the example uses an old version of Eclipse, but the wizard is very similar also in newer versions.

rmi and webservice

currently i have an web app build with Strus2 and Spring (IoC, Transactions), and i want to split this into 2 apps; one client which will contain only the web part and one core services that will be accessed via webservices and/or rmi.
I have a dilemma in what technology should i use for "glue", because i like the fact that webservices can be accessed by any clients (php,.net,...,mobile), but as i understand java rmi is faster then webservices.
I was thinking to expose the functionality via webservices and rmi in the same time... but i do not know how to do that.
Also in my current app i have a ajax action that is executed each second from the client to the server, and in this new configuration i think that there will be some performance penalties due to this.
How should i "attack" this situation ?
Thanks,
but as i understand java rmi is faster then webservices.
Why do you think this? Do you have a citation to bolster this claim?
Both RMI and webservices are using TCP/IP; both incur similar network latency. The former uses Java or CORBA serialization to send messages over the wire; the latter uses either HTTP (for REST) or XML over HTTP (for SOAP or RPC-XML).
The relative speed is far more dependent on what those services are doing and how you code them.
I would prefer a web service because simple and open win. You are restricted to RMI/CORBA clients if you use RMI.
Nice. You are running Spring and you already have all you need. Just throw in a few jars (spring webservices and related jars) and you should be good to go.
Please refer :
http://static.springsource.org/spring/docs/2.5.4/reference/ejb.html
http://static.springsource.org/spring/docs/2.5.4/reference/remoting.html

Calling a soap web service using java

In my java program, I need to call a SOAP web service that is deployed on a remote server.
Looks like there are several different approaches when explored in web.
But I would like to know as what is currently being used more in the developer world.
Also is there is a way to call a SOAP web service using Spring or axis or xfire.
Thanks in advance for your input.
For spring you can look at http://static.springsource.org/spring-ws/site/reference/html/client.html for client information.
When I write SOAP webservices I tend to use jax-ws now, especially since it comes installed with JDK6 now.
For a tutorial on that you can look at http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXWS.html.
I like it since it uses annotations, so is simpler than using axis.
If you are using Spring then using their webservice options would be your best bet though.

Categories