Sending chunked requests using Tsung - chunked-encoding

Does anybody know how to send POST requests with 'Transfer-Encoding' set to 'chunked' in Tsung? Do I just set the header in my request?
If so, will Tsung automatically chunk the requests? Is the chunk size configurable?
Also is there some method to disable the "Content-Length" header? My application expects only one of Content-Length or Transfer-Encoding, not both.
EDIT:
Sorry, I should have provided some sample code. Here is the Tsung snippet I used:
<request subst="true">
<http url="/blah/blah" method="POST" contents="{ "source_ip": "%%_requestip%%", "source_port": "%%_requestport%%", "method": "%%_method%%", "url":"%%_myurl%%", "http_version":"1.1","user_info":[{"username":"%%_myusername%%","client_id": "%%_myclientid%%"}],"headers":[{"host": "%%_apiid%%"},{"Authorization":"Bearer %%_mytoken%%"},{"x-api-key":"%%_myapikey%%"},%%_myheaderid%%]}">
<http_header name="Head123" value="approxyhttpjkjdalsjdjasldjasldjlasjldjasdkjasljdlasjd"/>
<http_header name="Transfer-Encoding" value="chunked"/>
<http_header name="X-CorrelationID" value="Id-%%_requestid%%" />
<http_header name="Content-Type" value="application/text"/>
</http>
</request>
As shown above, I am setting a 'Transfer-Encoding' header in my request.
I have two requirements.
How do I tell Tsung to send chunked packets? Is it by setting the 'Transfer-Encoding: chunked' header?
How do I tell Tsung to NOT send a 'Content-Length' header in a POST request? My application cannot handle both Transfer-Encoding and Content-Length, it needs one or the other.

You can just override the header, see Doc's Changelog:
12.2.2. Changed
[TSUN-307] - Allow all HTTP headers to be overridden by
Read the Doc's, 6.2.2 HTTP:
New in 1.2.2: You can add any HTTP header now, as in:
<request> <http url="/bla" method="POST" contents="bla=blu&name=glop"> <www_authenticate userid="Aladdin" passwd="open sesame"/> <http_header name="Cache-Control" value="no-cache"/> <http_header name="Referer" value="http://www.w3.org/"/> </http> </request>

Related

Getting Jmeter to generate the boundary dashes in the Content-Type header (eg boundary=--V0a4bfux...)

This what my HTTP request is generating
Content-Type: multipart/form-data; boundary=V0a4bfuxfGhaH_Voo_Gu6oAEtj5FJNcp; charset=UTF-8
However, when compared to the POST data, it is lacking the 2 dashes in the front, which causes the server to reject the request:
--V0a4bfuxfGhaH_Voo_Gu6oAEtj5FJNcp
Content-Disposition: form-data; data="dataToBeSent"
--V0a4bfuxfGhaH_Voo_Gu6oAEtj5FJNcp--
How do I get Jmeter to generate the dashes in the header?
(besides from manually creating the multipart form)
Note:
I am using the 'Use multipart/formdata for POST' option.
If I intercept the request and manually add the dashes in the header, the
server accepts the request.
You don't need to generate these values, the solution is to tick Use multipart/form-data for POST box in the HTTP Request sampler (or in the HTTP Request Defaults)
If you have any definition of Content-Type header in the HTTP Header Manager - you need to remove it and let JMeter generate appropriate Content-Type header on its own.
The header doesn't need the dashes. This is simply how multipart/form-data works. The body is built as follows:
--<boundary>
<headers>
<content>
--<boundary>
<headers>
<content>
--<boundary>--
The -- part indicates a new part starts. The body ends with ---- to indicate no new parts will follow.

Consuming XML response from a REST call in Spring Integration

Seems to be a simple task but I cannot get my head around it.
I have a Spring integration chain which calls an external Webservice, which returns an XML. I would like to use that XML response in a downstream XpathRouter.
What expected-response-type should I use?
<int:chain input-channel="filesChannel">
<!-- ... some previous components in the chain -->
<int-http:outbound-gateway
http-method="POST"
url="http://web/service/url"
expected-response-type="java.lang.String" />
<int-xml:xpath-router default-output-channel="resultChannel">
<int-xml:xpath-expression expression="/order/status" />
<int-xml:mapping value="Error" channel="importErrorChannel" />
</int-xml:xpath-router>
</int:chain>
It doesn't seem like the xpath-router can consume the XML returned by the webservice. When I debug the router with a breakpoint on the following line:
Node node = this.converter.convertToNode(message.getPayload());
The node is null, although the message does contain valid XML.
Is it because I am not setting the right expected-response-type?
Here is the response XML I receive from the service:
<apiResponse version="1.0">
<orders>
<order>
<orderReference>test_2_3045342</orderReference>
<status>Error</status>
<errors>
<error>
<errorCode>1100</errorCode>
<errorMessage><![CDATA[ "Field is required: dropWindow" ]]></errorMessage>
</error>
</errors>
</order>
</orders>
</apiResponse>
Ok, I found my mistake - it was actually in the XPATH expression. It should have been //order/status to enable deep search.
The java.lang.String expected-response-type works just fine with XML XpathRouter.
Thanks

No Payload Detected when using JMeter with a REST Webservice and XML body

I am using JMeter to do load-testing. My test consists of a simple POST request. When I perform this request, the server, in its error logs, says No Payload Detected. I have verified that the server is receiving a Post request, and I have tried different texts in the Raw Post Body.
Next, to make sure it wasn't a problem with the server, I used a different Http Request program (Wiztools rest client) to send off a post with the same content. It works, and no No Payload Detected error is thrown.
My current theory is that both JMeter and the server do parsing. I know the server does, as it is looking for a small piece of data, and that JMeter's parsing ruins that small piece of data.
So, in conclusion, my question is "What parsing does JMeter do?".
I've looked for this answer, and the only thing I know that it does parse is ${VARNAME}.
The text I am sending is below:
<IpReport xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
<ProductReviewId>12345</ProductReviewId>
<DepartmentCode>ABC</DepartmentCode>
<ProductTitle>Test of a teaser</ProductTitle>
<ProjectId>2</ProjectId>
<ProductCodePD>ICS-1139150</ProductCodePD>
<Priority>Pre-Approved</Priority>
<Status>Approved</Status>
<IpStatus>Submitted</IpStatus>
<EvalStatus>Approved</EvalStatus>
<EvalNotes>No Limitations - message from eval</EvalNotes>
<Notes>Notes test</Notes>
<IsInClarity>true</IsInClarity>
<IsPreRelease>true</IsPreRelease>
<IsApproved>true</IsApproved>
<IsCOREvalIP>false</IsCOREvalIP>
<Elements>
<IpReportElement>
<IpReportElementLineItemId>21774</IpReportElementLineItemId>
<ElementType>ReportingStatement</ElementType>
<Contributor>Sample Contributor</Contributor>
<Description>test</Description>
<LocationInProduct>test</LocationInProduct>
<ReportingStatementId>7</ReportingStatementId>
<IpCodeId>3</IpCodeId>
<Links>
<IpReportLink>
<IpReportLinkId>25982</IpReportLinkId>
<Name>Link</Name>
<Url>https://example.org/</Url>
</IpReportLink>
</Links>
</IpReportElement>
</Elements>
<CustomData><site>ldsorg</site>
<site-root>/preview/ldsorg/</site-root>
<correlation-document-id>123456-eng</correlation-document-id>
<post-to-server>l12773:9239</post-to-server>
</CustomData>
<ApprovalNumber>2013-1139150-I</ApprovalNumber>
<EvalApprovalNumber>2013-1139150-E</EvalApprovalNumber>
</IpReport>
Here is an screenshot of JMeter. This is the only request, with no other config elements:
You may also need to add an HTTP Header Manager as a child of HTTP Request to set some header like content-type:
First of all. In your question above, both in screenshot and in request text part of request has symbols < and > encoded and part - not. And you are using Content Encoding = UTF-8 in addition. Seems that in this situation request will be sent malformed.
You can add e.g. View Results Tree listener and check how the request is sent from jmeter.
You can try dedicated REST Sampler as well.

JMSExpiration vs TimeToLive

I'm trying to set message expiration within a Blueprint XML Camel route. The value I want to set as the expiration is held within the message body (a protobuf).
Here's my code:-
<setHeader headerName="AMQ_SCHEDULED_DELAY">
<method bean="NotificationScheduler" method="postponeSending" />
</setHeader>
<setHeader headerName="JMSExpiration">
<method bean="NotificationScheduler" method="getExpiry" />
</setHeader>
<setHeader headerName="ExpirationTest">
<method bean="NotificationScheduler" method="getExpiry" />
</setHeader>
<to uri="activemq:notifications.splitter" />
As you can see from the screen shot below, I'm successfully setting two of the three headers but the setting for "JMSExpiration" (as per this thread) has had no effect.
I know I could alternatively use the Recipient List pattern to dynamically set the uri - i.e. pull the expiry out of the message data and append the ?timeToLive=... option. However, this seems a little clunky to me.
Is there a way to set expiration via setHeader within the XML?
Thanks,
J.
Change your uri to: activemq:notifications.splitter?preserveMessageQos=true and you should be fine.
Some JMS headers can be "manually" overriden like you are trying to by using this option.
Please note that you might want to take some precausion, since if you are listening on one JMS endpoint, the arriving messages will have JMS headers populated, and when you send the message out in your "to", the message will keep JMSDeliveryMode, JMSExpiration and JMSPriority. This might or might not be what you want.

How to retrieve XML into Oracle PL/SQL via an HTTP Post transaction?

I'm trying to implement the "blog this" function from Flickr using the BloggerAPI to my pl/sql based CMS.
When Flickr sends me the posting transaction, the HTTP transaction looks like this:
POST /pls/website/!pkg.procAPI HTTP/1.1
Host: www.mydomain.com
Accept: */*
User-Agent: Flickr
Content-Type: text/xml; charset=utf-8
Content-Length: 1220
Expect: 100-continue
<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>blogger.newPost</methodName>
<params>
<param><value><string>NO_APP_KEY</string></value></param>
<param><value><string>1</string></value></param>
<param><value><string>markj</string></value></param>
<param><value><string>markj</string></value></param>
<param><value><string>This is a test post from <a href="http://www.flickr.com/r/testpost"><img alt="flickr" src="http://www.flickr.com/images/flickr_logo_blog.gif" width="41" height="18" border="0" align="absmiddle" /></a>, a fancy photo sharing thing.</string></value></param>
<param><value><boolean>1</boolean></value></param>
</params>
</methodCall>
But my server is responding with an HTTP-400 Bad Request and the error message is "Signature Mismatch or Missing '='" and my pl/sql procedure never gets a chance to process the request. I suspect that the flexible parameter passing is getting hosed when looking at the message, but I don't know how else
The process to get the available blogs seems to work ok, but the content of the request doesn't have all the html entities as part of the message:
POST /pls/website/!pkg.procAPI HTTP/1.1
Host: www.mydomain.com
Accept: */*
User-Agent: Flickr
Content-Type: text/xml; charset=utf-8
Content-Length: 304
<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>blogger.getUsersBlogs</methodName>
<params>
<param><value><string>NO-APP-KEY</string></value></param>
<param><value><string>mark</string></value></param>
<param><value><string>markj</string></value></param>
</params>
</methodCall>
Is there a way to get the xml data from the body of the http request directly? or some other approach I'm over looking?
Thanks,
Mark.
I opened a service request with Oracle and they confirmed that mod_plsql does not support retrieving httpheader variables. Here is the discussion I had on the SR:
ISSUE ANALYSIS
I need to confirm it, but Mark conclusion so far looks right to me,i.e. MOD_PLSQL is always invoking and processing PLSQL procedures and there is no way to read the raw HTTP request because MOD_PLSQL parses the request and checks if there is a PLSQL procedure with this name and if there are arguments to pass. If there are no arguments to pass but we are providing something else like the XML document, MODPLSQL gets puzzled and thinks this is a new pair of parameter and value when this is not really the case.
ANSWER
No, it is not possible to do it because MOD_PLSQL just treats requests with parameters which can be parsed and translated as a PLSQL procedure call with several arguments. MOD_PLSQL has no concept of a "httprequest" variable containing the whole request in the same way java has the HTTPRequest object
ISSUE ANALYSIS
Got the confirmation unless we pass it as a parameter we can not read it from MOD_PLSQL. In other words, if we pass the XML page in the HTTP request body we need to use something like java where we can treat the request in raw mode and we can read any HTTP header and the http body without restrictions of any kind.
Can the xml be sent as a file attachment? In other words change:
Content-Type: text/xml; charset=utf-8
to
Content-Type: multipart/form-data, boundary=AaB03x
Then add this before the xml:
--AaB03x
content-disposition: form-data; name="xmlfile"; filename="myfile.xml"
Content-Type: text/xml
And this after the xml:
--AaB03x--
Now, you set up the procedure for a file upload, as explained in this article:
Files, Uploads, and Downloads with Web PLSQL
Use UTL_HTTP
You can use the UTL_HTTP package to do this.
UTL_HTTP.read_text(
r IN OUT NOCOPY resp,
data OUT NOCOPY VARCHAR2,
len IN PLS_INTEGER DEFAULT NULL);
"The UTL_HTTP package supports HTTP 1.1 chunked transfer-encoding. When the response body is returned in chunked transfer-encoding format as indicated in the response header, the package automatically decodes the chunks and returns the response body in de-chunked format."
http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96612/u_http.htm
I'm encountering the same issue MojoMark was (though with a different external application). MojoMark's follow up comment is correct, the read_text information does not answer the question.
Like MojoMark, I am attempting to RECEIVE a POST from an external entity. The PLSQL I'm trying to write is to receive that POST and store it.
I was able to write the outbound POST XML with no problem, but have been unable to set up a procedure to receive it.
The issue appears to be the PLSQL procedure wants a variable name, ie:
http://server/modplsql/testload, POST "data='data'"
However, the body of the POST is just an XML data stream, no "=" assigning a value to a parameter, so the function gets the "Mismatch or Missing '='"" error.
It seems like there should be a way to tell MODPLSQL to just accept accept the post data like a "typical" function call, but I think I'm missing something obvious.
The basics function I'm trying to use to receive the post is:
procedure testload ( DATA in clob ) as
BEGIN
htp.print('Input POST stream was ' || DATA )
end testload;
The only significant difference I can see between the two requests is the "Expect: 100-continue" business. This appers to be a clause in the HTTP 1.1 specification which allows the client to split the request in two. Basically, the client sends the header to the server, and the server must make a choice. If it is "happy" with the header it will give a HTTP 100 response to indicate that the rest of the message will be accepted.
Since you're getting data from Flickr, I'm not sure what level of control you have over the http requests being made by the client. From the server side it may be necessary to make a configuration change to Apache, or it may be a bug in mod_plsql that's popping up with the "!" flexible parameter marker.
Either way, the current blogger api is not like this. You probably should move to the new GData API.

Resources