Skip to content

Commit

Permalink
[#1251] upgrade to Jetty 12
Browse files Browse the repository at this point in the history
Initial signature adaptation, payload is not yet considered

Signed-off-by: Alexander Fedorov <[email protected]>
  • Loading branch information
ruspl-afed committed Nov 15, 2023
1 parent c40d964 commit a550b25
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
9 changes: 6 additions & 3 deletions bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.core.runtime;bundle-version="0.0.0",
org.eclipse.jetty.http;bundle-version="0.0.0",
org.eclipse.jetty.server;bundle-version="0.0.0",
org.eclipse.jetty.util;bundle-version="0.0.0",
org.eclipse.passage.lic.equinox;bundle-version="0.0.0",
org.eclipse.passage.lic.net;bundle-version="0.0.0"
Export-Package: org.eclipse.passage.lic.internal.jetty;x-friends:="org.eclipse.passage.lbc.base,org.eclipse.passage.lbc.jetty,org.eclipse.passage.lac.jetty",
org.eclipse.passage.lic.internal.jetty.interaction;x-friends:="org.eclipse.passage.lbc.jetty"
Import-Package: javax.servlet,
javax.servlet.http,
org.eclipse.jetty.http;version="12.0.3",
org.eclipse.jetty.io;version="12.0.3",
org.eclipse.jetty.server;version="12.0.3",
org.eclipse.jetty.server.handler;version="12.0.3",
org.eclipse.jetty.util;version="12.0.3",
org.eclipse.jetty.util.component;version="12.0.3",
org.slf4j;version="1.7.36"
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
* Copyright (c) 2021, 2023 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -18,12 +18,16 @@
import java.util.Objects;
import java.util.function.Function;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Callback;
import org.eclipse.passage.lic.internal.net.api.handle.NetRequest;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;

Expand All @@ -34,7 +38,7 @@
* Thus, it's the only place to keep server's {@code state}. Which, for the
* floating server, is a persistent grant acquisition ledger.
*/
public final class JettyHandler extends AbstractHandler {
public final class JettyHandler extends Handler.Abstract {

private final Function<NetRequest, NetResponse> handler;

Expand All @@ -44,13 +48,48 @@ public JettyHandler(Function<NetRequest, NetResponse> handler) {
}

@Override
public void handle(String target, Request request, HttpServletRequest wrapper, HttpServletResponse envelope)
throws IOException, ServletException {
write(response(wrapper), envelope);
request.setHandled(true);
public boolean handle(Request request, Response response, Callback callback) throws Exception {
response.setStatus(200);
long contentLength = -1;
for (HttpField field : request.getHeaders()) {
HttpHeader header = field.getHeader();
if (header == null) {
continue;
}
switch (header) {
case CONTENT_LENGTH:
response.getHeaders().add(field);
contentLength = field.getLongValue();
break;
case CONTENT_TYPE:
response.getHeaders().add(field);
break;
case TRAILER:
response.setTrailersSupplier(HttpFields.build());
break;
case TRANSFER_ENCODING:
contentLength = Long.MAX_VALUE;
break;
}
}
if (contentLength > 0) {
//FIXME: AF: here we should somehow consider our "handler" function
Content.copy(request, response, Response.newTrailersChunkProcessor(response), callback);
} else {
callback.succeeded();
}
return true;

}

private NetResponse response(HttpServletRequest request) {
// @Override
// public void handle(String target, Request request, HttpServletRequest wrapper, HttpServletResponse envelope)
// throws IOException, ServletException {
// write(response(wrapper), envelope);
// request.setHandled(true);
// }

private NetResponse response(Request request) {
return handler.apply(new JettyRequest(request));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
* Copyright (c) 2021, 2023 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -16,31 +16,37 @@
import java.io.InputStream;
import java.util.Objects;

import javax.servlet.http.HttpServletRequest;

import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.server.Request;
import org.eclipse.passage.lic.internal.net.api.handle.NetRequest;

public final class JettyRequest implements NetRequest {

private final HttpServletRequest origin;
private final Request origin;

public JettyRequest(HttpServletRequest origin) {
public JettyRequest(Request origin) {
Objects.requireNonNull(origin, "JettyRequest::origin"); //$NON-NLS-1$
this.origin = origin;
}

@Override
public String parameter(String name) {
return origin.getParameter(name);
//FIXME: AF: most probably this is it
return Request.extractQueryParameters(origin).getValue(name);
}

@Override
public byte[] content() throws IOException {
byte[] content = new byte[origin.getContentLength()];
try (InputStream stream = origin.getInputStream()) {
//FIXME: AF: field can be null
HttpField field = origin.getHeaders().getField(HttpHeader.CONTENT_LENGTH);
//FIXME: AF: they expect long here
long length = field.getLongValue();
byte[] content = new byte[(int) length];
try (InputStream stream = Request.asInputStream(origin)) {
stream.read(content);
}
return content;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<unit id="org.eclipse.license.feature.group" version="0.0.0"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.28/R-4.28-202306050440/"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.30-I-builds/I20231109-0710/"/>
<unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
Expand Down

0 comments on commit a550b25

Please sign in to comment.