ZF2 + Doctrine 2 + SOAP - web-services

I have 2 applications, Intranet and Extranet.
The Extranet app does not communicate directly with database, only with web service. The Intranet app is normal with database.
I need use SOAP for communicate with my database, so I have
View -> Controller -> Service -> Entity.
For communicate with service I am using:
[Controller]
$client = new Client("my_soap_address");
$user = $client->test();
[Service]
public function test()
{
$res = $this->em->getRepository("my_entity")->fetchPairs();
return $res;
}
Without SOAP, works perfectly!
With SOAP, returns this error:
Call to a member function getRepository() on a non-object
If my service returns a string, integer or boolean as:
[Service]
public function test()
{
return "is OK";
}
My SOAP works normally.
The problem is any method as getRepository(), getReference(), etc.. But I need these methods for get or put informations from my database.
Please, can anybody help with this problem?
Thanks a lot!
ps.: I have a controller with handleWSDL and handleSOAP between Controler and service.

I solved my problem!
I need send the EntityManager with Soap for the service works.
Let's go:
In my SoapController:
use Path\of\my\service as MyService;
public function handleSOAP($class, $url) {
$soap = new Server($url."?wsdl");
$soap->setClass($class);
$soap->setObject(new MyService($this->getServiceLocator()->get('Doctrine\ORM\EntityManager')));
$soap->handle();
}
For works, I need instance inside setObject Method, my service as I instanced on my Module.php file inside of getServiceConfig().
So, now is ok!
Thanks!

Related

zf2 dervied controller - method seen as service

i've a custom base controller ,that extend AbstractRestfulController, from which extend other controller of mine web service.
In base controller i've method like this
public function p($text)
{
$oContainer = new Container('locale');
$translate = $this->_oViewHelperManager->get('translate');
return $translate($text, null, $oContainer->szLocale);
}
when i work in local all work fine
my configuration is
ubuntu 14.10
php 5.5.12 as apache module
when i put it in remote server i've got
remote configuration is
php 5.5.9 as fastcgi
Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for p
p as seen like service and not like method
why?

Grails: Create my datasource from a webservice

I've read a lot about switching between multiple datasource on runtime, but as far as I understand they're already defined datasources. I'm not quite sure on how can I just asign the datasources properties on runtime from a webservice call.
I don't need to switch between datasources, just need to create only one datasource with conection data coming from a webservice.
Is there a way to retrieve these parameters from the webservice and create the datasource from that?
The policy here is to retrieve the datasource parameters from a webservice for all the projects, that way the connection data is not inside a file nor into the code, and is only manipulated by DBAs from a global security aplication.
I tried to call the web service in the same datasource file, but it didn't work.
Info:
Web service is a Soap Web service
Grails: 1.3.9
Regards.
I think that you can create a BeanPostProcessor that take care of calling your webservice and changing the settings of your dataSource.
Probably you will need to delay the session factory creation, making sure Grails won't try to use your dataSource before you have all setted up correctly.
The BeanPostProcessor will looks like:
class WebserviceDataSourceBeanPostProcessor implements BeanPostProcessor {
Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean
}
Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof DataSource){
def info = //call webservice here...
bean.username = info.username
bean.password = info.password
bean.url = info.url
//checkout more setters in: http://commons.apache.org/proper/commons-dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html
}
return bean
}
}
And make sure you declared this Spring Bean in resources.groovy
beans = {
webserviceDataSourceBeanPostProcessor(WebserviceDataSourceBeanPostProcessor)
}
If you will have more than one project with this same config comming from a webservice you may think in the possibility of a plugin for this, reusing your code.

Create Web Service from struts2 Web Application

First, I'm new to Web Services. I have a didactical task at university about developing web application and web service for something like managing distribuited drug stores.
I've developed a working Web Application using struts2 framework, but now I'd like to extend it to a Web Service. I found that I could implement a class (named for example WSManager) which is a wrapper of the various Web App Controllers.
It would have to make calls to static methods of those Controllers. Web Application is designed to provide a Controller for each use case.
for example a Controller is like this:
public class AdminLocaleController extends AbstractController {
private static final long serialVersionUID = -6266455088438602574L;
private static Logger logger = Logger.getLogger(AdminLocaleController.class);
private List<Prodotto> prodotti;
#Override
public String execute() {
prodotti = initializeAdminLocaleView();
return "success";
}
public List<Prodotto> getProdotti() {
return prodotti;
}
public void setProdotti(List<Prodotto> prodotti) {
this.prodotti = prodotti;
}
public static List<Prodotto> initializeAdminLocaleView() {
logger.info("Recupero lista di prodotti da ordinare");
DBController dbController = new DBControllerImpl();
return dbController.getProdottiDaOrdinare();
}
}
and the WSManager class makes a call to the initializeAdminLocaleView(), just like this:
/* AdminLocaleController */
public List<Prodotto> initializeAdminLocaleView(){
return AdminLocaleController.initializeAdminLocaleView();
}
I would create a Web Service in Eclipse providing that service class.
If I'm doing something wrong I ask you the proper way to extend the web application to a web service.
Otherwise, my matter is if I have to (and how to) manage parameters and attributes between Views (jsp) and Controllers.
Finally I have some Controllers (each of these implement SessionAware) which process data and store returned object in Session (for example a LoginController which saves a User bean in request session). Deeper, my question is how I should manage Web App's session stored attributes in case of a Web Service. If I have method calls in WSManager which passes a User bean as parameters, how could I obtain it from a session. Or simply, do I have necessity of obtaining something from a session from a Web Service perspective?
I'm sure I've written a confusionary question, but confusionary is my state of mind at this point too.

JSP for adminstrating JBoss web service

For example, I write a simple code, pack it as *.jar and deploy WebService in JBoss, evrything works..
#WebService
#Stateless
public class TestService{
static int takeMePlz = 1;
#WebMethod
public String GetAnsw(String str){
++takeMePlz;
return Integer.toString(takeMePlz);
}
}
So, when i call this web service, takeMePlz static varible increases.
My Serivce has location http://localhost:8080/test_service/TestService,
Now i Want JSP with location: http://localhost:8080/test_service/Administrating,
that has access to my web service, and this JSP should show me takeMePlz static varible in web browser
Create client for webservice
invoke webservice from servlet
catch the result as attribute of request and forward it to jsp and on jsp use JSTL to show the data
In addition, you need to make the takeMePlz field public so it is accessible.
Moreover, you should synchronize access to the field, or make it a java.util.concurrent.atomic.AtomicInteger.
It will still be a bit rough though. Once you have it working, you might want to consider reimplementing using JMX.

Sending Cookies over WCF using the ChannelFactory

I use an IOC container which provides me with IService.
In the case where IService is a WCF service it is provided by a channel factory
When IService lives on the same machine it is able to access the same cookies and so no problem however once a WCF Service is called it needs to be sent those cookies.
I've spent a lot of time trying to find a way to send cookies using a channel factory and the only way I could find that works is the following
var cookie = _authenticationClient.GetHttpCookie();
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers.Add(HttpRequestHeader.Cookie, cookie.Name + "=" + cookie.Value);
using(var scope = new OperationContextScope((IClientChannel)_service))
{
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
var result = _service.Add(details);
if (result.Result == RPGResult.Success)
{
return RedirectToAction("Index", "Home", result.Id);
}
}
The problem with me using that method is that I have to know that I'm calling a WCF Service which is not always the case. I've tried writing a wrapper for the ChannelFactory that opens a new operationcontextscope when it creates a new service and various other solutions but nothing has worked.
Anyone have any experience with sending cookies over WCF Services?
I found a solution involving using SilverLight, unfortunately I'm not using silverlight, the solution is here: http://greenicicleblog.com/2009/10/27/using-the-silverlight-httpclient-in-wcf-and-still-passing-cookies/
Unfortunately standard .net doesn't contain the IHttpCookieContainerManager interface
Ideally I would be able to use something similar,i.e. I would be able to tell the channelfactory to pass a cookie whenever it opened.
If anyone has a better way to pass a token that is used for authentication that would be appreciated too.
I have a solution where I create a proxy class of IService and then every time a method on IService is called it invokes the proxy created by the channel factory but the call itself is wrapped in an operationcontextscope just like the one I have in my question.
I used the proxy factory from this link http://www.codeproject.com/KB/cs/dynamicproxy.aspx