1 package de.juplo.thymeproxy;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import org.apache.http.HttpEntity;
7 import org.apache.http.client.methods.CloseableHttpResponse;
8 import org.apache.http.util.EntityUtils;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11 import org.thymeleaf.TemplateProcessingParameters;
12 import org.thymeleaf.resourceresolver.IResourceResolver;
20 public class ProxyResourceResolver implements IResourceResolver
22 private final static Logger LOG =
23 LoggerFactory.getLogger(ProxyResourceResolver.class);
26 private final String resource;
28 private final CloseableHttpResponse response;
29 private final HttpEntity entity;
32 public ProxyResourceResolver(
34 CloseableHttpResponse response,
38 this.resource = resource;
39 this.response = response;
45 public String getName()
51 public InputStream getResourceAsStream(TemplateProcessingParameters templateProcessingParameters, String resourceName)
56 is = entity.getContent();
60 LOG.error("unexpected error while retriving the response-body", e);
64 return new InputStream()
67 public boolean markSupported()
69 return is.markSupported();
73 public synchronized void reset() throws IOException
79 public synchronized void mark(int readlimit)
85 public void close() throws IOException
88 EntityUtils.consume(entity);
93 public int available() throws IOException
95 return is.available();
99 public long skip(long n) throws IOException
105 public int read() throws IOException
111 public int read(byte[] b, int off, int len) throws IOException
113 return is.read(b, off, len);
117 public int read(byte[] b) throws IOException