Java to Javascript converter


#1

Hi, are there any good java to javascript compilers out there? Is that even possible?

Saw Google Web Kit, but have not used it before…

http://www.gwtproject.org/

For example I have this in Java:

RestFacade.java

import org.apache.http.HttpResponse;
public interface RestFacade {

public HttpResponse get (String url) ;
	public HttpResponse delete(String url) ;
	public HttpResponse update (String url, String sEntity) ;
	public HttpResponse create (String url, String sEntity) ;
	public HttpResponse query (String url, String sEntity) ;
	public void cleanUp ();
}

and IdentityQueryExample.java

/**
 * 
 * Get list of the users for a specific Identity Group
 *
 */

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.apache.http.HttpResponse;

private static void getUsersOfIdentityGroup(RestFacade restFacade,
		String groupName) {

	String url = "/Rest/Identity/User/op/query";

	Query query = new Query();

	//Set filter to return users of a group (User.IdentityGroupName EQUALS GroupName)
	SimpleFilter sFilter1 = new SimpleFilter();
	sFilter1.setOperation(FilterOperation.EQUALS);
	sFilter1.setValue(groupName);
	sFilter1.setPropertyName("identityGroupName");

	//Set query with filer
	query.setCriteria(sFilter1);

	//query.setNumberOfItemsInPage(100);
	      query.setNumberofItemsInPage(100);
                 query.setStartPageNumber(1);

	ByteArrayOutputStream baos = new ByteArrayOutputStream();

	try {
		//Marshal query into XML to be included in request body
		Marshaller queryMarshaler = JAXBContext.newInstance(
				new Class[] { Query.class }).createMarshaller();
		queryMarshaler.marshal(query, baos);

		// System.out.println("Query to be sent:" + baos.toString());

		HttpResponse response = restFacade.query(url, baos.toString());
		level = restUtils.handleResult(response);

		if (level == ResultLevel.SUCCESS) {
		ByteArrayInputStream bais = restUtils.extractEntity(response);

		//On Success unmarshal response into Users object

			Unmarshaller unmarshaller = JAXBContext.newInstance(
					new Class[] { Users.class }).createUnmarshaller();

			Users users = (Users) unmarshaller.unmarshal(bais);
			List<User> userList = users.getUserList();

			Iterator<User> it = userList.iterator();
			while (it.hasNext()) {
				User usr = (User) it.next();
				printUser(usr);
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return;
}

and I call it with

getUsersOfIdentityGroup(restFacade, "All Groups:HR");

How to convert this to Javascript? Thanks


#2

I’m sure there are, but they probably won’t convert to Meteor and Node.js API’s which are built specifically for JavaScript.