How to obtain reference to Jersey service from within Jetty - web-services

i add a webservice 'MyService' to my context:
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
ServletHolder myServlet = context.addServlet( org.glassfish.jersey.servlet.ServletContainer.class, "/service/*");
jerseyTaskServlet.setInitParameter("jersey.config.server.provider.classnames",
MyService.class.getCanonicalName());
So now i need to call a method (it's not a method from the web api, just a normal java method ) from MyService, this method is not static. I need a reference to an instance of MyService.
How can i acces the instance of MyService in this context?

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?

ZF2 + Doctrine 2 + SOAP

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!

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.

SoapHeader Value missing in ASP.NET 3.5 Web Service

I have created a custom SOAPHeader and Service with methods. While I was trying to consume the service, I was able to create the SOAPHeader and assign its property. But the proxy(SOAPClient) is missing the HeaderValue property.
My web method is expecting this Header as a parameter instead of property of the proxy.
Client Proxy:
MyServiceSoapClient client = new MyServiceSoapClient();
AuthHeader header = new AuthHeader();
header.UserName = "test";
client.MyMethod(header, value);
I want to set the header in "client" not send as parameter.
In your web service client, be sure to add a Web Reference and not a Service Reference (WCF service.) This will remove the soap header parameter from each call and add the SoapHeaderValue property you're looking for.