You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
johmn123-wq
changed the title
Suggest the alternative of the Some methods which doesn
Suggest the alternative of the Some methods which does't support jetty12
Aug 12, 2024
Jetty version(s)
migration from Jetty 11.0.x to Jetty 12.0.x
Jetty Environment
Applicable for jetty-12 ee10
Java version/vendor
(use: java -version)
Java17
OS type/version
Description
Here is the code for 11.0.x
Here is the migrated code to jetty12 where getOutStream, setHandled, response.add() etc functions are not supported.
public class ApacheServerHandler extends Handler.Abstract{
private ApacheServerHandler(){
client = HttpClients.createDeafult();
}
@OverRide
public void handle(Request request, Response response, Callback callback) throws IOException, ServletException{
String newHost = request.getHeaders().get('sb_host');
if(newHost.endsWith("/")){
newHost = StringUtils.substring(newHost, 0, newHost.length() - 1);
}
HttpUriRequest = null;
String method = request.getMethod();
String queryString = request.getHttpURI().getQuery();
String path = request.getHttpURI().getPath();
Enumerationheaders = request.getHeaders().getFieldNames();
String newUrl = String.format("http://%s%s", newHost, path, queryString);
if("GET".equalsIgnoreCase(method){
uriRequest = new HttpGet(newUrl);
}
else if("POST".equalsIgnoreCase(method){
uriRequest = new HttpPost(newUrl);
}
else if("PUT".equalsIgnoreCase(method){
uriRequest = new HttpPut(newUrl);
}
else{
baseRequest.setHandled(false);
}
if(uriRequest instanceof HttpEntityEncloseingRequest){
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) uriRequest;
entityRequest.setEntity(new InputStreamEntity(Request.asInputStream(requrest), ContentType.create(request.getHeaders().getHtHeader.CONTENT_TYPE.asString()))));
}
while(headers.hasMoreElements()){
String headerName = headers.nextElement();
if(headerName.equalIgnoreCase('Content-length'))
continue;
uriRequest.addHeader(headerName, baseRequest.getHeader(headerName));
}
baseRequest.setHandled(true);
return false;
}
}
The text was updated successfully, but these errors were encountered: