Generate XSD for CXF webservice - java

I've a CXF web service Java classes, I use Eclipse 3.5. I generated the service WSDL file, and it has the <wsdl:types>, but the client that I work for is asking for a separate XSD file, how can I generate it in Eclipse?

If you are using the JavaEE Eclipse (or added all relevant modules to another Eclipse version), right click the class containing your service implementation -> Web Services -> Create Web Service.
Everything should be okay with the default values, just make sure that the first page has the right service implementation class and the page Apache CXF Web Service Java2WS Configuration has the checkboxes Generate WSDL and Generate sparate XSD checked.

Related

How to generate mock web service using WSDL in Java?

I have WSDL file and for local testing I need to generate mock web service.
Please do not recommend SoapUI.
Can anybody please help how to generate mock web service in Java using WSDL?
One option is to create a Web Services project using an IDE.
This will allow you to create a mock service and also implement your business logic.
As an example, using Eclipse:
Before starting, ensure that:
Eclipse has a server installed (Apache Tomcat)
Your WSDL file have a .wsdl extension (if not, rename as .wsdl)
Now, start Eclipse:
Create a new java "Dynamic Web Project"
Create a folder WebContent\wsdl and copy your WSDL file
Right-click on project > select new "Web Service"
Select:
Web Service type: "Top down Java bean Web Service"
Service definition: browser your WSDL file
Select "Start Service"
Select "Java Proxy / Start Client"
Select both option at the bottom of the form (publish/monitor)
Click next to complete process
At the end, your server should be started and WS deployed - check that your WSDL is available.
Now, you can:
call your WS using Eclipse Web Services Explorer see explorer
implement your WS mockup business logic see method implementation
or use a working java client to call your WS programmatically
Hope this help.
Try using Wiremock. However you will be needing to create and structure json/xml files according to your need. This will give you an better idea. Using WireMock with SOAP Web Services in Java

Implement WS-Policy in a JAX-WS Web Service

I am developing a SOAP Web Service in Java with JAX-WS. I am using Eclipse Juno and Weblogic 12c. The web service is being developed in an EJB Project. I am using a top-down approach: from a WSDL that I have, I use JDK's wsimport tool (via command-line) to generate all the Java classes, I import them to the project and then I provide an implementation for the SEI.
The WSDL has a specification of a WS-Policy with a wsp:Policy tag, but the code generated from wsimport has no kind of information/annotation for this. As such, I suppose I've to write it myself.
From the search that I've made, it seems that either I've to use some Weblogic annotation or use some CXF/Axis/Metro feature. Is this true? Can't I use anything from JAX-WS? I read that CXF/Axis/Metro are all implementations of JAX-WS, but I don't have any idea if I'm using one of them, I think I am using JAX-WS reference implementation, but I don't know if this is true.
I also would like to keep an implementation independent from any application server (Weblogic, in this scenario). If I have to use CXF/Axis/Metro, how can I add their features to my EJB Project?
Firstly you can use Metro, Axis or any other third party library in your project to generate your client code. However if you want not to use third party libraries, you can generate the needed wsse headers on your own.
The followinf link described how to generate your desired headers in order to call wsse secured web services, you should just implement your own SOAPHandler :
http://www.javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-web-service-client/

How to get large data from webservice partial?

I've application in JSF 2.0 (on Glassfish 3). Now I have to write a .NET WCF webservice that will be connected to database and will be used by this JSF app to fill DataTables.
DataTable will have pagination, but how to get (form web-service) only that rows, which will be displayed in single page. And will allow action such as sorting, deleting, editing rows etc...
Is there any bulit-in mechanism/library to supported that? I mean in WCF or JSF2 ?
Thanks for help,
You should have a WSDL file (ask the web service owner/maintainer/admin for it). A WSDL file specifies by XML how the webservice is definied. A bit sane IDE like Eclipse can autogenerate a complete Java client application for it via File > New > Other... > Web Services > Web Service Client. You should then end up with an autogenerated web service client project which you just have to add as Deployment Assembly of your JSF project in order to access/use the autogenerated client classes.
You can find here a concrete tutorial which shows how to generate and use it in combination with a plain Java application project (instead of a JSF project).
As to partially retrieving the data, that depends on whether the web service supports that as per the WSDL. You can always issue an enhancement request at the maintainer of the web service so that they will add this to the web service (and then you should get an updated version of the WSDL and then re-generate the Java client application based on it).

Unable to publish wsdl file

Can any one tell me how to public the wsdl file ie., that web service is created in java using eclipse.I am self learner to java/eclipse and web service too,so can any one please make me clear with steps.
Thanks for your time!...
Apache Axis has some cool tools that I frequently use - to generate a wsdl, use java2wsdl. It has a command line version, but also a Maven plugin (which I highly recommend) that will re-generate the wsdl for you automatically each time you package your web service.
What's more, the axis stuff also provides auto-generation of client stubs by which you can use your web service in consumer apps or services. Alternatively, JAX-WS tools can be used for this as well. In either case I would recommend automating the process with Maven.
If you package your wsdl with your app in this way (rather than letting a server do this for you automatically), you can be certain that your contract will look the same on any platform.

Eclipse WSDL generator (from java class)?

I want to generate WSDL compliant with Java classes. At this phase I don't want to put it online, just have the wsdl (in order to discuss it with someone else) and validate the generated file.
I'm using Eclipse, so I would prefer any solution that's already integrated with it.
From eclipse in the java perspective:
Right click on the Java class you want to use as your service implementation
Select Web Services -> Create Web Service
Web service type should be "Botton up Java bean Web Service"
This will generate a WSDL file for you.
Also you can publish the service at localhost with any server (Tomcat, for instance) and then with your browser in the address bar write
http://localhost:<server_port>/path/to/your/service?wsdl
If the service is correctly configured, you should see the generated wsdl. Then you can copy/paste in any text editor and save it as myService.wsdl.
Hope that helps

Categories