List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestEntity
public void setRequestEntity(RequestEntity paramRequestEntity)
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public String startAnalysis(String id, String language, List<String> options, InputStream body) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/analyze", DefaultRestResource.REST_URI); PostMethod postMethod = new PostMethod(uri); NameValuePair[] queryString = new NameValuePair[2 + options.size()]; queryString[0] = new NameValuePair("id", id); queryString[1] = new NameValuePair("language", language); int count = 2; for (String option : options) { queryString[count] = new NameValuePair("option", option); count++;//from www. ja v a 2 s. c o m } postMethod.setQueryString(queryString); RequestEntity requestEntity = new InputStreamRequestEntity(body); postMethod.setRequestEntity(requestEntity); try { httpClient.executeMethod(postMethod); return postMethod.getResponseBodyAsString(); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:com.intuit.tank.httpclient3.TankHttpClient3.java
@Override public void doPost(BaseRequest request) { try {//w w w.j a v a 2 s . c o m PostMethod httppost = new PostMethod(request.getRequestUrl()); String requestBody = request.getBody(); RequestEntity entity = null; if (BaseRequest.CONTENT_TYPE_MULTIPART.equalsIgnoreCase(request.getContentType())) { List<Part> parts = buildParts(request); entity = new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), httppost.getParams()); } else { entity = new StringRequestEntity(requestBody, request.getContentType(), request.getContentTypeCharSet()); } httppost.setRequestEntity(entity); sendRequest(request, httppost, requestBody); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:edu.ku.brc.specify.plugins.ipadexporter.IPadCloudJSONImpl.java
/** * @param valuesMap//from www .j ava2 s .co m * @return */ private synchronized JSONObject sendPost(final HashMap<String, String> valuesMap) { String writeURLStr = getWriteURL(); isNetworkError = false; // System.out.println(writeURLStr); // System.out.println("\n------------------------ "); // for (String k : valuesMap.keySet()) // { // System.out.println(String.format("[%s] [%s]", k, valuesMap.get(k))); // } // System.out.println("------------------------\n"+writeURLStr); //UIRegistry.showError("Cloud URL: "+writeURLStr); // Visual Debugging PostMethod post = new PostMethod(writeURLStr); try { Part[] parts = new Part[valuesMap.size()]; int i = 0; for (String key : valuesMap.keySet()) { //System.out.println("key["+key+"] val["+valuesMap.get(key)+"]"); String val = valuesMap.get(key); parts[i++] = new StringPart(key, val == null ? "" : val, "UTF-8"); } post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(15000); client.getParams().setParameter("http.protocol.content-charset", "UTF-8"); //System.out.println("CharSet: "+client.getParams().getHttpElementCharset()); client.getParams().setHttpElementCharset("UTF-8"); //System.out.println("CharSet: "+client.getParams().getHttpElementCharset()); int status = client.executeMethod(post); if (status == HttpStatus.SC_OK) { System.err.println("HTTP Status: OK"); String outStr = post.getResponseBodyAsString(); System.out.println("outStr[" + outStr + "]"); return JSONObject.fromObject(outStr); } System.err.println("HTTP Status: " + status); System.err.println(post.getResponseBodyAsString()); } catch (java.net.UnknownHostException uex) { isNetworkError = true; } catch (Exception ex) { System.out.println("Error: " + ex.getMessage()); ex.printStackTrace(); isNetworkError = true; } finally { post.releaseConnection(); } return null; }
From source file:com.zimbra.cs.client.soap.LmcSendMsgRequest.java
public String postAttachment(String uploadURL, LmcSession session, File f, String domain, // cookie domain e.g. ".example.zimbra.com" int msTimeout) throws LmcSoapClientException, IOException { String aid = null;//from ww w . ja v a2s . c o m // set the cookie. if (session == null) System.err.println(System.currentTimeMillis() + " " + Thread.currentThread() + " LmcSendMsgRequest.postAttachment session=null"); HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); PostMethod post = new PostMethod(uploadURL); ZAuthToken zat = session.getAuthToken(); Map<String, String> cookieMap = zat.cookieMap(false); if (cookieMap != null) { HttpState initialState = new HttpState(); for (Map.Entry<String, String> ck : cookieMap.entrySet()) { Cookie cookie = new Cookie(domain, ck.getKey(), ck.getValue(), "/", -1, false); initialState.addCookie(cookie); } client.setState(initialState); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); } post.getParams().setSoTimeout(msTimeout); int statusCode = -1; try { String contentType = URLConnection.getFileNameMap().getContentTypeFor(f.getName()); Part[] parts = { new FilePart(f.getName(), f, contentType, "UTF-8") }; post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); statusCode = HttpClientUtil.executeMethod(client, post); // parse the response if (statusCode == 200) { // paw through the returned HTML and get the attachment id String response = post.getResponseBodyAsString(); //System.out.println("response is\n" + response); int lastQuote = response.lastIndexOf("'"); int firstQuote = response.indexOf("','") + 3; if (lastQuote == -1 || firstQuote == -1) throw new LmcSoapClientException("Attachment post failed, unexpected response: " + response); aid = response.substring(firstQuote, lastQuote); } else { throw new LmcSoapClientException("Attachment post failed, status=" + statusCode); } } catch (IOException e) { System.err.println("Attachment post failed"); e.printStackTrace(); throw e; } finally { post.releaseConnection(); } return aid; }
From source file:com.celamanzi.liferay.portlets.rails286.OnlineClient.java
protected void createMultipartRequest(NameValuePair[] parametersBody, Map<String, Object[]> files, PostMethod method, List<File> tempFiles) throws IOException, FileNotFoundException { List<Part> parts = new ArrayList<Part>(); parametersBody = removeFileParams(parametersBody, files); for (NameValuePair param : parametersBody) { parts.add(createStringPart(param)); }// w w w .j ava 2s .c o m for (String key : files.keySet()) { File file = createFile(files.get(key)); if (file != null) { parts.add(new FilePart(key, file)); tempFiles.add(file); } } Part[] array = new Part[parts.size()]; method.setRequestEntity(new MultipartRequestEntity(parts.toArray(array), method.getParams())); method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); }
From source file:is.idega.block.finance.business.sp.SPDataInsertTest.java
private MultipartPostMethod sendCreateClaimsRequest() { /*/*from w w w .j a v a2 s . c om*/ * HttpClient client = new HttpClient(); client.setStrictMode(false); * MultipartPostMethod post = new MultipartPostMethod(SITE + * POST_METHOD); File file = new File(FILE_NAME); * * try { post.addParameter("notendanafn", "lolo7452");// "aistest"); * post.addParameter("password", "12345felix"); * post.addParameter("KtFelags", "6812933379");// "5709902259"); * post.addParameter("Skra", file); * * post.setDoAuthentication(false); client.executeMethod(post); * * System.out.println("responseString: " + * post.getResponseBodyAsString()); } catch (FileNotFoundException e1) { * e1.printStackTrace(); } catch (IOException e2) { * e2.printStackTrace(); } finally { post.releaseConnection(); } return * post; */ PostMethod filePost = new PostMethod(SITE + POST_METHOD); File file = new File(FILE_NAME); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { StringPart userPart = new StringPart("notendanafn", "lolo7452"); StringPart pwdPart = new StringPart("password", "12345felix"); StringPart clubssnPart = new StringPart("KtFelags", "6812933379"); FilePart filePart = new FilePart("Skra", file); Part[] parts = { userPart, pwdPart, clubssnPart, filePart }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK) { System.out.println("Upload complete, response=" + filePost.getResponseBodyAsString()); } else { System.out.println("Upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { ex.printStackTrace(); } finally { filePost.releaseConnection(); } return null; /* * PostMethod authpost = new PostMethod(SITE + POST_METHOD); * * authpost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, * true); try { * * HttpClient client = new HttpClient(); * client.getHttpConnectionManager().getParams().setConnectionTimeout( * 5000); * * File file = new File(FILE_NAME); // Prepare login parameters * NameValuePair inputFile = new NameValuePair("xmldata", file); * authpost.setRequestBody(new NameValuePair[] { inputFile }); * * int status = client.executeMethod(authpost); System.out.println("Form * post: " + authpost.getStatusLine().toString()); if (status == * HttpStatus.SC_OK) { System.out.println("Submit complete, response=" + * authpost.getResponseBodyAsString()); } else { * System.out.println("Submit failed, response=" + * HttpStatus.getStatusText(status)); } } catch (Exception ex) { * ex.printStackTrace(); } finally { authpost.releaseConnection(); } */ }
From source file:is.idega.block.finance.business.kb.KBDataInsert.java
/** * Sends a http multipart post method to KBBanki to create the claims * /* w ww .j av a 2s .c o m*/ * @param bfm * @param groupId * @return */ private void sendCreateClaimsRequest(BankFileManager bfm) { /* HttpClient client = new HttpClient(); MultipartPostMethod post = new MultipartPostMethod(POST_METHOD); File file = new File(FILE_NAME); System.out.println("!!!kb:"); System.out.println("username = " + bfm.getUsername()); System.out.println("password = " + bfm.getPassword()); try { post.addParameter("cguser", bfm.getUsername());// "IK66TEST" post.addParameter("cgpass", bfm.getPassword());// "KBIK66" post.addParameter("cgutli", "0"); post.addParameter("cgskra", file); post.setDoAuthentication(false); client.executeMethod(post); System.out.println("responseString: " + post.getResponseBodyAsString()); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e2) { e2.printStackTrace(); } finally { post.releaseConnection(); } return post;*/ PostMethod filePost = new PostMethod(POST_METHOD); File file = new File(FILE_NAME); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { StringPart userPart = new StringPart("cguser", bfm.getUsername()); StringPart pwdPart = new StringPart("password", bfm.getPassword()); StringPart clubssnPart = new StringPart("cgclaimBatchName", batchName); FilePart filePart = new FilePart("cgskra", file); Part[] parts = { userPart, pwdPart, clubssnPart, filePart }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK) { System.out.println("Upload complete, response=" + filePost.getResponseBodyAsString()); } else { System.out.println("Upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { ex.printStackTrace(); } finally { filePost.releaseConnection(); } }
From source file:cdr.forms.SwordDepositHandler.java
public DepositResult deposit(Deposit deposit) { // Prepare the submission package Submission submission = Submission.create(deposit, this); File zipFile = makeZipFile(submission.getMetsDocumentRoot(), submission.getFiles()); // Obtain the path for the collection in which we'll attempt to make the deposit Form form = deposit.getForm();/*from w w w .j ava2 s .c o m*/ String containerId = form.getDepositContainerId(); if (containerId == null || "".equals(containerId.trim())) containerId = this.getDefaultContainer(); String depositPath = getServiceUrl() + "collection/" + containerId; // Make the SWORD request String pid = "uuid:" + UUID.randomUUID().toString(); HttpClient client = new HttpClient(); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.getUsername(), this.getPassword()); client.getState().setCredentials(getAuthenticationScope(depositPath), creds); client.getParams().setAuthenticationPreemptive(true); PostMethod post = new PostMethod(depositPath); RequestEntity fileRequestEntity = new FileRequestEntity(zipFile, "application/zip"); Header contentDispositionHeader = new Header("Content-Disposition", "attachment; filename=package.zip"); post.addRequestHeader(contentDispositionHeader); Header packagingHeader = new Header("Packaging", "http://cdr.unc.edu/METS/profiles/Simple"); post.addRequestHeader(packagingHeader); Header slugHeader = new Header("Slug", pid); post.addRequestHeader(slugHeader); post.setRequestEntity(fileRequestEntity); // Interpret the response from the SWORD endpoint DepositResult result = new DepositResult(); try { // Set the result's status based on the HTTP response code int responseCode = client.executeMethod(post); if (responseCode >= 300) { LOG.error(String.valueOf(responseCode)); LOG.error(post.getResponseBodyAsString()); result.setStatus(Status.FAILED); } else { result.setStatus(Status.COMPLETE); } // Save the response body result.setResponseBody(post.getResponseBodyAsString()); // Assign additional attributes based on the response body. try { Namespace atom = Namespace.getNamespace("http://www.w3.org/2005/Atom"); SAXBuilder sx = new SAXBuilder(); org.jdom.Document d = sx.build(post.getResponseBodyAsStream()); // Set accessURL to the href of the first <link rel="alternate"> inside an Atom entry if (result.getStatus() == Status.COMPLETE) { if (d.getRootElement().getNamespace().equals(atom) && d.getRootElement().getName().equals("entry")) { @SuppressWarnings("unchecked") List<Element> links = d.getRootElement().getChildren("link", atom); for (Element link : links) { if ("alternate".equals(link.getAttributeValue("rel"))) { result.setAccessURL(link.getAttributeValue("href")); break; } } } } } catch (JDOMException e) { LOG.error("There was a problem parsing the SWORD response.", e); } LOG.debug("response was: \n" + post.getResponseBodyAsString()); } catch (HttpException e) { LOG.error("Exception during SWORD deposit", e); throw new Error(e); } catch (IOException e) { LOG.error("Exception during SWORD deposit", e); throw new Error(e); } return result; }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies/* w w w .jav a2 s .c o m*/ * the previous requests cookies to keep in the same session. * @throws MojoExecutionException * if any error occurs during this process. */ @SuppressWarnings("deprecation") private void uploadPackage(final Cookie[] cookies) throws MojoExecutionException { PostMethod filePost = new PostMethod(crxPath + "/packmgr/list.jsp"); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("Uploading " + jarfile + " to " + filePost.getPath()); File jarFile = new File(jarfile); Part[] parts = { new FilePart("file", jarFile) }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); int status = client.executeMethod(filePost); // log the status getLog().info( "Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); if (status == HttpStatus.SC_MOVED_TEMPORARILY) { getLog().info("Upload complete"); } else { logResponseDetails(filePost); throw new MojoExecutionException( "Package upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { filePost.releaseConnection(); } }
From source file:com.seer.datacruncher.services.ServiceScheduledJob.java
@Override protected synchronized void executeInternal(JobExecutionContext arg0) throws JobExecutionException { long jobId = arg0.getJobDetail().getJobDataMap().getLong("jobId"); JobsEntity jobEntity = jobsDao.find(jobId); if (!jobEntity.isWorking()) { if (jobsDao.setWorkStatus(jobId, true)) { try { long eventTriggerId = arg0.getJobDetail().getJobDataMap().getString("eventTriggerId") == null ? -1l//from w w w .j a v a 2 s. co m : Long.parseLong(arg0.getJobDetail().getJobDataMap().getString("eventTriggerId")); if (eventTriggerId > 0) { EventTriggerEntity entity = eventTriggerDao.findEventTriggerById(eventTriggerId); String className = entity.getName(); try { String sourceCode = entity.getCode(); EventTrigger eventTrigger; String response; eventTrigger = (EventTrigger) CommonUtils.getClassInstance(className, "com.seer.datacruncher.eventtrigger.EventTrigger", EventTrigger.class, sourceCode); assert eventTrigger != null; response = eventTrigger.trigger(); log.info("Response From EventTrigger(" + className + ") :" + response); } catch (Exception e) { e.printStackTrace(); log.error("EventTrigger(" + className + ") :" + e.getMessage(), e); logDao.setErrorLogMessage("EventTrigger(" + className + ") :" + e.getMessage()); } catch (NoClassDefFoundError err) { log.error("EventTrigger(" + className + ") :" + err.getMessage(), err); logDao.setErrorLogMessage("EventTrigger(" + className + ") :" + err.getMessage()); } return; } int day = arg0.getJobDetail().getJobDataMap().getString("day") == null ? -1 : Integer.parseInt(arg0.getJobDetail().getJobDataMap().getString("day")); int month = arg0.getJobDetail().getJobDataMap().getString("month") == null ? -1 : Integer.parseInt(arg0.getJobDetail().getJobDataMap().getString("month")); if ((day > 0 && day != Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) || (month > 0 && month != (Calendar.getInstance().get(Calendar.MONTH) + 1))) { return; } StandardFileSystemManager fsManager = new StandardFileSystemManager(); boolean isDataStream = true; try { fsManager.init(); long schemaId = arg0.getJobDetail().getJobDataMap().getLong("schemaId"); long schedulerId = arg0.getJobDetail().getJobDataMap().getLong("schedulerId"); //long jobId = arg0.getJobDetail().getJobDataMap().getLong("jobId"); long connectionId = arg0.getJobDetail().getJobDataMap().getLong("connectionId"); String datastream = ""; int idSchemaType = schemasDao.find(schemaId).getIdSchemaType(); TasksEntity taskEntity = tasksDao.find(schedulerId); //JobsEntity jobEntity = jobsDao.find(jobId); if (taskEntity.getIsOneShoot()) { jobEntity.setIsActive(0); jobsDao.update(jobEntity); } if (idSchemaType == SchemaType.GENERATION) { StreamGenerationUtils sgu = new StreamGenerationUtils(); datastream = sgu.getStream(schemaId); log.debug("Content stream: " + schemaId); if (datastream.trim().length() > 0) { log.debug("Datastream to validate: " + datastream); DatastreamsInput datastreamsInput = new DatastreamsInput(); String result = datastreamsInput.datastreamsInput(datastream, schemaId, null); log.debug("Validation result: " + result); } else { isDataStream = false; log.debug("No datastream create"); } } if (connectionId != 0) { int serviceId = Integer .parseInt(arg0.getJobDetail().getJobDataMap().getString("serviceId")); String hostName = arg0.getJobDetail().getJobDataMap().getString("ftpServerIp"); String port = arg0.getJobDetail().getJobDataMap().getString("port"); String userName = arg0.getJobDetail().getJobDataMap().getString("userName"); String password = arg0.getJobDetail().getJobDataMap().getString("password"); String inputDirectory = arg0.getJobDetail().getJobDataMap().getString("inputDirectory"); String fileName = arg0.getJobDetail().getJobDataMap().getString("fileName"); ConnectionsEntity conn; conn = connectionsDao.find(connectionId); if (inputDirectory == null || inputDirectory.trim().length() == 0) { inputDirectory = fileName; } else if (!(conn.getIdConnType() == GenericType.uploadTypeConn && serviceId == Servers.HTTP.getDbCode())) { inputDirectory = inputDirectory + "/" + fileName; } log.info("(jobId:" + jobEntity.getName() + ") - Trying to Server polling at server [" + hostName + ":" + port + "] with user[" + userName + "]."); String url = ""; if (serviceId == Servers.SAMBA.getDbCode()) { if (!fsManager.hasProvider("smb")) { fsManager.addProvider("smb", new SmbFileProvider()); } url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory; } else if (serviceId == Servers.HTTP.getDbCode()) { if (!fsManager.hasProvider("http")) { fsManager.addProvider("http", new HttpFileProvider()); } url = "http://" + hostName + ":" + port + "/" + inputDirectory; } else if (serviceId == Servers.FTP.getDbCode()) { if (!fsManager.hasProvider("ftp")) { fsManager.addProvider("ftp", new FtpFileProvider()); } url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory; } log.info("url:" + url); final FileObject fileObject = fsManager.resolveFile(url); if (conn.getIdConnType() == GenericType.DownloadTypeConn) { if (conn.getFileDateTime() != null && conn.getFileDateTime().getTime() == fileObject .getContent().getLastModifiedTime()) { log.info("There is no New or Updated '" + fileName + "' file on server to validate. Returning ..."); return; } else { log.info("There is New or Updated '" + fileName + "' file on server to validate. Validating ..."); ConnectionsEntity connection = connectionsDao.find(connectionId); connection.setFileDateTime( new Date(fileObject.getContent().getLastModifiedTime())); ApplicationContext ctx = AppContext.getApplicationContext(); ConnectionsDao connDao = (ctx.getBean(ConnectionsDao.class)); if (connDao != null) { connDao.update(connection); } Map<String, byte[]> resultMap = new HashMap<String, byte[]>(); byte data[] = new byte[(int) fileObject.getContent().getSize()]; fileObject.getContent().getInputStream().read(data); resultMap.put(fileObject.getName().getBaseName(), data); Set<String> keySet = resultMap.keySet(); Iterator<String> itr = keySet.iterator(); while (itr.hasNext()) { String strFileName = itr.next(); String result = ""; try { Long longSchemaId = schemaId; SchemaEntity schemaEntity = schemasDao.find(longSchemaId); if (schemaEntity == null) { result = "No schema found in database with Id [" + longSchemaId + "]"; log.error(result); logDao.setErrorLogMessage(result); } else { if (strFileName.endsWith(FileExtensionType.ZIP.getAbbreviation())) { // Case 1: When user upload a Zip file - All ZIP entries should be validate one by one ZipInputStream inStream = null; try { inStream = new ZipInputStream( new ByteArrayInputStream(resultMap.get(fileName))); ZipEntry entry; while (!(isStreamClose(inStream)) && (entry = inStream.getNextEntry()) != null) { if (!entry.isDirectory()) { DatastreamsInput datastreamsInput = new DatastreamsInput(); datastreamsInput .setUploadedFileName(entry.getName()); byte[] byteInput = IOUtils.toByteArray(inStream); result += datastreamsInput.datastreamsInput( new String(byteInput), longSchemaId, byteInput); } inStream.closeEntry(); } log.debug(result); } catch (IOException ex) { result = "Error occured during fetch records from ZIP file."; log.error(result); logDao.setErrorLogMessage(result); } finally { if (inStream != null) inStream.close(); } } else { DatastreamsInput datastreamsInput = new DatastreamsInput(); datastreamsInput.setUploadedFileName(strFileName); result = datastreamsInput.datastreamsInput( new String(resultMap.get(strFileName)), longSchemaId, resultMap.get(strFileName)); log.debug(result); } } } catch (Exception ex) { ex.printStackTrace(); result = "Exception occured during process the message for xml file " + strFileName + " Error - " + ex.getMessage(); log.error(result); logDao.setErrorLogMessage(result); } } } } else if (isDataStream && (conn.getIdConnType() == GenericType.uploadTypeConn)) { File uploadFile = File.createTempFile(fileName, ".tmp"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(uploadFile)); bw.write(datastream); bw.flush(); bw.close(); } catch (IOException ioex) { log.error("Datastream file can't be created"); logDao.setErrorLogMessage("Datastream file can't be created"); return; } if (serviceId == Servers.HTTP.getDbCode()) { try { HttpClient httpclient = new HttpClient(); PostMethod method = new PostMethod(url); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); Part[] parts = new Part[] { new FilePart("file", uploadFile.getName(), uploadFile) }; method.setRequestEntity( new MultipartRequestEntity(parts, method.getParams())); method.setDoAuthentication(true); int statusCode = httpclient.executeMethod(method); String responseBody = new String(method.getResponseBody()); if (statusCode != HttpStatus.SC_OK) { throw new HttpException(method.getStatusLine().toString()); } else { System.out.println(responseBody); } method.releaseConnection(); } catch (Exception ex) { log.error("Exception occurred during uploading of file at HTTP Server: " + ex.getMessage()); logDao.setErrorLogMessage( "Exception occurred during uploading of file at HTTP Server: " + ex.getMessage()); } } else { try { FileObject localFileObject = fsManager .resolveFile(uploadFile.getAbsolutePath()); fileObject.copyFrom(localFileObject, Selectors.SELECT_SELF); System.out.println("File uploaded at : " + new Date()); if (uploadFile.exists()) { uploadFile.delete(); } } catch (Exception ex) { log.error( "Exception occurred during uploading of file: " + ex.getMessage()); logDao.setErrorLogMessage( "Exception occurred during uploading of file: " + ex.getMessage()); } } } } } catch (Exception ex) { log.error("Error " + ": " + ex.getMessage()); } finally { fsManager.close(); } } finally { jobsDao.setWorkStatus(jobId, false); } } else { log.error("Can not set " + jobEntity.getName() + "working."); } } else { log.debug("Job " + jobEntity.getName() + " is working."); } }