Created
May 26, 2012 21:38
-
-
Save kubamarchwicki/2795424 to your computer and use it in GitHub Desktop.
JAX-WS / JAX-RS TomEE issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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