Last active
February 7, 2018 19:23
-
-
Save Franco-Poveda/c451edfd9280ea02fd3f65b71f7c38fb to your computer and use it in GitHub Desktop.
proof of concept: ANDRIANI "Consultar Sucursales" raw WS method call - using handlebars template engine && okHttp request library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mycompany.manualws; | |
import com.github.jknack.handlebars.Handlebars; | |
import com.github.jknack.handlebars.Template; | |
import com.github.jknack.handlebars.io.FileTemplateLoader; | |
import com.github.jknack.handlebars.io.TemplateLoader; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.util.HashMap; | |
import java.util.Map; | |
import okhttp3.MediaType; | |
import okhttp3.OkHttpClient; | |
import okhttp3.Request; | |
import okhttp3.RequestBody; | |
import okhttp3.Response; | |
/** | |
* | |
* @author Franco Poveda (franco.poveda[at]gmail.com) | |
*/ | |
public class AndrianiWS { | |
private final String USER_AGENT = "Mozilla/5.0"; | |
private static final MediaType MEDIA_TYPE_PLAINTEXT = MediaType | |
.parse("text/plain; charset=utf-8"); | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) throws FileNotFoundException, IOException { | |
TemplateLoader loader = new FileTemplateLoader("/src/res"); | |
Handlebars handlebars = new Handlebars(loader); | |
Template template = handlebars.compile("sucursales"); | |
String envelop = template.apply(new HashMap<String, Object>() { | |
{ | |
put("pwd", "password"); | |
put("usr", "usuario"); | |
put("cp", "5515"); | |
} | |
});//System.out.println(template.apply("ANDRIANI")); | |
OkHttpClient client = new OkHttpClient(); | |
//.parse("text/plain; charset=utf-8"); | |
Request request = new Request.Builder() | |
.url("https://sucursalespreprod.andreani.com/ws?wsdl=") | |
.post(RequestBody.create(MEDIA_TYPE_PLAINTEXT, envelop)) | |
.addHeader("Cache-Control", "no-cache") | |
.build(); | |
Response response = client.newCall(request).execute(); | |
System.out.println(response.body().string()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependencies> | |
<dependency> | |
<groupId>com.github.jknack</groupId> | |
<artifactId>handlebars</artifactId> | |
<version>4.0.6</version> | |
</dependency> | |
<dependency> | |
<groupId>com.squareup.okhttp3</groupId> | |
<artifactId>okhttp</artifactId> | |
<version>3.9.1</version> | |
</dependency> | |
</dependencies> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment