Parsing application/x-java-serialized-object response

soapUI pro announcements and discussions

Parsing application/x-java-serialized-object response

Postby JHoreczky » 04 Jul 2012 18:02

We are trying to use SoapUI Pro 4.5 for testing of a servlet. Submitting the request through SoapUI works well. The problem is the reading of the response. The servlet returns a response as an application/x-java-serialized-object. Is there any example available about how to parse this type of response? I understand that SoapUI is primarily for web services testing and it would be quite straightforward to write our test using Apache's HTTPClient in combination with Junit, however we are trying to leverage the data driven testing capabilities in SoapUI for the servlet testing.


Thanks,

Joseph H.
JHoreczky
User
 
Posts: 26
Joined: 17 Mar 2011 16:34

Re: Parsing application/x-java-serialized-object response

Postby SmartBear Support » 05 Jul 2012 07:21

Hi,

hmm... you could add a RegquestFilter.afterRequest event handler (in the Project windows' Events tab) that changes the response to be something more readable by soapUI - preferably an XML version of your Java Objects (which would allow you to assert, etc..). For example the following replaces any png with a short XML string:

if( request.response == null )
return

if( context.httpResponse.contentType == "image/png" )
{
// get response content
def content = context.httpResponse.responseContent

// manipulate content here...
log.info content

// write it back
context.httpResponse.responseContent = "<xml><text>this is a png!</text></xml>"
}

A similar script could be created to convert the serialized java object..

Hope this helps!

/Ole
SmartBear Software
SmartBear Support
Administrator
Administrator
 
Posts: 6705
Joined: 16 Feb 2009 10:53

Re: Parsing application/x-java-serialized-object response

Postby JHoreczky » 05 Jul 2012 23:55

Thanks Ole, for the update!

Unfortunately I was not able to find javadoc for the SoapUI Pro API, so mostly through trial and error I ended up using the following scriptlet to retrieve the request details. I tried using both REST and HTTP type of request - but they both gave the same result:

Trigger type: RequestFilter.filterRequest
=====
if( context == null ) {
log.info "returning context is ******* NULL"
return
}

log.info "[" + context.httpResponseProperties + "]"
=====

Interestingly the above will actually return the HTTP Request Query params - what I needed.

Thu Jul 05 16:24:53 MDT 2012:INFO: [[Street:theStreet, HouseNumberAndSuffix:123, Province:theProvince, City:theCity]]

Below is how the HTTP Post was logged by SoapUI :

Thu Jul 05 16:21:27 MDT 2012:DEBUG:>> "POST /theServlet?HouseNumberAndSuffix=123&Street=theStreet&City=theCity&Province=theProvince HTTP/1.1[\r][\n]"

My question, is this the proper way to get the request details?


Thanks,

Joseph H.
JHoreczky
User
 
Posts: 26
Joined: 17 Mar 2011 16:34

Re: Parsing application/x-java-serialized-object response

Postby SmartBear Support » 06 Jul 2012 21:59

Hi Joseph,

you can just use

request.getPropertyValue( "..." )

to get the value of a request parameter.

Please note that the event you are showing here (filterRequest) is invoked before the request is sent so it will not have access to the response as in the event (afterRequest) I used in my example.

regards!

/Ole
SmartBear Software
SmartBear Support
Administrator
Administrator
 
Posts: 6705
Joined: 16 Feb 2009 10:53

Re: Parsing application/x-java-serialized-object response

Postby JHoreczky » 06 Jul 2012 22:13

Hi Ole,

Thanks for the update!

I am using filterRequest for getting the request and afterRequest for getting the response, as I needed access to both, as I have to reformat them into XML document - primarily for logging and assertion purposes.

Where is the best place to add an assertion for the result? Should I include an assertion step and scripting the logic in groovy, or it is doable to configure the assertion through the default point and click procedure - since I converted the response from application/x-java-serialized-object into an XML format?


Thanks,

Joseph H.
JHoreczky
User
 
Posts: 26
Joined: 17 Mar 2011 16:34

Re: Parsing application/x-java-serialized-object response

Postby SmartBear Support » 07 Jul 2012 08:15

Hi,

yes - you should be able to use the default point-and-click actions in the outline editor of the response.

What you have done is pretty cool - would you be interested sharing it in a blog-post or something!? If you send me your code/project I can do the writing...

regards!

/Ole
SmartBear Software
SmartBear Support
Administrator
Administrator
 
Posts: 6705
Joined: 16 Feb 2009 10:53

Re: Parsing application/x-java-serialized-object response

Postby JHoreczky » 07 Jul 2012 08:45

Actually I anticipated that the conversion will be straightforward, but it wasn't. The problem is, as I see it, I am not able to find out the encoding of the application/x-java-serialized-object in the format that was returned by SoapUI.

In afterRequest:

def content = context.httpResponse.responseContent
log.info "in afterRequest:[" + content + "]"

In script Log:

Sat Jul 07 01:36:53 MDT 2012:INFO:in afterRequest:[¬í sr Lcom.abc.togw.services.lpq.clientsharedobjects.TogwLpqTierRespDto°ˆ½sŽ04 L clliCodet Ljava/lang/String;[
qualifierst P[Lcom/abc/togw/services/lpq/clientsharedobjects/TogwQualifierDescription;L twidthq ~ xppur P[Lcom.abc.togw.services.lpq.clientsharedobjects.TogwQualifierDescription;.ÒÁ¨ºœ2 xp sr Mcom.abc.togw.services.lpq.clientsharedobjects.TogwQualifierDescriptionx›³Õ§…I^ L
qualifierNameq ~ L qualifierValueq ~ xpt t UNDt -1]

Is there another method available in the SoapUI, that would give access to the HTTP response in a format that can be normally processed?


Thanks,

Joseph H.
JHoreczky
User
 
Posts: 26
Joined: 17 Mar 2011 16:34

Re: Parsing application/x-java-serialized-object response

Postby SmartBear Support » 08 Jul 2012 00:29

Hi,

try

response.rawResponseData

which returns a byte-array of the (complete) response..

regards

/Ole
SmartBear Software
SmartBear Support
Administrator
Administrator
 
Posts: 6705
Joined: 16 Feb 2009 10:53

Re: Parsing application/x-java-serialized-object response

Postby JHoreczky » 08 Jul 2012 23:07

Hi Ole,

The rawResponseData looks better but it still errors out when I try to read it as an object. Was the response of the servlet altered in some way before it was put into rawResponseData?

byte[] ba = context.httpResponse.rawResponseData
ByteArrayInputStream b = new ByteArrayInputStream(ba);
ObjectInputStream o = new ObjectInputStream(b)

The last line above generates an exception:
Sun Jul 08 15:54:13 MDT 2012:ERROR:java.io.StreamCorruptedException: invalid stream header: 48545450
java.io.StreamCorruptedException: invalid stream header: 48545450
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)


Obviously the object header information is incorrect, as per the error message.


Please let me know how to resolve this problem.


Thanks,

Joseph H.
JHoreczky
User
 
Posts: 26
Joined: 17 Mar 2011 16:34

Re: Parsing application/x-java-serialized-object response

Postby SmartBear Support » 09 Jul 2012 08:57

Hi,

the raw response contains the entire response, including the http headers - I think you need to parse out the actual body of the message (after the double linebreaks) into a separate byte-array and then use that as input..

/Ole
SmartBear Software
SmartBear Support
Administrator
Administrator
 
Posts: 6705
Joined: 16 Feb 2009 10:53

Re: Parsing application/x-java-serialized-object response

Postby JHoreczky » 09 Jul 2012 09:22

Thanks for the update! I am making progress - slowly :-(

I encountered a class loader problem. I tried both: 1) adding the jar that contains my javabean to the SoapUI's bin/ext folder, and 2) using the com.eviware.soapui.support.ClasspathHacker.addURL( new URL("file://" + myjarpath) ) to load the jar.

I both cases I got the following exception triggered by the import statement:

Mon Jul 09 01:46:35 MDT 2012:ERROR:org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 24: unable to resolve class com.abc.togw.services.lpql.clientsharedobjects.TogDto
@ line 24, column 1.
import com.abc.togw.services.lpql.clientsharedobjects.TogDto
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class com.abc.togw.services.lpql.clientsharedobjects.TogDto
@ line 24, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:148)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1240)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:148)

I know that I am importing the proper class in the proper jar, as I am running on the side a stand alone small java program for verification and that works.

Is there a utility method for printing out the complete classpath that is in effect when the import statement is executed?

The SoapUI log has this log entry written when the script runs:

Mon Jul 09 02:17:35 MDT 2012:INFO:Added [file://C:/Documents and Settings/SoapUI/LpQ-1.0.6.jar] to classpath


Thanks,

Joseph H.
JHoreczky
User
 
Posts: 26
Joined: 17 Mar 2011 16:34

Re: Parsing application/x-java-serialized-object response

Postby JHoreczky » 09 Jul 2012 10:06

Hi Ole,

Please disregard the last message. I had to use classpathHacker.addFile( myfile ) and then the import worked.

I am still working on a number of details, so it's too early yet for me to consider the sharing of the end to end solution, as I need to finish it first. If you are still interested - as you mentioned earlier in this thread - we can certainly discuss it.


Thanks,

Joseph H.
JHoreczky
User
 
Posts: 26
Joined: 17 Mar 2011 16:34


Return to soapUI Pro Support



cron