last day (14 days later) » 

9:24 AM
0
Q: Jersy Rest client to Apache CXF client Conversion

RameshI need to consume upload file API. I have created client using Jersy and it gives me proper response. Here is that sample code: final Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build(); FileDataBodyPart filePart = new FileDataBodyPart("file", new File("somePath/f...

 
How are you creating webClient? Seems the url is not correct
 
No URL is correct . I didnt add that code details in that code snippet .
 
What is the response code? Is the server responding?
 
In first code I am getting 200 response but in the CXF It s keep on loading and after some time I got connection lost . And If I give invalid path I am getting 404 error . So I think there is no problem with connection
 
Try to add to the client a LoggingInInterceptor and LoggingOutInterceptor to log the messages. You can check also if the request is really consumed by server
 
9:24 AM
I don have access to server . Anyhow I can say my request is reaching server in case of Jersy . So problem might be with CXF code .
 
In this case, I suggest to log the rest message (header and paylodad) of the oubound connection in both cases and review differences
 
If possible can u say me how to do that
 
Thanks . I got two logs . Here I am posting
Jul 21, 2016 2:29:49 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Sending client request on thread main
1 > POST http://stage2dmslvs08.qa.paypal.com:6502/cq5/apps/paypal/dms/api/2/ingestion.html
1 > Content-Type: multipart/form-data

Jul 21, 2016 2:29:50 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Client response received on thread main
1 < 200
1 < Content-Length: 203
1 < Content-Type: application/json
1 < Date: Thu, 21 Jul 2016 08:59:50 GMT
1 < X-Powered-By: Servlet/2.5 JSP/2.1
the above is rest log
Here is CXF log
ID: 1
Address: http://stage2dmslvs08.qa.paypal.com:6502/cq5/apps/paypal/dms/api/2/ingestion.html
Http-Method: POST
Content-Type: multipart/form-data; boundary="uuid:e08b2e50-eaa0-4599-88aa-804bd6fd48a7"
Headers: {Accept=[multipart/form-data], CORRELATION-ID=[a91e5505f8dcc], CAL_POOLSTACK=[causereadserv:v1.customers.givingfund*CalThreadId=146*TopLevelTxnStartTime=1560cbf8dcb*Host=LM-MAA-26500479*pid=21138], CLIENT_PID=[21138]}
Payload: --uuid:e08b2e50-eaa0-4599-88aa-804bd6fd48a7
Content-Type: application/octet-stream
 
Hi Ramesh
You have a 401 error code in CXF
It is an authentication issue
 
9:32 AM
but how it is working in Rest
Any idea , Anything I need to change
 
I do not see the credentials
How your host are requesting you the authentication credentials?
The jersey log do not show so much...
 
I need to send appId and clientApp in header it seems
but I am sending in body payload
I am guessing like so . Am I correct . Because in jersy I am doing like that
 
These fields are not in the headers of CXF, so probably it is the reason
add them when you configure the CXF WebClient
simply webClient.header(name,value)
 
oh I will look how to do that . Thanks for your help . I guess I need ur help some more time
Oh I ll try
 
ok, no problem.
I will include a summary in the answer!
 
9:43 AM
Sure
I need a one more help
multipart = (FormDataMultiPart) formDataMultiPart.field("clientApp", "causereadservuser").field("tidy", "true").field("appID", "009").bodyPart(filePart);
target.request().post(Entity.entity(multipart, multipart.getMediaType()));
This is how I am sending clientApp , appId value in Jersy which is responsible for authentication
How can I send those values in CFX like Jersy
 
 
3 hours later…
12:26 PM
Check this link
Maybe you need to use the MultipartBody class
check in the link, the method restfullyUploadRepository
You have there an example of a multipartbody with a File and form fields
 

last day (14 days later) »