Java – Enterprise Solutions and Web

Java is the language of choice for enterprise solutions. There are numerous tools built in Java such as simple workflows used by car insurance agents, or sophisticated business processes managed in bank environments. With the advent of Spring, it is frequently used for micro-services and cloud applications.

How to decode a VIN with Java

Java is a verbose language. What can be done in a single line of Python code, requires five or ten in Java. This is necessary due to Java having a strong object foundation. Instead of a function with some parameters, it requires creating and configuring an object to pass to another objects. However, this verbosity is not that painful when used with Dependency Injection frameworks like Spring. Spring does a great deal of automation in creating, configuring and interweaving objects, and simplifies the whole process.

Working with Java Verbosity and VinLiNK™

The code below is an example and it doesn’t use any DI framework to reduce it’s verbosity. In reality, Spring’s Web Service Template can be useful to make it more manageable. In imports we use jax-ws generated stub, that is built using maven based on WSDL provided by VinLINK™ Web-Service.

import java.util.List;

import com.vinlink.ws.*;

public class Client {

Then we create a decoder service stub and pass it to a handler resolver that fills in authorization headers. After completing this step, we create communication port for connecting to the web-service. For the full code please visit: https://github.com/Piotr3kK/vinlink-vin-decoder-java

Next, we create a communication port for connecting to the web-service, like so:

public static void main(String[] args) {
		
		// create account at www.vinlink.com
		String LOGIN = "login";
		String PASSWD = "password";

		try {
			Decoder service = new Decoder();
			HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
			handlerResolver.setUser(LOGIN);
			handlerResolver.setPasswd(PASSWD);
			service.setHandlerResolver(handlerResolver);
			DecoderPortType port = service.getDecoderHttpPort();

Next, we process every VIN provided on the command line, catch eventual exceptions, and then close the code.

for (String vin: args) {
				ArrayOfReport reports = port.decode(vin, ReportTypes.BASIC_PLUS);
				List<Report> reprtList = reports.getReport();
				for (Report r : reprtList) {
					List<Item> items = r.getVinSpecification().getValue().getItem();
					for (Item i : items) {
						String n = i.getName().getValue();
						String v = i.getValue().getValue();
						System.out.printf("%s\t%s\n", n, v);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

For more information about Java implementation, please contact us: Sales@espdata.com.