comparison flys-client/src/main/java/de/intevation/flys/client/server/was/Response.java @ 2947:645c774b3b98

WAS response: Directly use Base64InputStream instead of reading it first into memory. flys-client/trunk@4922 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 10 Jul 2012 19:55:22 +0000
parents 927a3bd932d5
children
comparison
equal deleted inserted replaced
2946:1e01d3046260 2947:645c774b3b98
1 package de.intevation.flys.client.server.was; 1 package de.intevation.flys.client.server.was;
2 2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException; 3 import java.io.IOException;
5 import java.io.InputStream; 4 import java.io.InputStream;
6 5
7 import org.apache.commons.codec.binary.Base64; 6 import org.apache.commons.codec.binary.Base64InputStream;
8 import org.apache.commons.io.IOUtils; 7
9 import org.apache.http.HttpEntity; 8 import org.apache.http.HttpEntity;
9
10 import org.apache.log4j.Logger; 10 import org.apache.log4j.Logger;
11 11
12 import org.jdom.Document; 12 import org.jdom.Document;
13 import org.jdom.Element; 13 import org.jdom.Element;
14 import org.jdom.JDOMException; 14 import org.jdom.JDOMException;
15 import org.jdom.Namespace; 15
16 import org.jdom.input.SAXBuilder; 16 import org.jdom.input.SAXBuilder;
17 17
18 public class Response { 18 public class Response {
19 19
20 private static Logger logger = Logger.getLogger(Response.class); 20 private static Logger logger = Logger.getLogger(Response.class);
28 throw new ServiceException("Invalid response"); 28 throw new ServiceException("Invalid response");
29 } 29 }
30 30
31 String contenttype = entity.getContentType().getValue(); 31 String contenttype = entity.getContentType().getValue();
32 32
33 33 try {
34 try{
35 InputStream in = entity.getContent(); 34 InputStream in = entity.getContent();
36 35
37 if (!contenttype.equals("application/vnd.ogc.se_xml")) { 36 if (!contenttype.equals("application/vnd.ogc.se_xml")) {
38 // assume base64 37 // XXX: Assume base64 encoded content.
39 byte[] content = IOUtils.toByteArray(entity.getContent()); 38 in = new Base64InputStream(in);
40 in = new ByteArrayInputStream(Base64.decodeBase64(content));
41 } 39 }
42 40
43 SAXBuilder builder = new SAXBuilder(); 41 SAXBuilder builder = new SAXBuilder();
44 Document doc = builder.build(in); 42 Document doc = builder.build(in);
45 Element root = doc.getRootElement(); 43 Element root = doc.getRootElement();
44 String rname = root.getName();
46 45
47 if (root.getName() != null && root.getName().equals("ServiceExceptionReport")) { 46 if (rname != null && rname.equals("ServiceExceptionReport")) {
48 throw new ServiceException(root.getChildText("ServiceException")); 47 throw new ServiceException(root.getChildText("ServiceException"));
49 } 48 }
50 49
51 this.root = root; 50 this.root = root;
52 } 51 }
61 public Element getRoot() { 60 public Element getRoot() {
62 return this.root; 61 return this.root;
63 } 62 }
64 63
65 public Boolean isSuccess() { 64 public Boolean isSuccess() {
66 return (this.getStatus() != null && this.getStatus().equals("samlp:Success")); 65 String status = getStatus();
66 return status != null && status.equals("samlp:Success");
67 } 67 }
68 68
69 public String getStatus() { 69 public String getStatus() {
70 Element status = this.root.getChild("Status", Namespaces.SAML_NS_PROTO); 70 Element status = this.root.getChild("Status", Namespaces.SAML_NS_PROTO);
71 if (status == null) { 71 if (status == null) {

http://dive4elements.wald.intevation.org