
com.roskart.dropwizard.jaxws.example.JaxWsExampleApplication Maven / Gradle / Ivy
package com.roskart.dropwizard.jaxws.example;
import com.roskart.dropwizard.jaxws.BasicAuthentication;
import com.roskart.dropwizard.jaxws.ClientBuilder;
import com.roskart.dropwizard.jaxws.EndpointBuilder;
import com.roskart.dropwizard.jaxws.JAXWSBundle;
import com.roskart.dropwizard.jaxws.example.auth.BasicAuthenticator;
import com.roskart.dropwizard.jaxws.example.core.Person;
import com.roskart.dropwizard.jaxws.example.db.PersonDAO;
import com.roskart.dropwizard.jaxws.example.resources.*;
import com.roskart.dropwizard.jaxws.example.ws.*;
import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.hibernate.HibernateBundle;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import ws.example.jaxws.dropwizard.roskart.com.mtomservice.MtomService;
import ws.example.jaxws.dropwizard.roskart.com.wsdlfirstservice.WsdlFirstService;
public class JaxWsExampleApplication extends Application {
// HibernateBundle is used by HibernateExampleService
private final HibernateBundle hibernate = new HibernateBundle(Person.class) {
@Override
public DataSourceFactory getDataSourceFactory(JaxWsExampleApplicationConfiguration configuration) {
return configuration.getDatabaseConfiguration();
}
};
// JAX-WS Bundle
private JAXWSBundle jaxWsBundle = new JAXWSBundle();
private JAXWSBundle anotherJaxWsBundle = new JAXWSBundle("/api2");
public static void main(String[] args) throws Exception {
new JaxWsExampleApplication().run(args);
}
@Override
public void initialize(Bootstrap bootstrap) {
bootstrap.addBundle(hibernate);
bootstrap.addBundle(jaxWsBundle);
bootstrap.addBundle(anotherJaxWsBundle);
}
@Override
public void run(JaxWsExampleApplicationConfiguration jaxWsExampleApplicationConfiguration, Environment environment) throws Exception {
// Hello world service
jaxWsBundle.publishEndpoint(
new EndpointBuilder("/simple", new SimpleService()));
// Publish Hello world service again using different JAXWSBundle instance
anotherJaxWsBundle.publishEndpoint(
new EndpointBuilder("/simple", new SimpleService()));
// Java first service protected with basic authentication
jaxWsBundle.publishEndpoint(
new EndpointBuilder("/javafirst", new JavaFirstServiceImpl())
.authentication(new BasicAuthentication(new BasicAuthenticator(), "TOP_SECRET")));
// WSDL first service using server side JAX-WS handler and CXF logging interceptors
jaxWsBundle.publishEndpoint(
new EndpointBuilder("/wsdlfirst", new WsdlFirstServiceImpl())
.cxfInInterceptors(new LoggingInInterceptor())
.cxfOutInterceptors(new LoggingOutInterceptor()));
// Service using Hibernate
PersonDAO personDAO = new PersonDAO(hibernate.getSessionFactory());
jaxWsBundle.publishEndpoint(
new EndpointBuilder("/hibernate",
new HibernateExampleService(personDAO))
.sessionFactory(hibernate.getSessionFactory()));
// Publish the same service again using different JAXWSBundle instance
anotherJaxWsBundle.publishEndpoint(
new EndpointBuilder("/hibernate",
new HibernateExampleService(personDAO))
.sessionFactory(hibernate.getSessionFactory()));
// WSDL first service using MTOM. Invoking enableMTOM on EndpointBuilder is not necessary
// if you use @MTOM JAX-WS annotation on your service implementation class.
jaxWsBundle.publishEndpoint(
new EndpointBuilder("/mtom", new MtomServiceImpl())
.enableMtom()
);
// RESTful resource that invokes WsdlFirstService on localhost and uses client side JAX-WS handler.
environment.jersey().register(new AccessWsdlFirstServiceResource(
jaxWsBundle.getClient(
new ClientBuilder<>(
WsdlFirstService.class,
"http://localhost:8080/soap/wsdlfirst")
.handlers(new WsdlFirstClientHandler()))));
// RESTful resource that invokes MtomService on localhost
environment.jersey().register(new AccessMtomServiceResource(
jaxWsBundle.getClient(
new ClientBuilder<>(
MtomService.class,
"http://localhost:8080/soap/mtom")
.enableMtom())));
// RESTful resource that invokes JavaFirstService on localhost and uses basic authentication and
// client side CXF interceptors.
environment.jersey().register(new AccessProtectedServiceResource(
jaxWsBundle.getClient(
new ClientBuilder<>(
JavaFirstService.class,
"http://localhost:8080/soap/javafirst")
.cxfInInterceptors(new LoggingInInterceptor())
.cxfOutInterceptors(new LoggingOutInterceptor()))));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy