I made a simple webservice with JAXWS, the server contains my beans annotated with validation contraints and web methods which are inserting or updating beans in database.
I create my beans with forms on the client-side and then call the web methods to save changes.
For the moment I validate my bean with hibernate validator, on the server-side, inside web methods.
I would like to make dynamic form validation on the client side. But with the wsdl generation, my beans have no more annotations, so nothing is validated.
What should I do ?
You can enable the client side schema validation as mentioned here
Related
I already know how to write JUnit test cases (can also use Mockito). Thanks for the simple tutorials in the web for that. The only problem is that I can't find any examples on implementing it to an actual or let's say realistic project.
I have a simple REST web service which uses Servlets. It has an API method that sends a POST request to another web service then arranges the data as its response.
The API request is processed by two layers:
Servlet (Controller) - validates the request parameters
Service - The sender of the POST request to another web service
Here's what the service method does:
Prepares a parameter data (some attributes are provided in the paramaters of this request, some are retrieved from the database)
sends a request to another web service which responds with an image url for a QR Code
Decodes the QRCode image and then responds to its request with the decoded text
What are the unit tests cases needed for this?
How about integration tests? Do I have to use ServletUnit, or can I just run the server and write tests with requests to the running server?
Unit testing usually involves testing a single class in isolation. So you would need tests for the servlet class and for your service class as well.
If you're interested in unit testing a servlet, then have a look at these answers. In your case, you need to mock any external dependencies and check for example if valid parameters are sent to the service method.
Unit testing the service method includes mocking all external dependencies (web service, database) and only test the logic that's performed in the method (e.g. data is prepared correctly, QR decoding and responding with the correct text).
Most of the time you end up writing integration tests since you have multiple components which need to work together. There are multiple possible solutions to tackle that problem. You could create a separate integration testing environment which tries to replicate your production environment as closely as possible (web server, application server, database). For smaller projects that might be too much work and you could just spin up an embedded Tomcat with some kind of an in memory database (H2 for example). Keep in mind that for integration tests to be repeatable you might have to reinitialize the database for every test run.
In addition, you mentioned a web service which responds with a URL to a QR code. If you're not in control of that service, I would try to mock that service as well. You don't want to have a failing integration test because of a web service which might not be available 100% of the time.
Since your Servlet acts as a RESTful web service, take a look at rest-assured. This is a DSL for testing REST services.
I want to build an e-commerce application using JSF 2.0. I saw some examples (including the ones that come bundled with NetBeans). In those examples data was stored in some sort of database and was retrieved and queried using SQL. In those examples there was some sort of persistent object in the application. What I want to do is retrieve data from a Restful Web Service and so I will not use SQL at all. My question is: Do I need to include a model section (MVC pattern) in my application having persistent objects or should I just use beans which will directly connect with the web service? How does such an application generally work?
Your REST service would provide some data (JSON, XML), probably it would be handy to map these data to model classes on JSF application side. So in your JSF bean you would connect REST service, map data obtained from it to model classes and then call some bussines logic (that use model classes).
Obviously if the REST service returns single number or string there is no use to create another class just for the sake of architecture. Similarly if you bussiness logic is very simple, it is better to do everything in JSF managed bean class.
Situation:
We are planning to build a set of new services a long side a set of old SOAP (Spring, apache CXF) web services. Our customers are used to being able to use ?wsdl to get a wsdl describing a service and the content it will accept/return.
I'm looking at providing the new services via spring controllers and RESTful urls. However not all of a request can be handled via a RESTful url, so we still need to have a payload request and responses. I'm looking at use #RequestBody and #ResponseBody and spring's Message Converters to auto(magically) handle both XML and JSON content. The idea being to let spring do as much of the heaving lifting as possible.
The problem:
I'm trying to figure out if it's possible given the REST/Message converter concept, to be able to provide a description of a service and it's request/response data in a similar fashion to the ?wsdl request. I understand that there are WADL documents that can be generated by some systems, but they appear to be a proposel and not fully accepted yet.
Does anyone know if spring can generate WADLs or something else that I can use to allow clients to query the RESTful services data structures?
SpringMVC doesn't support WADL auto generation, mostly because it doesn't use the JSR-311 standard REST API.
I have create a blog entry with a simple WADL generation Controller in java :
Tuxgalaxy Blog Entry.
But Tomasz Nurkiewicz also provide a WADL generation Controller in scala :
nurkiewicz Blog Entry.
You could use CXF JAX-RS for your REST services since you're already using it for SOAP (you can even expose the same service as SOAP and REST with CXF), and CXF gives you the WADL that you want by adding ?_wadl&_type=xml
The following code will work with Spring REST 4x and its based on the suggested code by tuxgalaxy provided on below https://jira.spring.io/browse/SPR-8705
http://javattitude.com/2014/05/26/wadl-generator-for-spring-rest/
I have a classic ASP page that was implemented in 2002-ish.
It was acting as an exposed entry point for a collection of SOAP web services.
All this page has is the VB script to create a SoapServer30 object, load a WSDL and WSML and send the object the HttpRequest in order to invoke the web service method.
The web service method is being specified in the HTTP Header's SOAPAction variable.
The request also contains the SOAP envelope with the parameters for the web service call.
This process is no longer working due to changes in the WSDL, the deployment changes, etc.
Basically it's too far gone and too much change has happened since 2002 to salvage this process.
We have a client though that does not want to make any code changes, they use Axis and Java to create the web service request and call this ASP page.
I'd like to alter the VB script to simply pass the HttpRequest to an ASP.NET MVC page for parsing and to route to the correct web service.
Then I'll simply return the result.
Any and all code samples would be greatly appreciated as I have little to no experience with VBScript. My experience is in C#.NET.
Thanks.
Why do you need VBScript at all any more? Why not simply create an ASP.NET MVC route that takes the request directly? I think the ASP.NET MVC route could simply have the same name as the old .asp file.
A friend wants to consume my ASP.NET MVC 2 application in a similar fashion as adding a web reference to it, accessing my functions, and using my model objects from a .Net web form from a separate website.
Any links out there that could explain how to "dress" my MVC responses so that his server to server consumption would be similar in experience to a web service?
I suggested using System.Net.WebClient to pull the results in to a variable then deserialize the JSON result, but maybe there's a better approach out there?
I'd suggest that you consider an API controller or a separate API application depending on the load you expect from people consuming data from your application. A separate API application will allow you to move it off your application servers if needed.
Rarely, will you find that the data that you would provide via an API is a one-to-one match with what your views need to be rendered. Behind the scenes you could abstract the data generation so that your API and your application controllers reuse the same code to get at the data, but the front-end of the API would understand how to negotiate security (from an API perspective) and present data that is easily consumed by a program. Moreover, you won't find that you're creating extra controllers and methods in your application just to provide some data that will never be used in a particular view.
You could use MVC or WCF for the API and JSON or XML as the payload format. If you use WCF, you get the benefit that he really can simply add a service reference to connect to it without you having to build a WSDL file/action.
From another's advice, Phil Haack added this to MVC 2 Futures. Add the DLL reference to the Application Start, and bingo. It uses a validator.