Archive

Archive for the ‘Uncategorized’ Category

Deserializing XML twitter feeds.

July 2nd, 2010 Wytze No comments

1. Use xsd.exe to extract an xsd file from an xml feed.
Download a private xml feed for example from “http://api.twitter.com/1/statuses/user_timeline.xml” and store it to local disk. Use xsd.exe to generate the xsd.
2. Generate the classes from the xsd file you just generated.

xsd.exe yourxsd.xsd /c

3. Add the generated classes to your C# project.
4. Time for some fetching here is a short example:

// encode the username/password
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.twitter.com/1/statuses/user_timeline.xml");
// set the method to GET
request.Method = "GET";
request.ServicePoint.Expect100Continue = false;
// set the authorisation levels
request.Headers.Add("Authorization", "Basic " + user);
request.ContentType = "application/x-www-form-urlencoded";
 
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
	XmlSerializer serializer = new XmlSerializer(typeof(statuses));
	statuses s = serializer.Deserialize(response.GetResponseStream()) as statuses;
 
	listBox1.Items.Clear();
	foreach (statusesStatus status in s.status)
	{
		listBox1.Items.Add(status.text);
	}
}

Jackrabbit configuration

April 16th, 2010 Wytze No comments
1. Download the jackrabbit jca from http://jackrabbit.apache.org/downloads.html
2. Deploy it on glassfish
3. Create a new Resource Adapter Configuration (Create a new Thread-pool first if you want)
4. Create a new Connector Connection Pool with the new Resource Adapter Configuration
Add the following properties:
homeDir <full path to where your repository is located>
configFile <full path to where your repository config (repository.xml) is located>
5. Create the connector resource and name it 'jcr/repository' for example.

You can now access your repository in the code. Below is a sample.

package com.famvdploeg.jackrabbit;
 
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
 
/**
 *
 * @author wytze
 */
@Stateless
public class JackrabbitManager {
 
	@Resource(mappedName="jcr/repository", type=javax.jcr.Repository.class)
	private Repository repository;
 
	public String getFromRepo() {
		try {
			Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
			Node root = session.getRootNode();
			Node hello = root.addNode("hello");
			hello.setProperty("message", "Hello, World!");
			session.save();
 
			// Retrieve content
            		Node node = root.getNode("hello");
            		System.out.println(node.getPath());
            		System.out.println(node.getProperty("message").getString());
 
			root.getNode("hello").remove();
 
			return "Created and removed!";
		} catch (Exception ex) {
			return ex.getMessage();
		}
	}
}

A possible Java EE 6 Servlet which you can use for WebDAV support. You will need jackrabbit-jcr-server for the base servlet. You can get it by building the source package with maven.

package com.famvdploeg.jackrabbit;
 
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.jcr.Repository;
import javax.servlet.annotation.WebServlet;
import javax.servlet.annotation.WebInitParam;
 
/**
 *
 * @author wytze
 */
@WebServlet(
	name = "webdav",
	urlPatterns = "/repository/*",
	initParams = {
		@WebInitParam(name = "resource-path-prefix", value = "/repository"),
		@WebInitParam(name = "missing-auth-mapping", value = "admin:admin"),
		@WebInitParam(name = "resource-config", value = "/WEB-INF/config.xml")
	}
)
public class SimpleWebdavServlet extends org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet {
 
	@EJB
	private RepositoryFactory repositoryFactory;
 
	private Repository repository;
 
	@PostConstruct
	public void postConstruct() {
		repository = repositoryFactory.getRepository();
	}
 
	@Override
	public Repository getRepository() {
		return repository;
	}
}

Possible extended configuration of the repository:

<!-- Store all items larger than 256 bytes in the FileDataStore -->
<DataStore class="org.apache.jackrabbit.core.data.FileDataStore">
        <param name="path" value="${rep.home}/repository/datastore"/>
        <param name="minRecordLength" value="256"/>
</DataStore>
Categories: Uncategorized Tags:

Some basic Glassfish commands

April 14th, 2010 Wytze No comments

I ran out of brain capacity. So here is a list of commands to do some basic glassfish stuff.

Updating: pkg image-update
Start domain: asadmin start-domain
Stop domain: asadmin stop-domain
Deploy item: asadmin deploy <path to file>
List JNDI entries: asadmin list-jndi-entries
Categories: Uncategorized Tags: