Java Code Examples for org.apache.http.entity.ContentType#APPLICATION_XML

The following examples show how to use org.apache.http.entity.ContentType#APPLICATION_XML . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Notification.java    From azure-notificationhubs-java-backend with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to set up a native notification for WNS. Sets the
 * X-WNS-Type headers based on the body provided. If you want to send raw
 * notifications you have to set the X-WNS header and ContentType after creating this
 * notification or use createWindowsRawNotification method
 * 
 * @param body
 * @return
 */
public static Notification createWindowsNotification(String body) {
	Notification n = new Notification();
	n.body = body;

	n.headers.put("ServiceBusNotification-Format", "windows");

	if (body.contains("<toast>"))
		n.headers.put("X-WNS-Type", "wns/toast");
	if (body.contains("<tile>"))
		n.headers.put("X-WNS-Type", "wns/tile");
	if (body.contains("<badge>"))
		n.headers.put("X-WNS-Type", "wns/badge");

	if (body.startsWith("<")) {
		n.contentType = ContentType.APPLICATION_XML;
	}

	return n;
}
 
Example 2
Source File: Notification.java    From azure-notificationhubs-java-backend with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to set up a native notification for MPNS. Sets the
 * X-WindowsPhone-Target and X-NotificationClass headers based on the body
 * provided. Raw notifications are not supported for MPNS.
 * 
 * @param body
 * @return
 */
public static Notification createMpnsNotifiation(String body) {
	Notification n = new Notification();
	n.body = body;

	n.headers.put("ServiceBusNotification-Format", "windowsphone");

	if (body.contains("<wp:Toast>")) {
		n.headers.put("X-WindowsPhone-Target", "toast");
		n.headers.put("X-NotificationClass", "2");
	}
	if (body.contains("<wp:Tile>")) {
		n.headers.put("X-WindowsPhone-Target", "tile");
		n.headers.put("X-NotificationClass", "1");
	}

	if (body.startsWith("<")) {
		n.contentType = ContentType.APPLICATION_XML;
	}

	return n;
}
 
Example 3
Source File: SimpleMmiDemo.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void send(final Mmi mmi, final URI target) throws JAXBException,
        IOException {
    final JAXBContext ctx = JAXBContext.newInstance(Mmi.class);
    final Marshaller marshaller = ctx.createMarshaller();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    marshaller.marshal(mmi, out);
    final HttpClient client = new DefaultHttpClient();
    final HttpPost post = new HttpPost(target);
    final HttpEntity entity = new StringEntity(out.toString(),
            ContentType.APPLICATION_XML);
    post.setEntity(entity);
    client.execute(post);
    LOGGER.info("sending " + mmi + " to '" + target + "'");
}