Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JAX-WS / JAX-RS TomEE issues
package pl.marchwicki.jee6.basetypes;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="helloMessage")
public class HelloMessage {
@XmlElement(name="message")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
private String message;
}
package pl.marchwicki.jee6;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import pl.marchwicki.jee6.basetypes.HelloMessage;
@Path("/say")
@Produces(MediaType.APPLICATION_JSON)
@Stateless
public class JaxRsService {
@Inject
Service service;
@Path("/hello/{name}")
@GET
public HelloMessage sayHello(@PathParam("name") String name) {
return service.hello(name);
}
}
package pl.marchwicki.jee6;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebService;
import pl.marchwicki.jee6.basetypes.HelloMessage;
@WebService
@Stateless
public class JaxWsService {
@Inject
Service service;
public HelloMessage sayHello(String name) {
return service.hello(name);
}
}
package pl.marchwicki.jee6;
import javax.inject.Named;
import javax.ws.rs.PathParam;
import pl.marchwicki.jee6.basetypes.HelloMessage;
@Named
public class Service {
public HelloMessage hello(@PathParam("name") String name) {
HelloMessage msg = new HelloMessage();
msg.setMessage("Hello! " + name);
return msg;
}
}
package pl.marchwicki.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import pl.marchwicki.jee6.Service;
import pl.marchwicki.jee6.basetypes.HelloMessage;
@WebServlet(urlPatterns = "/servlet")
public class Servlet extends HttpServlet {
@Inject
Service service;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
HelloMessage hello = service.hello("Jakub");
PrintWriter writer = resp.getWriter();
writer.append("Hello message: " + hello.getMessage());
writer.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.