Java - Ayuda con sintaxis

 
Vista:
Imágen de perfil de Victor
Val: 7
Ha aumentado su posición en 4 puestos en Java (en relación al último mes)
Gráfica de Java

Ayuda con sintaxis

Publicado por Victor (6 intervenciones) el 27/02/2015 19:18:05
Hola javeros, necesito ayuda para entender lo que se hace en este código java, hasta cierto punto entiendo, pero me gustaría saber si estoy en lo correcto. No tengo la descripción de las clases de este código, por lo que se hace un poco mas dificil la interpretación.

Va el codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.awt.PageAttributes.MediaType;
import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URI;
import java.text.Normalizer.Form;
 
public class OndemandWsClient {
	private static final String UTF8 = "UTF-8";
	private static final String OUT_FILE = "C:/temp/simulation.pdf";
	private static final String WS_URL = "http://192.168.42.203:9085/ondemand-ws/test/";
 
	public OndemandWsClient() {
	}
 
	public void callRestful() throws IOException {
		ClientConfig config = new DefaultClientConfig();
		Client client = Client.create(config);
		WebResource service = client.resource(getBaseURI());
		final Form FORM = new Form();
		FORM.add("id", "myform");
		FORM.add("comment", "Demonstration of the client jax-rs for forms");
		InputStream is = OndemandWsTest.class.getResourceAsStream("/bom.xml");
		StringWriter writer = new StringWriter();
		IOUtils.copy(is, writer, UTF8);
		String bomString = writer.toString();
		FORM.add("bomXml", bomString);
		final Base64 B64ENC = new Base64();
		FORM.add("dataXml", new String(B64ENC.encode(myZIP.getBytes(UTF8))));
		String client0 = "client1";
		String proc = "proc1";
		String app = "app1";
		String env = "simulation";
		ClientResponse response = service.path(client0).path(proc).path(app).path(env).type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, FORM);
		final int RESULT = response.getStatus();
		String res;
		System.out.println("Response status: " + response.getStatus());
		res = response.getEntity(String.class);
		System.out.println("Response: " + StringUtils.abbreviate(res, 40));
		assertEquals(200, RESULT);
		try {
			byte[] decoded;
			decoded = B64ENC.decode(res);
			if (decoded.length != 0) {
				File file = new File(OUT_FILE);
				FileOutputStream fos = new FileOutputStream(file);
				IOUtils.write(decoded, fos);
			} else {
				fail("Decoded byte array is empty");
			}
		} catch (Exception e) {
			fail("Error writing file: " + e);
		}
	}
	private static URI getBaseURI() {
		return UriBuilder.fromUri(WS_URL).build();
	}
}

A muy grandes rasgos les digo lo que entiendo. Se lee desde el mismo directorio donde está situada la aplicacion, el archivo "bom.xml", y luego se copia a la variable "writer" con codificacion utf-8, luego este ultimo es copiado a una variable "bomString" como string, y es adherido a un FORM bajo el nombre "bomXml", estuve leyendo sobre la clase FORM en el API, pero no logro entender bien.
Luego se agrega al FORM, bajo el nombre "dataXml", la codificacion en base64 de un archivo zip "myZip". Despues de esto me pierdo, veo que al final se graban todos los datos a un file (OUTPUT). Me podrian corregir, ayudar en lo que hace este pedazo de codigo? Lo pegue en el eclipse para tratar de hacer funcionar y hacer debug, pero me saltan muchos errores de clases e importacion, parece ser que los repositorios de algunas clases ya no existen.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder