package tests;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
import org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser;
import org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser.SpringJAXRSServerFactoryBean;
import org.codehaus.jackson.map.ObjectMapper;
import org.mortbay.jetty.Server;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.request.RequestContextListener;
@Path("/command")
public class CommandExecutor {
@PUT
@Path("/execute/{service}/{method}")
public void execute(final String command, @PathParam("service") final String service, @PathParam("method") final String method) {
ObjectMapper objectMapper = new ObjectMapper();
try {
CustomerData readValue = objectMapper.readValue(command, CustomerData.class);
System.out.println(readValue);
} catch (Exception e) {
}
}
public static void main(final String[] args) throws Exception {
Server server = new Server(7070);
org.mortbay.jetty.servlet.Context root =
new org.mortbay.jetty.servlet.Context(server, "/next-app", org.mortbay.jetty.servlet.Context.SESSIONS);
root.getSessionHandler().getSessionManager().setMaxInactiveInterval(5000);
Map<String, String> param = new HashMap<String, String>();
param.put("contextConfigLocation", "classpath:context.xml");
root.setInitParams(param);
root.addEventListener(new RequestContextListener());
root.addEventListener(new ContextLoaderListener());
root.addServlet(org.apache.cxf.transport.servlet.CXFServlet.class, "/services/*");
server.start();
SpringJAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBeanDefinitionParser.SpringJAXRSServerFactoryBean();
factoryBean.setAddress("/rest");
factoryBean.setServiceBeanObjects(new CommandExecutor());
List<Object> arrayList = new ArrayList<Object>();
// arrayList.add(new JacksonJsonProvider());
JAXBElementProvider elementProvider = new JAXBElementProvider();
elementProvider.setMarshallAsJaxbElement(true);
elementProvider.setUnmarshallAsJaxbElement(true);
arrayList.add(elementProvider);
factoryBean.setProviders(arrayList);
// List<?> providers = factoryBean.getProviders();
List<?> providers = factoryBean.getProviders();
// factoryBean.getProperties().put("faultStackTraceEnabled", "true");
factoryBean.create();
Thread.sleep(100000);
}
}