Page 1 of 2

How to use WebService with php

PostPosted:Sun Jan 18, 2009 3:55 pm
by neil
Hi All :) ,

I want to use Webservices provided by OpenKM. But I am not understanding from where to start. I am using nusoap php for using Web Service.Can you give any examlpe in php or java for using webservices for searching file by name and by contents it will be help full. so that I can start using OpenKm webservice.

I have already gone through one post on \"How to use webservices? :dry: \" but that is using perl and xpath. I dnt know nothing about both of thses technology.

And one more thing can you also tell me if I want to make some changes in web services provided by you.Please do get back to me.

Thanks and Regards

Neil M

Re:How to use WebService with php

PostPosted:Sun Jan 18, 2009 10:13 pm
by pavila
This sample code make an XPath search in the repository. It runs on PHP5, and no external libraries (like nuSoap) are needed:
Code: Select all
<html>
<head>
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
</head>
<body>
<?php
  $OKMAuth = new SoapClient(\'http://localhost:8080/OpenKM/OKMAuth?wsdl\');
  $OKMSearch = new SoapClient(\'http://localhost:8080/OpenKM/OKMSearch?wsdl\');
      
  $token = $OKMAuth->login(\'admin\', \'admin\');
  echo \"Token: \".$token.\"<br>\\n\";
  $queryResultArray = $OKMSearch->findByStatement($token, \'/jcr:root/okm:rootelement(*,okm:document)\', \'xpath\');
  $arrayOfQueryResult = $queryResultArray->value;
  
  echo \"<ul>\\n\";
  foreach ($arrayOfQueryResult as $queryResult) {
  	echo \"<li>\".$queryResult->document->path.\"</li>\";
  }
  echo \"</ul>\\n\";
  
  $OKMAuth->logout($token);
?>
</body>
</html>

Re:How to use WebService with php

PostPosted:Mon Jan 19, 2009 5:17 am
by neil
Hi pavila,


I have gone through code given by you.But I am not getting some things from code?
what does this function do
\"$OKMSearch->findByStatement($token, \'/jcr:root/okm:rootelement(*,okm:document)\', \'xpath\');\"

can you please explain this function in brief?
for eg what is \"/jcr:root/okm:rootelement(*,okm:document)\"?
what is jcr:root and where i can find it and is okm:rootelement(*,okm:document) is XPath function???

Please explain this cause I am not able to understand this. :(

Regards
Neil m

Re:How to use WebService with php

PostPosted:Mon Jan 19, 2009 8:38 am
by pavila
This is an XPath query that get all nodes of type \"okm:documen\" from the repository. You can read more on this at:

* http://en.wikipedia.org/wiki/Content_re ... I_for_Java
* http://jcp.org/aboutJava/communityproce ... index.html

Also you can see the WS API at:

* Webservices Specification

Re:How to use WebService with php

PostPosted:Mon Jan 19, 2009 1:09 pm
by neil
Hi Pavila,


I tried to create folder using Web Service. But It is giving me error while I try to create folder.
I think I am making some silly mistake in my coding but not able to find it out. I am copy pasting my code here can you just check it and let me know what is bug in this.
Code: Select all
<?php

$OKMAuth = new SoapClient(\'http://localhost:8080/OpenKM/OKMAuth?wsdl\'); 
	
$OKMFolder = new SoapClient(\'http://localhost:8080/OpenKM/OKMFolder?wsdl\');
	
$token = $OKMAuth->login(\'admin\', \'admin\');
$queryResultArray = $OKMFolder->create($token,\'neil_test\');
?>
Please let me know what is the issue with this as soon as possible.is this the issue with path given for the file?

Regards Neil M

Re:How to use WebService with php

PostPosted:Mon Jan 19, 2009 9:22 pm
by jllort
Correct the path, it must be something like \'/okm:root/neil_test\'.

Re:How to use WebService with php

PostPosted:Tue Jan 20, 2009 7:29 pm
by pavila
Usually post the error string can help. You can also see the JBoss log because it can give you more info.

Re:How to use WebService with php

PostPosted:Thu Jan 22, 2009 1:30 pm
by neil
Hi pavila,
Code: Select all
\"java.lang.NullPointerException
        at es.git.openkm.util.FileUtils.getParent(FileUtils.java:67)
        at es.git.openkm.module.direct.DirectFolderModule.create(DirectFolderMod
ule.java:168)
        at es.git.openkm.ws.endpoint.OKMFolder.create(OKMFolder.java:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.wsf.container.jboss42.DefaultInvocationHandler.invoke(Defau
ltInvocationHandler.java:102)
        at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpoin
tInvoker.java:220)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHan
dlerImpl.java:408)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHand
lerImpl.java:272)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl
.java:189)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(Request
HandlerImpl.java:122)
        at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java
:84)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:175)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:179)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:432)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
onnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:262)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
6)
        at java.lang.Thread.run(Thread.java:595)
18:54:46,656 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
java.lang.NullPointerException
        at es.git.openkm.util.FileUtils.getParent(FileUtils.java:67)
        at es.git.openkm.module.direct.DirectFolderModule.create(DirectFolderMod
ule.java:168)
        at es.git.openkm.ws.endpoint.OKMFolder.create(OKMFolder.java:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.wsf.container.jboss42.DefaultInvocationHandler.invoke(Defau
ltInvocationHandler.java:102)
        at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpoin
tInvoker.java:220)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHan
dlerImpl.java:408)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHand
lerImpl.java:272)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl
.java:189)
        at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(Request
HandlerImpl.java:122)
        at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java
:84)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:175)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:179)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:432)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
onnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:262)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
6)
        at java.lang.Thread.run(Thread.java:595)\"

This is the error that iam getting while i am trying to create file using web services and code in php is
Code: Select all
if($_SESSION[\'ws_token\'] == \'\')
	{
		$OKMAuth = new SoapClient(\'http://localhost:8080/OpenKM/OKMAuth?wsdl\'); 
	
		$OKMSearch = new SoapClient(\'http://localhost:8080/OpenKM/OKMSearch?wsdl\');
		
		$OKMFolder = new SoapClient(\'http://localhost:8080/OpenKM/OKMFolder?wsdl\');
		$token = $OKMAuth->login(\'admin\', \'admin\');
		$_SESSION[\'ws_token\'] = $token;
	}
	else
	{
		$token = $_SESSION[\'ws_token\'];
	}
	
	echo \"Token: \".$token.\"<br>\\n\";
	//$queryResultArray = $OKMSearch->findByStatement($token, \'/jcr:root/okm:rootelement(*,/okm:root/)\',\'xpath\'); 	 
	//$queryResultArray = $OKMSearch->findByStatement($token, \'okm:rootelement(*,/okm:root/)\',\'xpath\'); 	 
	$folder = array(\"path\"=>\'neil_test\');
	$queryResultArray = $OKMFolder->create($token,\'/okm:root/neil_test\');
	print_r($queryResultArray);
	$OKMAuth->logout($token);
can you tell me wht is the reason behind this?

Re:How to use WebService with php

PostPosted:Thu Jan 22, 2009 2:26 pm
by pavila
Look at this code:
Code: Select all
<?php
  $OKMAuth = new SoapClient(\"http://localhost:8080/OpenKM/OKMAuth?wsdl\");
  $OKMFolder = new SoapClient(\"http://localhost:8080/OpenKM/OKMFolder?wsdl\");

  // This will give you some tips
  print_r($OKMFolder->__getFunctions());
  print_r($OKMFolder->__getTypes());

  // Login
  $token = $OKMAuth->login(\'admin\', \'admin\');
  
  // Create folder
  $fld = array(\'path\' => \'/okm:root/gandalf\', \'author\' => null, \'created\' => null,
  		\'hasChilds\' => false, \'permissions\' => 0, \'subscribed\' => false, \'uuid\' => null);
  $OKMFolder->create($token,  $fld);
  
  // Logout
  $OKMAuth->logout($token);
?>

Re:How to use WebService with php

PostPosted:Fri Jan 23, 2009 4:05 am
by neil
Hi pavia,

Thanks for code :). It\'s now working perfectly.Can you tell me how can I manage user permission for files? Can admin assign permissions to user and if possible can you tell me how to assign that?

Regards
Neil M

Re:How to use WebService with php

PostPosted:Mon Jan 26, 2009 8:29 am
by pavila
Code: Select all
<?php
  $OKMAuth = new SoapClient(\"http://loclahost/OpenKM/OKMAuth?wsdl\");
  $token = $OKMAuth->login(\'admin\', \'admin\');
  $OKMAuth->revokeRole($token, \'/okm:root\', \'UserRol\', 2, false);
  $OKMAuth->grantUser($token, \'/okm:root/privado\', \'demo\', 1, false);
  $OKMAuth->grantRole($token, \'/okm:root/publico\', \'UserRol\', 1, false);
  $OKMAuth->logout($token);
?>
These are the permissions:
  • READ: 1
  • WRITE: 2

Re: How to use WebService with php

PostPosted:Wed Mar 17, 2010 6:25 am
by neshdenial
I have some experience with this as well. I've also dealt with using a PHP client to consume a webservice using through a WSDL using a hashed password option.

Let me know if you still need help...

Re: How to use WebService with php

PostPosted:Thu Mar 18, 2010 9:20 am
by pavila
What does means "using a hashed password option"?

Re: How to use WebService with php

PostPosted:Thu Mar 18, 2010 10:07 am
by neshdenial
I am trying to create PHP client which consume the ASP.NET webservice.I have one web method that will returns the array of bytes as value.
My wsdl mapping this data type as Base64Binary value only.But I could not see the Binary string or something blah..blah string to decode them and utilise them in PHP.
I am naive to PHP.What should I do now to get encoded binary string in order to use in my PHP client ?
<?php
require_once('lib/nusoap.php');
$client = new soapclient('http://localhost/website1/Service.asmx?WSDL','wsdl');
echo $client->call('GenerateReport');
?>
This will shows only the word Array.

Re: How to use WebService with php

PostPosted:Fri Mar 19, 2010 11:12 am
by pavila
Perhaps you should look for a PHP forum.