Let's i have simply #Stateless session bean. (EJB 3.0)
#Stateless
public class SomeBeanWS implements ISomeBeanWS {
// ...
}
And I have many WebServices (that are beans also) that have already deployed on the app server.
I have WSDLs of this Services.
I can generate Interfaces if this WebServices in my project using Maven.
Can I inject this Webservieces (beans) to my SomeBeanWS?
May you're using NetBeans, it provides a "generate WebService from WSDL" tool.
It helped me accessing external WS from within my ManagedBean (by using #WebServiceRef annotation there). Only injecting the WS through a Session Bean doesn't work (see here).
Edit says: I've found a solution, follow the link ;)
Related
I'm working on a project with JAX-WS.
When I annotate my endpoint class with #WebService the WSDL is marked in console like
.../<context-root>/XXXService?wsdl
When I add #Stateless on those endpoints the WSDL is not marked in console and the actual address is
.../XXXService/XXXEndpoint?wsdl
Is this normal or expected?
Update
For further readers.
I couldn't find any resolution. I decided not to use mixed #Stateless+#WebService. I split those #EJBs and #WebServices for clear module separation.
What youre experiencing is expected behaviour. It's a different matter if the service s not functional. When an EJB 3.x stateless bean is deployed as a WS, it's naming defaults to what you see there,
Servername/SIBnameService/SIBName.
The reason for this is obvious: EJBs don't operate within the context of a web application and so cannot be addressed as such. You can customise the default name using the serviceName attribute on the #WebService annotation
Look at this from apache
This question is similar to Java EE declarative security, acquiring reference to a secured bean from application client but is more specific.
I can unit test my local beans with the Glassfish embedded container. For the remote beans I have written application clients. This was a viable solution until security was applied at the remote beans. Now I encountered the problem of authenticating an application client towards Glassfish 3.1.1.
The phenomenon:
Testing the remote bean without security with an application client is all right.
The approach to use security with the application of ProgrammaticLogin does not work and I am not sure it is the correct way to solve the issue in unit tests. (See the attached link at the beginning.)
Question:
How do you think unit testing with security with remote beans should be done?
Where does one need to place the glassfish-ejb-jar.xml? (Maybe this is erronous in my case and this is the reason that the ProgrammaticLogin does not work.)
I continued to search for more information on the internet and I encountered the following blog: http://www-02.imixs.com/roller/ralphsjavablog/entry/junit_and_glassfish_3_1.
It answers how to test EJB 3.1 on Glassfish 3.1.1 without any third party tool. It is a little tricky.
The security settings I have not yet tried but there is also an example with regard to this.
I know there are a few web service plug-ins for Grails, some of them look like they aren't maintained. I have a jar with all the stubs generated from a wsdl and now I need to start integrating. Which plugin would serve best for this? Also, the web service uses SOAP, not REST.
I know your question asked about a plugin for consuming, but I've never used one of the Grails-WS plugins, so I can't comment there. Instead, if your stubs are compatible with JAXB marshalling you can use the Spring Web Services project. You'll just have to add a dependency in BuildConfig.groovy to import the appropriate jars.
http://static.springsource.org/spring-ws/sites/2.0/reference/html/client.html
So you just define some JAXB marshaller/unmarshaller beans and web service handlers. You can get as detailed as you want with this from the documentation above and define timeouts and security if you specify your own connection handler or interceptors.
myJaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) {
classesToBeBound = ['my.class.Class1','my.class.Class2']
}
myWebServiceMessageFactory(org.springframework.ws.soap.saaj.SaajSoapMessageFactory)
myWebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate, ref('myWebServiceMessageFactory')) {
marshaller = ref('myJaxb2Marshaller')
unmarshaller = ref('myJaxb2Marshaller')
}
At that point you can use Grail's dependency injection to use the WebServiceTemplate in your Grails code:
class myService {
def myWebServiceTemplate
void myMethod {
...
Class1 myRequestObject = new Class1(data:myData)
Class2 myResponseObject = myWebServiceTemplate.marshalSendAndReceive(mySoapEndpoint, myRequestObject)
...
}
}
I would recommend using Spring's way.
You're developing in grails after all, so maybie you don't need a plugin.
Read Spring docs on Remoting and webservices, chapter 19.5.2 "Accessing web services using JAX-RPC".
No need for any of your jar's stubs. Spring will generate everything for you...
P.S. : I assume you know how to declare spring beans in grails...
I'm building a RESTful web service using Jersey that relies on MongoDB for persistence.
The web service itself connects to the default database, but for the unit tests, I would like to use a separate test database. I would populate this test database in setUp, run my tests, and then destroy it in tearDown.
Normally, I would use dependency injection here to supply the data source to an entity manager that the service would use, but in this case the web service is running independent of the unit tests. I'm using the Jersey Test Framework, which starts up a Grizzly container to provide the web service interface, and provides a web service client to the unit testing class.
What is the best way to inject a dependency from my unit test class into the server instance (which Jersey Test Framework sets up in a Grizzly container)?
After digging through the Jersey Test Framework source, I've discovered an elegant way to inject dependencies into my RESTful resource classes.
In my test class (which extends JerseyTest), I've added only an implementation for the configure() method:
public AppDescriptor configure() {
return new WebAppDescriptor.Builder()
.contextListenerClass(ContextLoaderListener.class)
.contextParam("contextConfigLocation", "classpath:applicationContext.xml")
.initParam("com.sun.jersey.config.property.packages", "[resource package]")
.build();
}
This effectively provides a custom built WebAppDescriptor instead of relying on Jersey Test's Grizzly Web container to build one.
This will use the "applicationContext.xml" file on the classpath, which can be configured differently for running JUnit tests. Effectively, I have two different applicationContext.xml files: one for my JUnit tests, and the other for production code.
The test's applicationContext.xml will configure the data access dependency object differently.
I modified a WebService to include a public property and a public class, rebuild, updated the service in my client app. Neither are accessible by the client app for some reason. When I launch the test page, I can see them there; but when I use them in code, building breaks. It seems like the WebService is ignoring my changes or not regenerating.
Thanks for help!!
Web-services only support calling methods, not properties.
You'll have to create GetPropertyName and SetPropertyName methods to wrap up your property.