List of usage examples for org.apache.commons.httpclient.methods ByteArrayRequestEntity ByteArrayRequestEntity
public ByteArrayRequestEntity(byte[] paramArrayOfByte, String paramString)
From source file:org.exjello.mail.Exchange2003Connection.java
private static RequestEntity createCustomInboxEntity(boolean unfiltered, String filterLastCheck, String filterFrom, String filterNotFrom, String filterTo) throws Exception { synchronized (Exchange2003Connection.class) { /*/*from w w w .j a v a2s . c o m*/ * If user has to use filter base on a adte we have to build a new * filter */ // if (customInboxEntity == null) { customInboxEntity = createSearchEntity( new String(getResource(GET_FILTERED_MESSAGES_SQL_RESOURCE), "UTF-8")); // } /* Mirco: Replace Filtes */ String filter = new String(customInboxEntity); if (!unfiltered) { filter = filter.replace(BOOKMARK_FILTER_UNREADED, "AND \"urn:schemas:httpmail:read\" = False"); } else { filter = filter.replace(BOOKMARK_FILTER_UNREADED, ""); } if (filterLastCheck != null && !"".equals(filterLastCheck)) { // Es. AND "urn:schemas:httpmail:datereceived" > // CAST("2010-08-04T00:00:00Z" as 'dateTime') filter = filter.replace(BOOKMARK_FILTER_LAST_CHECK, "AND \"urn:schemas:httpmail:datereceived\" > CAST(\"" + filterLastCheck + "\" as 'dateTime')"); } else { filter = filter.replace(BOOKMARK_FILTER_LAST_CHECK, ""); } if (filterFrom != null && !"".equals(filterFrom)) { // Es. AND "urn:schemas:httpmail:fromemail" LIKE '@domain.com%' filter = filter.replace(BOOKMARK_FILTER_FROM, "AND \"urn:schemas:httpmail:fromemail\" LIKE '%" + filterFrom + "%'"); } else { filter = filter.replace(BOOKMARK_FILTER_FROM, ""); } if (filterNotFrom != null && !"".equals(filterNotFrom)) { if (filterNotFrom.indexOf(";") > 0) { StringBuilder sb = new StringBuilder(); // sb.append("AND ("); for (String aFilter : filterNotFrom.split(";")) { sb.append("AND \"urn:schemas:httpmail:fromemail\" NOT LIKE '%" + aFilter + "%'"); } // sb.append(")"); filter = filter.replace(BOOKMARK_FILTER_NOT_FROM, sb.toString()); } else { // Es. AND "urn:schemas:httpmail:fromemail" LIKE // '@domain.com%' filter = filter.replace(BOOKMARK_FILTER_NOT_FROM, "AND \"urn:schemas:httpmail:fromemail\" NOT LIKE '%" + filterNotFrom + "%'"); } } else { filter = filter.replace(BOOKMARK_FILTER_NOT_FROM, ""); } if (filterTo != null && !"".equals(filterTo)) { // Es. AND "urn:schemas:httpmail:to" LIKE '%test@domain.com%' filter = filter.replace(BOOKMARK_FILTER_TO, "AND \"urn:schemas:httpmail:to\" LIKE '%" + filterTo + "%'"); } else { filter = filter.replace(BOOKMARK_FILTER_TO, ""); } customInboxEntity = filter.getBytes(); return new ByteArrayRequestEntity(customInboxEntity, XML_CONTENT_TYPE); } }
From source file:org.exjello.mail.Exchange2003Connection.java
private static RequestEntity createDeleteEntity(List<ExchangeMessage> messages) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);/*from www. j a v a 2s.co m*/ Document doc = dbf.newDocumentBuilder().newDocument(); Element delete = doc.createElementNS(DAV_NAMESPACE, "delete"); doc.appendChild(delete); Element target = doc.createElementNS(DAV_NAMESPACE, "target"); delete.appendChild(target); for (ExchangeMessage message : messages) { String url = message.getUrl(); Element href = doc.createElementNS(DAV_NAMESPACE, "href"); target.appendChild(href); String file = url.substring(url.lastIndexOf("/") + 1); href.appendChild(doc.createTextNode(file)); } ByteArrayOutputStream collector = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); transformer.transform(new DOMSource(doc), new StreamResult(collector)); return new ByteArrayRequestEntity(collector.toByteArray(), XML_CONTENT_TYPE); }
From source file:org.exjello.mail.Exchange2003Connection.java
private RequestEntity createAddBccEntity(Address[] addresses) throws Exception { StringBuilder recipientList = new StringBuilder(); for (Address address : addresses) { if (recipientList.length() != 0) recipientList.append(';'); recipientList.append(((InternetAddress) address).getAddress()); }/* ww w .j a v a 2 s.c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().newDocument(); Element propertyUpdate = doc.createElementNS(DAV_NAMESPACE, "propertyupdate"); doc.appendChild(propertyUpdate); Element set = doc.createElementNS(DAV_NAMESPACE, "set"); propertyUpdate.appendChild(set); Element prop = doc.createElementNS(DAV_NAMESPACE, "prop"); set.appendChild(prop); Element bcc = doc.createElementNS(MAILHEADER_NAMESPACE, "bcc"); prop.appendChild(bcc); bcc.appendChild(doc.createTextNode(recipientList.toString())); ByteArrayOutputStream collector = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); if (session.getDebug()) { transformer.transform(new DOMSource(doc), new StreamResult(session.getDebugOut())); session.getDebugOut().println(); } transformer.transform(new DOMSource(doc), new StreamResult(collector)); return new ByteArrayRequestEntity(collector.toByteArray(), XML_CONTENT_TYPE); }
From source file:org.exjello.mail.Exchange2003Connection.java
private static RequestEntity createMarkReadEntity(List<ExchangeMessage> messages) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);// w w w . ja v a 2 s .c o m Document doc = dbf.newDocumentBuilder().newDocument(); Element propertyUpdate = doc.createElementNS(DAV_NAMESPACE, "propertyupdate"); doc.appendChild(propertyUpdate); Element target = doc.createElementNS(DAV_NAMESPACE, "target"); propertyUpdate.appendChild(target); for (ExchangeMessage message : messages) { String url = message.getUrl(); Element href = doc.createElementNS(DAV_NAMESPACE, "href"); target.appendChild(href); String file = url.substring(url.lastIndexOf("/") + 1); href.appendChild(doc.createTextNode(file)); } Element set = doc.createElementNS(DAV_NAMESPACE, "set"); propertyUpdate.appendChild(set); Element prop = doc.createElementNS(DAV_NAMESPACE, "prop"); set.appendChild(prop); Element read = doc.createElementNS(HTTPMAIL_NAMESPACE, "read"); prop.appendChild(read); read.appendChild(doc.createTextNode("1")); ByteArrayOutputStream collector = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); transformer.transform(new DOMSource(doc), new StreamResult(collector)); return new ByteArrayRequestEntity(collector.toByteArray(), XML_CONTENT_TYPE); }
From source file:org.exjello.mail.ExchangeConnection.java
private static RequestEntity createFindInboxEntity() throws Exception { synchronized (ExchangeConnection.class) { if (findInboxEntity == null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().newDocument(); Element propfind = doc.createElementNS(DAV_NAMESPACE, "propfind"); doc.appendChild(propfind);//from ww w. j av a 2 s . c o m Element prop = doc.createElementNS(DAV_NAMESPACE, "prop"); propfind.appendChild(prop); Element inbox = doc.createElementNS(HTTPMAIL_NAMESPACE, "inbox"); prop.appendChild(inbox); Element drafts = doc.createElementNS(HTTPMAIL_NAMESPACE, "drafts"); prop.appendChild(drafts); Element sendmsg = doc.createElementNS(HTTPMAIL_NAMESPACE, "sendmsg"); prop.appendChild(sendmsg); Element outbox = doc.createElementNS(HTTPMAIL_NAMESPACE, "outbox"); prop.appendChild(outbox); Element sentitems = doc.createElementNS(HTTPMAIL_NAMESPACE, "sentitems"); prop.appendChild(sentitems); // http://msdn.microsoft.com/en-us/library/ms992623(EXCHG.65).aspx ByteArrayOutputStream collector = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); transformer.transform(new DOMSource(doc), new StreamResult(collector)); findInboxEntity = collector.toByteArray(); } return new ByteArrayRequestEntity(findInboxEntity, XML_CONTENT_TYPE); } }
From source file:org.exjello.mail.ExchangeConnection.java
private static RequestEntity createUnreadInboxEntity() throws Exception { synchronized (ExchangeConnection.class) { if (unreadInboxEntity == null) { unreadInboxEntity = createSearchEntity( new String(getResource(GET_UNREAD_MESSAGES_SQL_RESOURCE), "UTF-8")); }//from w w w . j a v a2 s.co m return new ByteArrayRequestEntity(unreadInboxEntity, XML_CONTENT_TYPE); } }
From source file:org.exjello.mail.ExchangeConnection.java
private static RequestEntity createAllInboxEntity() throws Exception { synchronized (ExchangeConnection.class) { if (allInboxEntity == null) { allInboxEntity = createSearchEntity( new String(getResource(GET_ALL_MESSAGES_SQL_RESOURCE), "UTF-8")); }//from w w w .j av a 2s .co m return new ByteArrayRequestEntity(allInboxEntity, XML_CONTENT_TYPE); } }
From source file:org.exjello.mail.ExchangeConnection.java
private static RequestEntity createCustomInboxEntity(boolean unfiltered, String filterLastCheck, String filterFrom, String filterNotFrom, String filterTo) throws Exception { synchronized (ExchangeConnection.class) { /*/*from www. j a va2s . c o m*/ * If user has to use filter base on a adte we have to build a new * filter */ // if (customInboxEntity == null) { customInboxEntity = createSearchEntity( new String(getResource(GET_FILTERED_MESSAGES_SQL_RESOURCE), "UTF-8")); // } /* Mirco: Replace Filtes */ String filter = new String(customInboxEntity); if (!unfiltered) { filter = filter.replace(BOOKMARK_FILTER_UNREADED, "AND \"urn:schemas:httpmail:read\" = False"); } else { filter = filter.replace(BOOKMARK_FILTER_UNREADED, ""); } if (filterLastCheck != null && !"".equals(filterLastCheck)) { // Es. AND "urn:schemas:httpmail:datereceived" > // CAST("2010-08-04T00:00:00Z" as 'dateTime') filter = filter.replace(BOOKMARK_FILTER_LAST_CHECK, "AND \"urn:schemas:httpmail:datereceived\" > CAST(\"" + filterLastCheck + "\" as 'dateTime')"); } else { filter = filter.replace(BOOKMARK_FILTER_LAST_CHECK, ""); } if (filterFrom != null && !"".equals(filterFrom)) { // Es. AND "urn:schemas:httpmail:fromemail" LIKE '@domain.com%' filter = filter.replace(BOOKMARK_FILTER_FROM, "AND \"urn:schemas:httpmail:fromemail\" LIKE '%" + filterFrom + "%'"); } else { filter = filter.replace(BOOKMARK_FILTER_FROM, ""); } if (filterNotFrom != null && !"".equals(filterNotFrom)) { if (filterNotFrom.indexOf(";") > 0) { StringBuilder sb = new StringBuilder(); // sb.append("AND ("); for (String aFilter : filterNotFrom.split(";")) { sb.append("AND \"urn:schemas:httpmail:fromemail\" NOT LIKE '%" + aFilter + "%'"); } // sb.append(")"); filter = filter.replace(BOOKMARK_FILTER_NOT_FROM, sb.toString()); } else { // Es. AND "urn:schemas:httpmail:fromemail" LIKE // '@domain.com%' filter = filter.replace(BOOKMARK_FILTER_NOT_FROM, "AND \"urn:schemas:httpmail:fromemail\" NOT LIKE '%" + filterNotFrom + "%'"); } } else { filter = filter.replace(BOOKMARK_FILTER_NOT_FROM, ""); } if (filterTo != null && !"".equals(filterTo)) { // Es. AND "urn:schemas:httpmail:to" LIKE '%test@domain.com%' filter = filter.replace(BOOKMARK_FILTER_TO, "AND \"urn:schemas:httpmail:to\" LIKE '%" + filterTo + "%'"); } else { filter = filter.replace(BOOKMARK_FILTER_TO, ""); } customInboxEntity = filter.getBytes(); return new ByteArrayRequestEntity(customInboxEntity, XML_CONTENT_TYPE); } }
From source file:org.intalio.tempo.workflow.fds.core.MessageSender.java
/** * Sends an XML request to a specific HTTP endpoint with a specific * <code>SOAPAction</code> header and returns the reply as XML. * /*from ww w. j a v a2 s .c o m*/ * @param requestMessage * The request XML payload. * @param endpoint * The endpoint URL, such as * <code>http://localhost/webservice</code> * @param soapAction * The <code>SOAPAction</code> to send the message with. * @return The reply from the endpoint as an XML <code>Document</code>. * @throws HttpException * If an HTTP-level error happens. * @throws IOException * If a low-level input/output error happens (e.g. a * disconnection during the request/response). * @throws DocumentException * @see <a href="http://www.w3.org/TR/soap/">The SOAP specification.</a> */ public Document requestAndGetReply(Document requestMessage, String endpoint, String soapAction) throws HttpException, IOException, DocumentException { Document result = null; PostMethod postMethod = new PostMethod(endpoint); postMethod.addRequestHeader("SOAPAction", soapAction); postMethod.setRequestEntity( new ByteArrayRequestEntity(requestMessage.asXML().getBytes(), "text/xml; charset=UTF-8")); HttpClient httpClient = new HttpClient(); // turn off retrying, since retrying SOAP requests can cause side-effects DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(0, false); httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); // set the timeout httpClient.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, FormDispatcherConfiguration.getInstance().getHttpTimeout()); // Prepare an XML parser SAXReader reader = new SAXReader(); InputStream responseInputStream = null; try { httpClient.executeMethod(postMethod); responseInputStream = postMethod.getResponseBodyAsStream(); result = reader.read(responseInputStream); } finally { postMethod.releaseConnection(); if (responseInputStream != null) responseInputStream.close(); } return result; }
From source file:org.mule.transport.http.HttpClientMessageDispatcher.java
protected HttpMethod createEntityMethod(MuleEvent event, Object body, EntityEnclosingMethod postMethod) throws TransformerException { HttpMethod httpMethod;/* ww w . j ava 2 s. c o m*/ if (body instanceof String) { httpMethod = (HttpMethod) sendTransformer.transform(body.toString()); } else if (body instanceof byte[]) { byte[] buffer = event.transformMessage(DataType.BYTE_ARRAY_DATA_TYPE); postMethod.setRequestEntity(new ByteArrayRequestEntity(buffer, event.getEncoding())); httpMethod = postMethod; } else { if (!(body instanceof OutputHandler)) { body = event.transformMessage(DataTypeFactory.create(OutputHandler.class)); } OutputHandler outputHandler = (OutputHandler) body; postMethod.setRequestEntity(new StreamPayloadRequestEntity(outputHandler, event)); postMethod.setContentChunked(true); httpMethod = postMethod; } return httpMethod; }