remove http headers from response using java/camel - java

I need to remove the below headers from response that I sent to 3rd party.
$WSIS:
$WSPR: HTTP/1.1
$WSRA:
$WSRH:
$WSSC: http
$WSSN:
$WSSP:
Authorization:
What would be the best way to remove the HTTP headers from the response in Java or camel? We are using WAS 8.5 server.

There isa removeHeaders / removeHeader you can use. The former takes a pattern where you can remove using a wildcard pattern, eg removeHeader("$W*")

These headers are added by the WebSphere Plugin and not by Camel. Using removeHeader seems to be the only solution. The same worked for me...surely a good workaround but definitely not a solution..

Related

How to test ETags in Spring API with SOAPui?

I have tried to configure the ETags in my Spring REST API. As far as I understand, I just needed to add a filter, which with jetty server looks like:
servletContextHandler.addFilter(new FilterHolder(
new ShallowEtagHeaderFilter()) , "/*", EnumSet.allOf( DispatcherType.class ));
Then I started my SOApui and makde a request with a Etag header. When I got a responce, I resent the request with the If-None-Match header.
I supposed to receive an empty responce with 304 status code, but instead of this the responce was full, as if there is not any ETag thing at all.
Should I add something to Spring-Etag configuration? should I set something in SOAPui request?
Thank you in advance.
the problem was that I wanted to use both ETag and Spring Security. The last switches somehow the first off if by configuration the following line is not added:
http.headers().cacheControl().disable();

Caching Data with OKHttp

I'm trying to cache data with OKHttp's native cache; my problem is that I don't have control over the server side data, and the response header Cache-Control is coming back with a "no-cache" value.
Is there anyway to intercept the request to add in a header to cache the data that's coming back using OkHttp? (I'd also like to cache specific requests if possible).
Thank you!
Best Regards,
Christopher Steven
OkHttp doesn't currently offer a mechanism to defeat Cache-Control: no-cache. OkHttp will end up validating the response with the server, but if the server says the stored response is still good then the response body won't need to be retransmitted.
We've got a feature request outstanding that wants something like this, though it's difficult because it may mean a single request yields multiple responses.
Just in case anyone else comes across this 18 months late... you can now "defeat" Cache-Control: no-cache through adding an interceptor as a network interceptor (so it updates the server response before OkHttp processes it).
There is a good example on the OkHttp wiki at https://github.com/square/okhttp/wiki/Interceptors#rewriting-responses.
Hope this helps.

is there any tool to simulate http requests in java

I am trying to simulate HTTP requests in Java with the URL class and the HttpURLConnection class, the GET requests are easy to simulate while some POST requests seem harder because most POST request need Cookie in the request header. Some cookies were set by the HTTP response in the Set-Cookie field and I can get them by the function provided by HttpURLConnection, but I found that other cookies may be set by JavaScript and I have no way to handle them, so I wonder is there any packaged tool to simulate HTTP requests in Java?
try Apache commons Httpclient:
http://hc.apache.org/httpclient-3.x/
Why do you need to generate HTTP requests? Do you want to perform some stress tests?
I'd advise using something like JMeter (you can find a brief tutorial here).
Hope this helps something, it's better to avoid reinventing the wheel (if you need something like this, but it wasn't clear for me from your question).
For the cookie set with Javascript, you could try to parse the HTTP response, extract the cookie information and set it for your next request
For example, lets say, the response has code which calls a setCookie() function (setCookie is user-defined javascript function),
...
//some javascript code
setCookie("username", "johndoe");
//some more javascript
...
then you would extract the line setCookie() and the parse it for the name and value

Sending user data to server using http protocol

How can we send user data to server using http protocol by using other than Query string ?
Check out the Apache Commons HttpClient libraries.
The query string is used with HTTP GET requests.
You can also use HTTP POST request.
Here is a place to start: here
Use Http Post - Xml over Http Web Service.
Here is an example on how to POST some JSON and expect JSON back using the Resty library (I'm the author yadda yadda).
import static us.monoid.web.resty.Resty.*;
Resty r = new Resty();
r.json(url, content(myJsonObject));

Setting up a Restful POST request using xml

I'm working on setting up a RESTful request for the application I'm working on and I wanted to use xml as the request in the uri instead of allowing the client to supply the parameters in the URI itself.
I'm looking to have the URI like so: someurl/service/request
instead of: someurl/service/request?id={id}&name={name}
I have been searching the web to see what the convention should be when creating the POST request. Can anyone kind of help point me in the right direction on how I should set up this POST request allowing the client to use xml?
Not sure if it is relevant but I'm setting up the server side code in JAVA using the SPRING 3.0 framework. Please let me know if I need to supply more details.
Thanks for your help!!
You can put parameters into the body of the request. They are the same format as appending them to the URL. Eg:
POST /path/script.cgi HTTP/1.0
User-Agent: HTTPTool/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
home=Cosby&favorite+flavor=flies
You can do that in prototype pretty easily with:
new Ajax.Request('someurl/service', {
method: 'post',
postBody: 'home=Cosby&favorite+flavor=flies',
encoding: 'UTF-8'});
To add your xml file, just append it to your postBody with some sort of delimiter so your cgi knows where parameters end and where xml begins.
I think that's what you were looking for, hope it helps.
You can pass whatever you want in your POST body. So if you want to use XML, you can use XML. Example:
POST /car
Content-Type: text/xml
<car>
<date>10-10-2007<date>
<type>Corvette</type>
</car>
HTTP/1.1 201 CREATED
I think all the REST API frameworks let you easily specify XML in the client request and server response. See Restlet's quick start for an example.

Categories

Resources