How can I send a GWT-RPC request with HttpClient? - java

I am using the Apache HTTPClient API to send HTTPRequests, and so far it's worked with standard requests. Now I want to send a GWT-RPC request and show the response, but I always receive the following error from the GWT-RPC server:
//EX[2,1,"com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533","This application is out of date, please click the refresh button on your browser. ( Malformed or old RPC message received - expecting version 5 )"],0,5]
Actually, I have to send the following data with the request:
5|0|5|http://172.16.103.244:38081/kunagi/scrum.ScrumGwtApplication/|6E611C647A0C98D5A31A2506E16D81D6|scrum.client.ScrumService|startConversation|I|1|2|3|4|1|5|-1|
but I don't know how.
When I retrieve the request code from FireBug, I find the above data as a source in the post area.

Take a look at the gwt-syncproxy project. It does exactly what you are looking for, faking RCP calls from Java code. If you don't want to rely your project on gwt-syncproxy, you could look at it's implementation and find out how the create valid requests.

Related

Is it possible to send body in GET request using rest-assured

I'm using rest-assured on my test automation project and in one of my calls I need to send body in GET request, is that possible to do it in rest-assured and if yes how?
No. GET requests don't have a body. They don't need one, because with a GET request you don't send data to the server, GET requests are for GETting data from the server. Take a look at PUT and POST requests to send data to the server.

Simulate form post using http client in Android app?

So, I'm currently developing an app for a service which has a json-based (unfortunately) read only API. Retrieving content is no problem at all, however the only way to post content is using a form on their site which location is a PHP script. The service is open source so I know which fields the form expects, but whatever I send, it always results in a BAD REQUEST.
I captured the network traffic inside my browser and as far as I can see, the browser constructs a multipart form request, however when I copy the request and invoke it again using a REST client, a BAD REQUEST gets returned.
Is there a way to construct a http request in Android that simulates a form post?
If it's readonly I think you wouldn't be able to make requests with POST (it's assume for editing or adding things).
If you let me make you an advise, I recommend you using this project as a Library.
https://github.com/matessoftwaresolutions/AndroidHttpRestService
It makes you easy deal with apis, control network problems etc.
You can find a sample of use there.
You only have to:
Build your URL
Tell the component to execute in POST mode
Build your JSON
As I told you, I don't know even if it will work.
I hope it helps!!!

Viewing SOAP request from Java client

I have built a Java client for an external web service. When I send a request using Eclipse I get a response, but it is not the response I expect. I think I have traced this to one of the fields (a date field), but I can't work out if it is on my side that the conversion is wrong or on theirs, only that the response returns a different date than the one I sent.
How can I see the SOAP request in the xml format that it is sent in to check how the date field is being sent to the external service?
You just need to use a Jax-WS interceptor/handler. They are very easy to write. Netbeans actually has great built in support for them. But if you want to write one from scratch, check out this question
You can use Wireshark. It's pretty easy. If you don't know how to use it just type "wireshark soap" in Google.

Is there a way to get the raw SOAP request from a SOAP based Web Service in a Java application

I am working on an application, that will pass client input to a vendor using web services. As phase I of the project, the vendor provided us with the XSD's and WSDL information. I used apache CXF to build the client jar. Now the issue I am facing is that, as part of the requirement, I need to send them the SOAP Request in an encrypted(I have taken care of the encryption part) XML file, that they will manually process, and send me back the response in another XML file that I need to parse and retrieve the response object.
Is there anyway to use the client jar in a dummy mode or something, where it looks like we are calling the client, but all we are doing is getting the raw SOAP request to a file
I kind of a hit a dead end and I am not totally sure how to proceed here, any help or suggestions would be appreciated
You might try SoapUI, it's a free web service testing tool. I know you can view the raw data of your soap request and response with it. soapUI

How to implement communication between Java client application (Android) and PHP server application?

I have a simple Java client application (Android app). I have to write a PHP server application which receives a request from the Java client application to write some data to a MySQL database or read some data from the MySQL database. It should respond with a status message (Write failed/success) or the data requested respectively.
How would I get the Java client send a request and receive the reply from the PHP program and how would the PHP program receive the request and send the reply? I have googled about SOAP and REST architectures, but looking for a simple tutorial which will allow me to implement this simple program.
Thanks.
With basic Java SE API you can use java.net.URLConnection to fire a HTTP request. A basic example of firing a GET request can be found in Sun tutorial on the subject. A POST request isn't much different, you instead just need to set URLConnection#setDoOutput() to true and write the query string to URLConnection#getOutputStream() instead of in URL.
Note that it's "lazily executed", the request will only be fired if you actually obtain the response stream by URLConnection#getInputStream(), even though you don't need it.
If you want less verbose code and/or more control over the request, then I can recommend to use Apache Commons HttpComponents Client.
The PHP program in turn can just be written the usual way. Get request parameters by $_GET, $_POST and so on and echo the response. Nothing special needs to be done here. You may however consider to use an more easy parseable response format, such as XML or JSON.
You should build a simple JSON or XML based REST web service with PHP.
Then with the Android SDK, you can use the HttpClient module to connect to your web service. The SDK also provide a JSON and XML module to parse the result.

Categories

Resources