Showing posts with label http. Show all posts
Showing posts with label http. Show all posts

Wednesday, October 11, 2017

JAX-RS tutorials and documentation

Here a reasoned discussion about CacheControl and ETag https://abhirockzz.wordpress.com/2016/03/27/efficient-jax-rs-conditional-gets-puts/

Here https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html all the HTTP 1.1 headers specifications


http://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/request-context/

deploy it in a PVRestRS project and hit it with http://localhost:8080/PVRestRS/users

it's an excellent simple example showing the use of:

http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Request.html


specifically, here http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Request.html#evaluatePreconditions-javax.ws.rs.core.EntityTag- some explanations on the use of an ETag.

http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/CacheControl.html


Some explanations on "what ETag is for?" here http://www.logicbig.com/quick-info/web/etag-header/

I open Chrome, STRL-SHIFT.I (developer tools) , Networks, select "users", right-click, console / Headers/all (it took me a lot of clicking to find it...) and I see this:


Request URL:http://localhost:8080/PVRestRS/users
Request Method:GET
Status Code:304 Not Modified
Remote Address:127.0.0.1:8080
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Date:Wed, 11 Oct 2017 00:31:57 GMT
Server:WildFly/11
X-Powered-By:Undertow/1
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:Idea-f3d396f=f1a96b31-981d-4574-a116-314fe061816e; __utma=111872281.364080227.1506531800.1506531800.1506531800.1; __utmc=111872281; __utmz=111872281.1506531800.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Host:localhost:8080
If-Modified-Since:Tue, 19 Sep 2017 22:00:00 GMT
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36


If I request http://localhost:8080/PVRestRS/users/pippo , I see also ETag:"version1" and (the second time only) If-None-Match:"version1"

"The If-None-Match request-header field is used with a method to make it conditional. A client that has one or more entities previously obtained from the resource can verify that none of those entities is current by including a list of their associated entity tags in the If-None-Match header field. The purpose of this feature is to allow efficient updates of cached information with a minimum amount of transaction overhead. It is also used to prevent a method (e.g. PUT) from inadvertently modifying an existing resource when the client believes that the resource does not exist. "


"1. If the response includes the "s-maxage" cache-control
directive, the cache MAY use that response in replying to a
subsequent request. But (if the specified maximum age has
passed) a proxy cache MUST first revalidate it with the origin
server, using the request-headers from the new request to allow
the origin server to authenticate the new request. (This is the
defined behavior for s-maxage.) If the response includes "s-
maxage=0", the proxy MUST always revalidate it before re-using
it."

"s-maxage
If a response includes an s-maxage directive, then for a shared cache (but not for a private cache), the maximum age specified by this directive overrides the maximum age specified by either the max-age directive or the Expires header. The s-maxage directive also implies the semantics of the proxy-revalidate directive (see section 14.9.4), i.e., that the shared cache must not use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server. The s- maxage directive is always ignored by a private cache. "


This book is on my to-read list https://leanpub.com/rest-assured-with-jaxrs


The excellent article about JAX-RS on Java Magazine jan/feb 2016 by Abishek is available here http://www.javamagazine.mozaicreader.com/JanFeb2016#&pageSet=32&page=0














Friday, April 8, 2016

Firebug for Chrome

As a Firefox user I have normally used Firebug to debug HTTP requests and trace the execution of a request.
In Chrome most people see to be happy with the Control-Shift-I (= “more tools” / “Developer tools”) , then in the Network tab, enable “preserve logs”


Sunday, April 3, 2016

HTTP/1.1 502 Bad Gateway

com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.io.IOException: Unable to tunnel through proxy. 
Proxy returns "HTTP/1.1 502 Bad Gateway" HTTP transport error: 
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 502 Bad Gateway" at 
com.sun.xml.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:141) at 
com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:187) at 
com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:124) at 
com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:118) at 
com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:866) at 
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:815) at 
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:778) at 
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:680) at 
com.sun.xml.ws.client.Stub.process(Stub.java:272) at 
com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:153) at 
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:115) at 
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:95) at 
com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:136) 



It's not clear what is causing this problem...



Wednesday, July 3, 2013

WebLogic webapplications returning HTTP 302 Moved Temporarily

If I configure a HTTPFRONTEND HOST to the LoadBalancer lbr.acme.com (5.6.7.8), when I contact directly a Managed Server myserver.acme.com in the cluster, results in a HTTP redirect with the new location pointing to the LoadBalancer.
I am struggling to find out how to disable this.


wget http://myserver.acme.com:8001/gridlinkha
--2013-07-03 13:40:15--  http://myserver.acme.com:8001/gridlinkha
Resolving myserver.acme.com... 1.2.3.4
Connecting to myserver.acme.com|1.2.3.4|:8001... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://lbr.acme.com/gridlinkha/ [following]
--2013-07-03 13:40:15--  http://lbr.acme.com/gridlinkha/
Resolving lbr.acme.com... 5.6.7.8
Connecting to lbr.acme.com|5.6.7.8|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1308 (1.3K) [text/html]
Saving to: `index.html'


setting max-redirect=0 makes the request fail altogether:

wget --max-redirect 0 http://myserver.acme.com:8001/gridlinkha
--2013-07-03 13:51:14--  http://myserver.acme.com:8001/gridlinkha
Resolving myserver.acme.com... 1.2.3.4
Connecting to myserver.acme.com|1.2.3.4|:8001... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://lbr.acme.com/gridlinkha/ [following]
0 redirections exceeded.