Following code solved the issue HttpClient httpclient = HttpClientBuilder.create().build();; HttpPost httppost = new HttpPost(endpoint);
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addPart(PARAM_NAME_FILEUPLOAD, new FileBody(uploadArtifact)); builder.addPart(PARAM_NAME_ACTION, new StringBody(CREATE_APPLICATION_ACTION, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_APPLICATION_NAME, new StringBody(applicationName, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_APPLICATION_DESCRIPTION, new StringBody(applicationDescription, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_RUNTIME, new StringBody(runtime, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_APP_TYPE_NAME, new StringBody(appTypeName, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_APPLICATION_REVISION, new StringBody(applicationVersion, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_UPLOADED_FILE_NAME, new StringBody(uploadedFileName, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_PROPERTIES, new StringBody(runtimeProperties, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_TAGS, new StringBody(tags, ContentType.TEXT_PLAIN)); builder.addPart(PARAM_NAME_IS_FILE_ATTACHED, new StringBody(Boolean.TRUE.toString(), ContentType.TEXT_PLAIN));//Setting true to send the file in request httppost.setEntity(builder.build()); httppost.setHeader(HEADER_COOKIE, getRequestHeaders().get(HEADER_COOKIE)); org.apache.http.HttpResponse response = httpclient.execute(httppost); Thanks & Regards Danushka Fernando Senior Software Engineer WSO2 inc. http://wso2.com/ Mobile : +94716332729 On Thu, Mar 10, 2016 at 2:38 PM, Manjula Rathnayake <[email protected]> wrote: > Hi Danushka, > > We need to avoid deprecated code as much as possible. What is the > alternative provided by the API? Can we use the latest http client? > > thank you. > > On Thu, Mar 10, 2016 at 2:28 PM, Danushka Fernando <[email protected]> > wrote: > >> Was trying with the Automation utils. But couldn't do this so I >> implemented following code (Working) with httpclient. But only concern is >> there are lot of depcrated classes used here. So are there any better way >> to implement this. >> @Manjula : any concerns? >> >> HttpClient httpclient = new DefaultHttpClient(); >> >> HttpPost httppost = new HttpPost(endpoint); >> >> MultipartEntity reqEntity = new MultipartEntity(); >> reqEntity.addPart(PARAM_NAME_FILEUPLOAD, new FileBody(uploadArtifact)); >> reqEntity.addPart(PARAM_NAME_ACTION, new >> StringBody(CREATE_APPLICATION_ACTION)); >> reqEntity.addPart(PARAM_NAME_APPLICATION_NAME, new >> StringBody(applicationName)); >> reqEntity.addPart(PARAM_NAME_APPLICATION_DESCRIPTION, new >> StringBody(applicationDescription)); >> reqEntity.addPart(PARAM_NAME_RUNTIME, new StringBody(runtime)); >> reqEntity.addPart(PARAM_NAME_APP_TYPE_NAME, new StringBody(appTypeName)); >> reqEntity.addPart(PARAM_NAME_APPLICATION_REVISION, new >> StringBody(applicationVersion)); >> reqEntity.addPart(PARAM_NAME_UPLOADED_FILE_NAME, new >> StringBody(uploadedFileName)); >> reqEntity.addPart(PARAM_NAME_PROPERTIES, new StringBody(runtimeProperties)); >> reqEntity.addPart(PARAM_NAME_TAGS, new StringBody(tags)); >> reqEntity.addPart(PARAM_NAME_IS_FILE_ATTACHED, new >> StringBody(Boolean.TRUE.toString()));//Setting true to send the file in >> request >> >> httppost.setEntity(reqEntity); >> >> httppost.setHeader(HEADER_COOKIE, getRequestHeaders().get(HEADER_COOKIE)); >> >> org.apache.http.HttpResponse response = httpclient.execute(httppost); >> >> >> Thanks & Regards >> Danushka Fernando >> Senior Software Engineer >> WSO2 inc. http://wso2.com/ >> Mobile : +94716332729 >> >> On Thu, Mar 10, 2016 at 12:28 PM, Manuranga Perera <[email protected]> wrote: >> >>> Does it work if you upload through the browser? >>> If yes, put tcpmon in-front and see how your request is different form >>> the browser request. >>> >>> On Thu, Mar 10, 2016 at 11:38 AM, Danushka Fernando <[email protected]> >>> wrote: >>> >>>> Hi All >>>> I am trying to do $subject for a test case. Tried with sending the file >>>> and the file input stream. Both didn't work. What should I send here. In >>>> Jaggery side its retrieving by request.getFile(). >>>> >>>> Thanks & Regards >>>> Danushka Fernando >>>> Senior Software Engineer >>>> WSO2 inc. http://wso2.com/ >>>> Mobile : +94716332729 >>>> >>> >>> >>> >>> -- >>> With regards, >>> *Manu*ranga Perera. >>> >>> phone : 071 7 70 20 50 >>> mail : [email protected] >>> >> >> > > > -- > Manjula Rathnayaka > Associate Technical Lead > WSO2, Inc. > Mobile:+94 77 743 1987 >
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
