All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anthavio.httl.util.CodeGeneratingHandler Maven / Gradle / Ivy

The newest version!
package net.anthavio.httl.util;

import java.io.IOException;

import net.anthavio.httl.HttlRequest;
import net.anthavio.httl.HttlResponse;
import net.anthavio.httl.HttlResponseHandler;

/**
 * Jackson2 required
 * 
 * @author martin.vanek
 *
 */
public class CodeGeneratingHandler implements HttlResponseHandler {

	@Override
	public void onResponse(HttlResponse response) throws IOException {
		String mediaType = response.getMediaType();
		if (mediaType.indexOf("javascript") != -1 || mediaType.indexOf("json") != -1) {
			JsonInputGenerator generator = new JsonInputGenerator();
			String java = generator.process("com.example.httl.GeneratedResponse", response.getReader());
			System.out.println(java);
		} else if (mediaType.indexOf("xml") != -1) {
			throw new UnsupportedOperationException("Not yet " + mediaType);
		} else {
			throw new IllegalArgumentException("Unsupported media type " + mediaType);
		}
	}

	@Override
	public void onFailure(HttlRequest request, Exception exception) {
		exception.printStackTrace();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy