Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 665e996

Browse files
committed
Revert "Issue #3: initial autoconfiguration support"
This reverts commit 2866c6a.
1 parent 68ecddb commit 665e996

File tree

7 files changed

+10
-225
lines changed

7 files changed

+10
-225
lines changed

nbactions.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
1111
</goals>
1212
<properties>
13-
<exec.args>-classpath %classpath eu.fusepool.p3.proxy.Main -P 8181 -BAC src/test/resources/autoconfig</exec.args>
13+
<exec.args>-classpath %classpath eu.fusepool.p3.proxy.Main -P 8181</exec.args>
1414
<exec.executable>java</exec.executable>
1515
</properties>
1616
</action>
1717
<action>
1818
<actionName>debug</actionName>
19-
<!-- <displayName>Custom Debug</displayName> -->
2019
<packagings>
2120
<packaging>jar</packaging>
2221
</packagings>
@@ -25,7 +24,7 @@
2524
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
2625
</goals>
2726
<properties>
28-
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath eu.fusepool.p3.proxy.Main -P 8181 -BAC src/test/resources/autoconfig</exec.args>
27+
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath eu.fusepool.proxy.Main -P 8181</exec.args>
2928
<exec.executable>java</exec.executable>
3029
<jpda.listen>true</jpda.listen>
3130
</properties>

src/main/java/eu/fusepool/p3/proxy/Arguments.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,4 @@ public interface Arguments extends ArgumentsWithHelp {
3636
description = "The base URI to which to redirect the requests (hostname is only used to locate target server)")
3737
public String getTarget();
3838

39-
@CommandLine(longName = "backendAutoConfiguration", shortName = {"BAC"}, required = false,
40-
description = "If set the proxy will attempt to put the files in the specified direcrory to the target on the firts request")
41-
public String backendAutoConfiguration();
42-
4339
}

src/main/java/eu/fusepool/p3/proxy/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception
3333

3434
private static void start(Arguments arguments) throws Exception {
3535
final Server server = new Server(arguments.getPort());//new Server(Integer.parseInt(arguments.getPort()));
36-
server.setHandler(new ProxyHandler(arguments.getTarget(), arguments.backendAutoConfiguration()));
36+
server.setHandler(new ProxyHandler(arguments.getTarget()));
3737
server.start();
3838
server.join();
3939
}

src/main/java/eu/fusepool/p3/proxy/ProxyHandler.java

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
import eu.fusepool.p3.vocab.ELDP;
2323
import java.io.ByteArrayInputStream;
2424
import java.io.ByteArrayOutputStream;
25-
import java.io.File;
2625
import java.io.IOException;
2726
import java.io.InputStream;
2827
import java.io.StringWriter;
29-
import java.net.MalformedURLException;
3028
import java.net.URI;
3129
import java.net.URISyntaxException;
32-
import java.net.URL;
3330
import java.util.Enumeration;
3431
import java.util.HashSet;
3532
import java.util.Iterator;
@@ -58,11 +55,8 @@
5855
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
5956
import org.apache.http.client.methods.HttpGet;
6057
import org.apache.http.client.methods.HttpPost;
61-
import org.apache.http.client.methods.HttpPut;
6258
import org.apache.http.client.methods.HttpUriRequest;
6359
import org.apache.http.entity.ByteArrayEntity;
64-
import org.apache.http.entity.ContentType;
65-
import org.apache.http.entity.FileEntity;
6660
import org.apache.http.impl.client.CloseableHttpClient;
6761
import org.apache.http.impl.client.HttpClientBuilder;
6862
import org.apache.http.protocol.HttpContext;
@@ -79,10 +73,8 @@ public class ProxyHandler extends AbstractHandler {
7973
private final CloseableHttpClient httpclient;
8074
private final Parser parser = Parser.getInstance();
8175
private final Serializer serializer = Serializer.getInstance();
82-
boolean firstRequest = true;
83-
private final String backendAutoConfiguration;
8476

85-
ProxyHandler(String targetBaseUri, String backendAutoConfiguration) {
77+
ProxyHandler(String targetBaseUri) {
8678
if (targetBaseUri.endsWith("/")) {
8779
this.targetBaseUri = targetBaseUri.substring(0, targetBaseUri.length() - 1);
8880
} else {
@@ -91,7 +83,6 @@ public class ProxyHandler extends AbstractHandler {
9183
final HttpClientBuilder hcb = HttpClientBuilder.create();
9284
hcb.setRedirectStrategy(new NeverRedirectStrategy());
9385
httpclient = hcb.build();
94-
this.backendAutoConfiguration = backendAutoConfiguration;
9586
}
9687

9788
@Override
@@ -100,18 +91,6 @@ public void handle(String target, Request baseRequest,
10091
throws IOException, ServletException {
10192
final String targetUriString = targetBaseUri + inRequest.getRequestURI();
10293
final String requestUri = getFullRequestUrl(inRequest);
103-
if (firstRequest) {
104-
if (!"no-auto-config".equals(inRequest.getHeader("X-Fusepool-Proxy"))) {
105-
synchronized (this) {
106-
if (firstRequest) {
107-
if (backendAutoConfiguration != null) {
108-
autoCofigureBackend(requestUri);
109-
}
110-
firstRequest = false;
111-
}
112-
}
113-
}
114-
}
11594
//System.out.println(targetUriString);
11695
final URI targetUri;
11796
try {
@@ -138,7 +117,7 @@ public String getMethod() {
138117
final Enumeration<String> headerNames = baseRequest.getHeaderNames();
139118
while (headerNames.hasMoreElements()) {
140119
final String headerName = headerNames.nextElement();
141-
if (headerName.equalsIgnoreCase("Content-Length")
120+
if (headerName.equalsIgnoreCase("Content-Length")
142121
|| headerName.equalsIgnoreCase("X-Fusepool-Proxy")
143122
|| headerName.equalsIgnoreCase("Transfer-Encoding")) {
144123
continue;
@@ -159,7 +138,7 @@ public String getMethod() {
159138
if (inEntityBytes.length > 0) {
160139
outRequest.setEntity(new ByteArrayEntity(inEntityBytes));
161140
}
162-
final CloseableHttpResponse inResponse = httpclient.execute(outRequest);
141+
final CloseableHttpResponse inResponse = httpclient.execute(outRequest);
163142
try {
164143
outResponse.setStatus(inResponse.getStatusLine().getStatusCode());
165144
final Header[] inResponseHeaders = inResponse.getAllHeaders();
@@ -260,13 +239,13 @@ private void startTransformation(final String resourceUri,
260239

261240
@Override
262241
public void run() {
263-
Transformer transformer = new TransformerClientImpl(transformerUri);
242+
Transformer transformer= new TransformerClientImpl(transformerUri);
264243
Entity entity = new InputStreamEntity() {
265244

266245
@Override
267246
public MimeType getType() {
268247
try {
269-
for (Header h : requestHeaders) {
248+
for(Header h : requestHeaders) {
270249
if (h.getName().equalsIgnoreCase("Content-Type")) {
271250
return new MimeType(h.getValue());
272251
}
@@ -319,7 +298,7 @@ public URI getContentLocation() {
319298
} catch (IOException ex) {
320299
throw new RuntimeException(ex);
321300
}
322-
301+
323302
}
324303

325304
}).start();
@@ -354,55 +333,6 @@ private void post(String ldpcUri, HttpEntity entity, String mediaType,
354333
}
355334
}
356335

357-
private void autoCofigureBackend(String requestUri) throws MalformedURLException, IOException {
358-
URL baseUrl = new URL(new URL(requestUri), "/");
359-
File directory = new File(backendAutoConfiguration);
360-
if (!directory.exists()) {
361-
log.warn(directory.getAbsolutePath() + " does not exist, ignoring.");
362-
return;
363-
}
364-
putFileOrDir(baseUrl, directory);
365-
}
366-
367-
private void putFileOrDir(URL url, File file) throws MalformedURLException, IOException {
368-
if (!file.isDirectory()) {
369-
putFile(url, file);
370-
} else {
371-
final String urlString = url.toString();
372-
final URL baseUrl = urlString.endsWith("/") ? url : new URL(urlString+"/");
373-
for (File child : file.listFiles()) {
374-
putFileOrDir(new URL(baseUrl, child.getName()), child);
375-
}
376-
}
377-
}
378-
379-
private void putFile(URL url, File file) throws IOException {
380-
try {
381-
HttpPut httpPut = new HttpPut(url.toURI());
382-
//again, while we could also post directly to the proxied server, this would
383-
//require twaeking host header and possibly request path
384-
//so we call back to the proxy and use this header to allow a transformation loop
385-
httpPut.setHeader("X-Fusepool-Proxy", "no-auto-config");
386-
ContentType contentType = guessContentType(file);
387-
HttpEntity entity = new FileEntity(file, contentType);
388-
httpPut.setEntity(entity);
389-
try (CloseableHttpResponse response = httpclient.execute(httpPut)) {
390-
if (response.getStatusLine().getStatusCode() != 201) {
391-
log.warn("Response to PUT request to backend resulted in: "
392-
+ response.getStatusLine() + " rather than 201. URI: " + url);
393-
}
394-
}
395-
396-
} catch (URISyntaxException ex) {
397-
throw new RuntimeException(ex);
398-
}
399-
}
400-
401-
private static ContentType guessContentType(File file) {
402-
//TODO be a bit more sophisticated
403-
return ContentType.create("text/turtle");
404-
}
405-
406336
private static class NeverRedirectStrategy implements RedirectStrategy {
407337

408338
public NeverRedirectStrategy() {

src/test/java/eu/fusepool/p3/proxy/ProxyAutoConfigTest.java

Lines changed: 0 additions & 129 deletions
This file was deleted.

src/test/java/eu/fusepool/p3/proxy/ProxyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static void startProxy() throws Exception {
6565
proxyPort = findFreePort();
6666
Assert.assertNotEquals("the assignment of different ports went wrong", backendPort, proxyPort);
6767
server = new Server(proxyPort);
68-
server.setHandler(new ProxyHandler("http://localhost:" + backendPort, null));
68+
server.setHandler(new ProxyHandler("http://localhost:" + backendPort));
6969
server.start();
7070
RestAssured.baseURI = "http://localhost:" + proxyPort + "/";
7171
}

src/test/resources/autoconfig/ldp/platform.nt

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)