Skip to content

Commit

Permalink
Port HttpHeadersValidator to http client v5
Browse files Browse the repository at this point in the history
  • Loading branch information
nitind committed Jul 8, 2024
1 parent e15a0b2 commit 5f7c6a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
10 changes: 3 additions & 7 deletions core/bundles/org.eclipse.wst.wsi/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %_PLUGIN_NAME
Bundle-SymbolicName: org.eclipse.wst.wsi; singleton:=true
Automatic-Module-Name: org.eclipse.wst.wsi
Bundle-Version: 1.1.501.qualifier
Bundle-Version: 1.1.600.qualifier
Bundle-Activator: org.eclipse.wst.wsi.internal.WSITestToolsPlugin
Bundle-Vendor: %_PROVIDER_NAME
Bundle-Localization: plugin
Expand Down Expand Up @@ -53,14 +53,10 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.17.0,4.0.0)",
javax.wsdl;bundle-version="[1.6.2,1.7.0)",
org.uddi4j;bundle-version="[2.0.4,2.1.0)",
org.apache.axis;bundle-version="[1.3.0,2.0.0)",
org.apache.commons.commons-logging,
org.apache.commons.commons-logging;bundle-version="[1.3.3,2.0.0)",
org.apache.xerces;bundle-version="[2.12.1,3.0.0)",
org.apache.commons.commons-codec;bundle-version="[1.2.0,2.0.0)",
org.apache.httpcomponents.core5.httpcore5;bundle-version="[5.2.3,6.0.0)",
com.ibm.icu;bundle-version="73.1.0"
Import-Package: org.apache.http,
org.apache.http.config,
org.apache.http.impl.conn,
org.apache.http.impl.io,
org.apache.http.io
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
2 changes: 1 addition & 1 deletion core/bundles/org.eclipse.wst.wsi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>org.eclipse.webtools.webservices</groupId>
<artifactId>org.eclipse.wst.wsi</artifactId>
<version>1.1.501-SNAPSHOT</version>
<version>1.1.600-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2020 IBM Corporation and others.
* Copyright (c) 2002, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -19,14 +19,15 @@
import java.text.ParseException;
import java.util.Locale;

import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.config.MessageConstraints;
import org.apache.http.impl.conn.DefaultHttpResponseParserFactory;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.io.SessionInputBufferImpl;
import org.apache.http.io.HttpMessageParser;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParserFactory;
import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl;
import org.apache.hc.core5.http.io.HttpMessageParser;

import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.util.StringTokenizer;
Expand Down Expand Up @@ -349,12 +350,12 @@ private static boolean isFullAddr(String mailbox)

public static boolean validateHttpRequestHeaders(String headers)
{
SessionInputBufferImpl buffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 2048);
buffer.bind(new ByteArrayInputStream(headers.getBytes()));
HttpMessageParser<HttpResponse> messageParser = DefaultHttpResponseParserFactory.INSTANCE.create(buffer, MessageConstraints.DEFAULT);
SessionInputBufferImpl buffer = new SessionInputBufferImpl(new BasicHttpTransportMetrics(), 2048);
// buffer.fillBuffer(new ByteArrayInputStream(headers.getBytes()));
HttpMessageParser<ClassicHttpResponse> messageParser = DefaultHttpResponseParserFactory.INSTANCE.create(Http1Config.custom().build());
HttpResponse response;
try {
response = messageParser.parse();
response = messageParser.parse(buffer, new ByteArrayInputStream(headers.getBytes()));
}
catch (IOException e1) {
return false;
Expand All @@ -363,12 +364,12 @@ public static boolean validateHttpRequestHeaders(String headers)
return false;
}

if (!isHTTPVersion(response.getProtocolVersion().toString()))
if (response.getVersion()==null)
return false;

try
{
for (Header httpHeader: response.getAllHeaders())
for (Header httpHeader: response.getHeaders())
{
String header = httpHeader.getName();
String value = httpHeader.getValue();
Expand Down

0 comments on commit 5f7c6a1

Please sign in to comment.