Last active
May 28, 2017 09:53
-
-
Save cjmamo/4346702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 org.opensourcesoftwareandme; | |
import javax.ws.rs.core.Application; | |
import java.util.Collections; | |
import java.util.HashSet; | |
import java.util.Set; | |
public class HelloWorldApp extends Application { | |
public Set<Class<?>> getClasses() { | |
Set<Class<?>> classes = new HashSet<Class<?>>(); | |
classes.add(HelloWorldImpl.class); | |
return classes; | |
} | |
} |
This file contains hidden or 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 org.opensourcesoftwareandme; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; | |
import javax.ws.rs.Produces; | |
@Path("/helloWorld") | |
public class HelloWorldImpl { | |
@GET | |
@Produces("text/html") | |
@Path("sayHi/{text}") | |
public String sayHi(@PathParam("text") String text) { | |
return "Hello " + text; | |
} | |
} |
This file contains hidden or 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
... | |
<dependencies> | |
<dependency> | |
<groupId>org.apache.cxf</groupId> | |
<artifactId>cxf-rt-frontend-jaxrs</artifactId> | |
<version>${cxf.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.cxf</groupId> | |
<artifactId>cxf-rt-transports-http-jetty</artifactId> | |
<version>${cxf.version}</version> | |
</dependency> | |
</dependencies> | |
... |
This file contains hidden or 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
mvn package; mvn exec:java -Dexec.mainClass="org.opensourcesoftwareandme.Server" |
This file contains hidden or 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 org.opensourcesoftwareandme; | |
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; | |
import javax.ws.rs.ext.RuntimeDelegate; | |
public class Server { | |
public static void main(String args[]) throws Exception { | |
JAXRSServerFactoryBean jaxrsServerFactory = RuntimeDelegate.getInstance().createEndpoint(new HelloWorldApp(), JAXRSServerFactoryBean.class); | |
jaxrsServerFactory.setAddress("http://localhost:9000"); | |
org.apache.cxf.endpoint.Server server = jaxrsServerFactory.create(); | |
server.start(); | |
System.out.println("Server started..."); | |
Thread.sleep(5 * 60 * 1000); | |
System.out.println("Server stopping..."); | |
server.stop(); | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment