9
9
import java .security .KeyStoreException ;
10
10
import java .security .NoSuchAlgorithmException ;
11
11
import java .util .*;
12
- import com .genexus .servlet . http . ICookie ;
12
+ import com .genexus .ModelContext ;
13
13
import com .genexus .util .IniFile ;
14
14
import org .apache .http .*;
15
15
import com .genexus .CommonUtil ;
47
47
import org .apache .http .ssl .SSLContexts ;
48
48
import org .apache .http .util .EntityUtils ;
49
49
import org .apache .logging .log4j .Logger ;
50
+ import com .genexus .webpanels .HttpContextWeb ;
51
+ import java .net .URI ;
50
52
51
53
import javax .net .ssl .SSLContext ;
52
54
@@ -115,7 +117,9 @@ public void setTimeout(int timeout)
115
117
private ByteArrayEntity entity = null ; // Para mantener el stream luego de cerrada la conexion en la lectura de la response
116
118
private Boolean lastAuthIsBasic = null ;
117
119
private Boolean lastAuthProxyIsBasic = null ;
118
- private static IniFile clientCfg = new com .genexus .ModelContext (com .genexus .ModelContext .getModelContextPackageClass ()).getPreferences ().getIniFile ();
120
+ private static IniFile clientCfg = new ModelContext (ModelContext .getModelContextPackageClass ()).getPreferences ().getIniFile ();
121
+ private static final String SET_COOKIE = "Set-Cookie" ;
122
+ private static final String COOKIE = "Cookie" ;
119
123
120
124
121
125
private void resetExecParams () {
@@ -167,7 +171,7 @@ private void resetStateAdapted()
167
171
public void setURL (String stringURL ) {
168
172
try
169
173
{
170
- java . net . URI url = new java . net . URI (stringURL );
174
+ URI url = new URI (stringURL );
171
175
setHost (url .getHost ());
172
176
setPort (url .getPort ());
173
177
setBaseURL (url .getPath ());
@@ -181,10 +185,10 @@ public void setURL(String stringURL) {
181
185
}
182
186
183
187
private String getURLValid (String url ) {
184
- java . net . URI uri ;
188
+ URI uri ;
185
189
try
186
190
{
187
- uri = new java . net . URI (url );
191
+ uri = new URI (url );
188
192
if (!uri .isAbsolute ()) // En caso que la URL pasada por parametro no sea una URL valida (en este caso seria que no sea un URL absoluta), salta una excepcion en esta linea, y se continua haciendo todo el proceso con los datos ya guardados como atributos
189
193
return url ;
190
194
else {
@@ -236,14 +240,12 @@ private static SSLConnectionSocketFactory getSSLSecureInstance() {
236
240
}
237
241
238
242
private CookieStore setAllStoredCookies () {
239
- ICookie [] webcookies ;
240
-
241
243
CookieStore cookiesToSend = new BasicCookieStore ();
242
- if (!com . genexus . ModelContext .getModelContext ().isNullHttpContext ()) { // Caso de ejecucion de varias instancia de HttpClientJavaLib, por lo que se obtienen cookies desde sesion web del browser
243
- webcookies = (( com . genexus . webpanels . HttpContextWeb ) com . genexus . ModelContext . getModelContext (). getHttpContext ()). getCookies ();
244
- ICookie webcookie = webcookies == null ? null : Arrays . stream ( webcookies ). filter ( cookie -> "Set-Cookie" . equalsIgnoreCase ( cookie . getName ())). findAny (). orElse ( null );
245
- if (webcookie != null )
246
- this .addHeader ("Cookie" , com . genexus . webpanels . WebUtils . decodeCookie ( webcookie . getValue () ));
244
+ if (!ModelContext .getModelContext ().isNullHttpContext ()) { // Caso de ejecucion de varias instancia de HttpClientJavaLib, por lo que se obtienen cookies desde sesion web del browser
245
+
246
+ String selfWebCookie = (( HttpContextWeb ) ModelContext . getModelContext (). getHttpContext ()). getCookie ( SET_COOKIE );
247
+ if (! selfWebCookie . isEmpty () )
248
+ this .addHeader (COOKIE , selfWebCookie . replace ( "+" , ";" ));
247
249
248
250
} else { // Caso se ejecucion de una misma instancia HttpClientJavaLib mediante command line
249
251
if (!getIncludeCookies ())
@@ -262,14 +264,14 @@ private CookieStore setAllStoredCookies() {
262
264
263
265
private void SetCookieAtr (CookieStore cookiesToSend ) {
264
266
if (cookiesToSend != null ) {
265
- if (com . genexus . ModelContext .getModelContext ().isNullHttpContext ()) {
267
+ if (ModelContext .getModelContext ().isNullHttpContext ()) {
266
268
for (Cookie c : cookiesToSend .getCookies ())
267
269
cookies .addCookie (c );
268
270
} else {
269
271
try {
270
- com . genexus . webpanels . HttpContextWeb webcontext = ((com . genexus . webpanels . HttpContextWeb ) com . genexus . ModelContext .getModelContext ().getHttpContext ());
272
+ HttpContextWeb webcontext = ((HttpContextWeb ) ModelContext .getModelContext ().getHttpContext ());
271
273
272
- Header [] headers = this .response .getHeaders ("Set-Cookie" );
274
+ Header [] headers = this .response .getHeaders (SET_COOKIE );
273
275
if (headers .length > 0 ) {
274
276
String webcontextCookieHeader = "" ;
275
277
for (Header header : headers ) {
@@ -278,9 +280,9 @@ private void SetCookieAtr(CookieStore cookiesToSend) {
278
280
webcontextCookieHeader += cookieKeyAndValue [0 ] + "=" + cookieKeyAndValue [1 ] + "; " ;
279
281
}
280
282
webcontextCookieHeader = webcontextCookieHeader .trim ().substring (0 ,webcontextCookieHeader .length ()-2 ); // Se quita el espacio y la coma al final
281
- webcontext .setCookie ("Set-Cookie" ,webcontextCookieHeader ,"" ,CommonUtil .nullDate (),"" ,this .getSecure ());
283
+ webcontext .setCookie (SET_COOKIE ,webcontextCookieHeader ,"" ,CommonUtil .nullDate (),"" ,this .getSecure ());
282
284
}
283
- com . genexus . ModelContext .getModelContext ().setHttpContext (webcontext );
285
+ ModelContext .getModelContext ().setHttpContext (webcontext );
284
286
} catch (Exception e ) {
285
287
e .printStackTrace ();
286
288
}
@@ -411,7 +413,7 @@ public void execute(String method, String url) {
411
413
}
412
414
413
415
url = setPathUrl (url );
414
- url = com . genexus . CommonUtil .escapeUnsafeChars (url );
416
+ url = CommonUtil .escapeUnsafeChars (url );
415
417
416
418
if (getSecure () == 1 ) // Se completa con esquema y host
417
419
url = url .startsWith ("https://" ) ? url : "https://" + getHost ()+ (getPort () != 443 ?":" +getPort ():"" )+ url ; // La lib de HttpClient agrega el port
@@ -447,7 +449,7 @@ public void execute(String method, String url) {
447
449
448
450
ByteArrayEntity dataToSend ;
449
451
if (!getIsMultipart () && getVariablesToSend ().size () > 0 )
450
- dataToSend = new ByteArrayEntity (com . genexus . CommonUtil .hashtable2query (getVariablesToSend ()).getBytes ());
452
+ dataToSend = new ByteArrayEntity (CommonUtil .hashtable2query (getVariablesToSend ()).getBytes ());
451
453
else
452
454
dataToSend = new ByteArrayEntity (getData ());
453
455
httpPost .setEntity (dataToSend );
@@ -594,7 +596,7 @@ public void getHeader(String name, java.util.Date[] value) {
594
596
return ;
595
597
try
596
598
{
597
- value [0 ] = com . genexus . CommonUtil .getHeaderAsDate (response .getFirstHeader (name ).getValue ());
599
+ value [0 ] = CommonUtil .getHeaderAsDate (response .getFirstHeader (name ).getValue ());
598
600
}
599
601
catch (IOException e )
600
602
{
@@ -619,7 +621,7 @@ public InputStream getInputStream() throws IOException {
619
621
public InputStream getInputStream (String stringURL ) throws IOException
620
622
{
621
623
try {
622
- java . net . URI url = new java . net . URI (stringURL );
624
+ URI url = new URI (stringURL );
623
625
HttpGet gISHttpGet = new HttpGet (String .valueOf (url ));
624
626
CloseableHttpClient gISHttpClient = HttpClients .createDefault ();
625
627
return gISHttpClient .execute (gISHttpGet ).getEntity ().getContent ();
0 commit comments