I know php webservice SOAP,json,rest etc, but I am new for java webservice. Now I want to get php client to java webservice. What is the best way to do this?
There is nothing new in it. Just create SoapClient with java web services WSDL URL and call it's method:
<?php
try{
$proxy = new SoapClient("javaWsdlUrl?wsdl");
$result = $proxy->javaWSMethod(array("arg0"=>"1234","arg1"=>"5678"));
print_r($result);
} catch (Exception $e) {
echo $e->getMessage ();
}
?>
Other things will be same like generating stubs, getting method names,...
When you connnect to a public webservice like Amazon, you dont (necesserly) know what language is used to create the webservice (server side) . So you will connect to your java webservice the same way you connect to a php or any other webservice.
Related
Hello I face some problem, I'm not able to to call webservice from java and send the result to flex side.
the process
the user launches the application and lands on an authentication form
The user enters login and password and submits the authentication form
Submission call on java side a remoteservice checkUserCredetialFromLdap()
inside this java method I try to call an external ldap webservice as shown below.
The class responsible for ldap ws call is in custom jar (Maven dependencies)
public User checkUserCredetialFromLdap(String identifiant, String password) throws EmmBusinessException, LdapServiceException{
User myUser = null;
User myCompleteUser = null;
//initialization of webservice with the endpoint URL failed
Axis1LdapWsAuth ws = new Axis1LdapWsAuth(Config.getProperties().getProperty("endpoint.url"));
try{
//authentication using webservice
String csif_sessionID =ws.login(identifiant, password);
....
}
}catch(LdapServiceException lse)
{
EmmBusinessException emmB = new EmmBusinessException(lse,this,"","Unable to get User",Level.WARNING);
log(emmB);
throw (emmB);
}
catch (Exception t) {
EmmBusinessException emmB = new EmmBusinessException(t,this,"","Unable to get User",Level.WARNING);
log(emmB);
throw (emmB);
} finally {
finish();
}
return myCompleteUser;
}
I know it's possible to call webservice on flex side using RPC, but I don't want to do that, but for some reason I need to and have to call webservice from java side.
is't possible ? How can I do that ?
I suggest you to:
Develop a kind of proxy ldap webservice whose will do the bridge between flex app and your custom ldap authentication process
Use HttpService from flex to send parameter to the proxy ldap
Use proxy ldap to consume the checkUserCredetialFromLdap api with parameter get from flex
I have the php webservice code below, what I am suppose to do, so that I can call this web service in java.
I need to generate the wsdl first? Then generate the java web service stubs with the wsdl? How can I call this in java. And what tool I need to use. Thank you.
<?php include_once("../../lib/config.php"); ?>
<?php
if(!extension_loaded("soap")){
dl("php_soap.dll");
}
ini_set("soap.wsdl_cache_enabled","0");
$server = new SoapServer("membersearch.wsdl");
function doMyMemberSearch($membernumber){
$sqlMemberInfo = mysql_query("SELECT * FROM Member_Info WHERE Member_Number = '".$membernumber."'");
$rowMemberInfo = mysql_fetch_array($sqlMemberInfo);
$arr[] = array(
"anniversary" => $rowMemberInfo['Anniversary'],
"club" => $rowMemberInfo['Club'],
"level"=> $rowMemberInfo['Level'],
"delivery"=> $rowMemberInfo['Delivery'],
"firstname"=> $rowMemberInfo['First_Name'],
"lastname"=> $rowMemberInfo['Last_Name'],
"birthday"=> $rowMemberInfo['Birthday'],
"spousefirst"=> $rowMemberInfo['Spouse_First'],
"spouselast"=> $rowMemberInfo['Spouse_Last'],
"spousebirthday"=> $rowMemberInfo['Spouse_Birthday'],
"signuploc"=> $rowMemberInfo['Signup_Loc'],
"status"=> $rowMemberInfo['Status']
);
if (isset($rowMemberInfo['Anniversary'])) {
return $arr;
}else {
throw new SoapFault("Server","Unknown Member Number '$membernumber'.");
}
}
$server->AddFunction("doMyMemberSearch");
$server->handle();
?>
WSDL is implementation language agnostic. So it doesn't matter if it was written in PHP, C#, Java or any other language.
You need to get the .wsdl file for the service. Usually you can get that by pointing your browser at the service URL with the addition of a query string '?WSDL'.
Example:
http://www.example.com/theWebService?WSDL
Once you have that you can use Apache CXF, Apache Axis2, Spring WS or any other web services framework to generate java client stub code.
I am fairly new to Android programming and was wondering how I can get data from an SQL database in my Android app.
I currently have a PHP script that pulls the data I want from the SQL table but I'm not sure how to pull the data from the PHP script into my Java. How do I do this? I read something about SOAP. Is this the protocol I want to use?
Thanks
It depends. Where's the database, on the device, or on a server? If it's on the server, is the PHP code already a web app, or is it just a script?
In general, if the database is on the device, throw out the PHP and use JDBC to grab the data directly from Java. If the data is on the server, then turn the PHP script into a web app, and access that web app from Java. SOAP is certainly one protocol you can use for this, albeit a complex one that's often overkill. JSON or just plain text are many times better choices.
You can use the function below to get content from your PHP script
public static String get(String from) {
try {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(from);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) return EntityUtils.toString(resEntityGet);
} catch (Exception e) {
Log.e("", e.toString());
}
return null;
}
I got quercus up and running on GAE and when I process this code I get Error: Server Error
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
$user="user";
$pass="pass";
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME);
} catch (Zend_Gdata_App_AuthException $ae) {
exit("Error: ". $ae->getMessage() ."\nCredentials provided were email: [$user] and password [$pass].\n");
}
?>
The thing is GAE is blocking every curl request and I can't make the request to the Spreadsheets
You cannot use curl on App Engine. You need to use URLFetch.
Using code that was generated with wsimport, can the service endpoint be overridden without having to regenerate the code?
I have written a simple java webservice, following are the steps:
I compile the java class and generate a war file
Deploy the war file to my app server (tomcat)
Access the WSDL via the URL e.g. localhost:8080/service/helloservice?wsdl
use the URL with wsimport.bat to generate client classes for example: wsimport http://localhost:8080/service/helloservice?Wsdl
I use those classes in my client app to call the service
The problem is that is the service is deployed on an app server running on port other than 8080, the communication between client and service never happens. I am trying to know what is the best way to create stubs that does not have server and port hardcoded in the stub used by the client.
Your client can set the end-point in the service "port" at runtime via the BindingProvider interface.
Consider the JAX-WS client in this JAX-WS tutorial. Another way to write this code would be:
HelloService service = new HelloService();
Hello port = service.getHelloPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://foo:8086/HelloWhatever");
String response = port.sayHello(name);
Caveat: I haven't downloaded the tutorial code and tested this code against it.
I faced the same issue, and it was terrible coz once the code is moved to production it always looked for the hardcoded WSDL location i.e. Windows C:........etc
I have gone thru various post and pages to find the answer however all was failing then found myself a way by looking at the Service Class generated by JAX-WS imports.
I had to override the JAX-WS WSDL location implementation in my calling class like this.
URL baseUrl;
URL wsdlURL = null;
baseUrl = <your Services>.class.getResource(".");
try {
wsdlURL = new URL(baseUrl, "http://<your path>?wsdl");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
<your Services> yourServices = new <your Services(wsdlURL,new QName("your namespace", "<your service name>"));
System.out.println(Services.getWSDLDocumentLocation());
YourInterface YourInterfacePort = yourServices.getServicePort();
BindingProvider bindingProvider = (BindingProvider)YourInterfacePort;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
YourInterfacePort.methods();