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.
Related
One of my system need to invoke SOAP based webservices. As of now, for every new webservices, I generate Java stubs from the provided WSDL file and redeploy the web application with new webservice consumer code. Is there a good approach to dynamically create a webservice client that can invoke the methods from the provided WSDL files? All I am expecting is
put the WSDL file in the location that can be accessed by the web application
invoke the Servlet with a keyword having the wsdl file name, and other params required for the webservice method.
Can the Apache CXF help in this? I read in a post, generating wsdl2java in the runtime and loading the classes, over a time, can exhaust the pemgen memory space.
You should look here : http://cxf.apache.org/docs/dynamic-clients.html
This is exactly that.
here an example:
ClientImpl client = (ClientImpl)doc.getClientFromWsdl("http://myurl:8080/DataCentersWS?wsdl");
String operationName = "getVirtualisationManagerUuid";
BindingOperationInfo op = doc.getOperation(client, operationName);
List<MessagePartInfo> messagesParts = op.getInput().getMessageParts();
Object[] params = new Object[messagesParts.size()];
/* feed yours params here (this feeding was heavy in my code */
Object[] res = client.invoke(op, params);
There is many other examples in the source distribution of cxf.
I have a WCF service deployed at a certain server.
I need to call it through the JAVA application, when i am checking the parameter for this OperationContract is being passed correctly from java side but when i am logging the parameter value in WCF service, it seems not to be received here.
We are using 'basicHttpBinding' only and the attributes set for the Service and OperationContracts are as follows :-
[ServiceContract]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Encoded)]
public interface IMyService
{
[WebMethod]
[OperationContract(Action = #"http://tempuri.org/GetString")]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetString(string strParameters);
}
Can any body check if this is correct or may suggest with all the steps so that a WCF can be accessed properly through JAVA application ?
For REST ful WCF, try using WEbHTTPBinding rather basic HTTP. REST WCF support WebHTTPBindings
WebInvoke attribute is not used for BasicHttpBinding (It is for webhttpBinding). You can take that out. One way to diagnose is open config in wcf config editor (SvcConfigEditor.exe). Enable tracing (search for enabling wcf tracing), make a request to service which will generate trace file. Check the log in Trace viewer (svtraceviewer.exe). You will find place where it is failing.
I am trying to create a java application to read the information from ARIN using an IP Address. I see ARIN is using RESTful Web Services to get the IP information but I am not sure what I need to do to start. Some people are talking about RESTLET, other people about JAX-RS,etc. Can you please help me to take me in the right direction? Thanks!
Restlet also has a client API to interact with a remote RESTful application. See the classes Client, ClientResource for more details. For this, you need to have following jar files from Restlet distribution:
org.restlet: main Restlet jar
org.restlet.ext.xml: Restlet support of XML
org.restlet.ext.json: Restlet support of JSON. In this case, the JSON jar present in libraries folder is also required.
If I use the documentation located at this address https://www.arin.net/resources/whoisrws/whois_api.html#whoisrws. Here is a simple Restlet code you can use:
ClientResource cr = new ClientResource("http://whois.arin.net/rest/poc/KOSTE-ARIN");
Representation repr = cr.get();
// Display the XML content
System.out.println(repr.getText());
or
ClientResource cr = new ClientResource("http://whois.arin.net/rest/poc/KOSTE-ARIN.txt");
Representation repr = cr.get();
// Display the text content
System.out.println(repr.getText());
Restlet also provides some support at XML level. So you can have access to hints contained in the XML in a simple way, as described below:
ClientResource cr = new ClientResource("http://whois.arin.net/rest/poc/KOSTE-ARIN");
Representation repr = cr.get();
DomRepresentation dRepr = new DomRepresentation(repr);
Node firstNameNode = dRepr.getNode("//firstName");
Node lastNameNode = dRepr.getNode("//lastName");
System.out.println(firstNameNode.getTextContent()+" "+lastNameNode.getTextContent());
Note that you can finally handle content negotiation (conneg) since it seems supported by your REST service:
ClientResource cr = new ClientResource("http://whois.arin.net/rest/poc/KOSTE-ARIN");
Representation repr = cr.get(MediaType.APPLICATION_JSON);
In this case, your representation object contains JSON formatted data. In the same way than the DomRepresentation, there is a JsonRepresentation to inspect this representation content.
Hope it helps you.
Thierry
The problem is that you don't seem to understand very well what REST is (sorry if I'm mistaken!). Restlet and JAX-RS are both server-side related.
You probably need something like jersey-client. This is a library which helps to interact with RESTful webservices.
You could also usa plain Java libraries to make HTTP calls to the webservice. REST is tightly bound to its implementation protocol. This means that if the webservice is implemented in HTTP (most likely is) you don't need anything fancy to interact with it. Just HTTP.
I strongly encourage you to learn more about REST and HTTP itself.
1) Hello I am trying to use the admin services to create an Proxy inside the ESB.
So I have exposed the admin services (Hidden=false)
I have imported the WSDl in my Java project https://localhost:8243/services/ProxyServiceAdmin?wsdl
But I cannot workout how to call the method addProxy am I using the wrong admin service? Please help with an example of consuming this method.
ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //wrong
2) I have a proxy defined as a one-line String, like
String xmlproxy="<?xml version='1.0' encoding='UTF-8'?><proxy xmlns='http://ws.apache.org/ns/synapse' name='MyProxy1' transports='https' startOnLoad='true' trace='disable'> <target inSequence='sequence1'>...."
Is it possible to add this Proxy by calling some method of the admin services?
thanks a lot for your attention!
EDIT I had a look at the WSDL "ProxyServiceAdmin?wsdl"
it says <wsdl:operation name="addProxy"><http:operation location="addProxy"/><wsdl:input><mime:content type="text/xml" part="parameters"/></wsdl:input><wsdl:output><mime:content type="text/xml" part="parameters"/></wsdl:output>
so it is there, but why I cannot call it? Why my code does not work as a normal Web Service would? Really, please help. I don't get what i am doing wrong...
ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //not recognized as an operation of ProxyServiceAdmin even if it is in the wsdl
You simply have to use "org.wso2.carbon.proxyadmin.stub.ProxyServiceAdminStub" to ad proxy by admin services
Please have a look at following code and comments inline.
String endPoint = *<your backend service url>* +"ProxyServiceAdmin";
proxyServiceAdminStub = new ProxyServiceAdminStub(endPoint);
You have to authenticate your service stub before make any use of it
CarbonUtils.setBasicAccessSecurityHeaders(userName, password,
proxyServiceAdminStub._getServiceClient());
Need to generate ProxyData object of your proxy as synaps xml
String[] transport = {"http", "https"};
ProxyData data = new ProxyData();
data.setName(proxyName);
data.setWsdlURI(*<url to your WSDL>*);
data.setTransports(transport);
data.setStartOnLoad(true);
data.setEndpointXML("<endpoint xmlns=\"http://ws.apache.org/ns/synapse\"><address uri=\"" + serviceEndPoint + "\" /></endpoint>");
data.setEnableSecurity(true);
proxyServiceAdminStub.addProxy(data);
Thank You,
Dharshana
please find the sample to create a proxy using admin service here. I added Darshana's code to a complete example.
This is the JSP page is used for creating a pass through proxy. You can fill your proxy data similar to that. if you browse the other jsps you can find similar logics used for different proxy templates. Here you can find the complete module, both UI and Service code.
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.