Skip to content

Instantly share code, notes, and snippets.

@dhval
Last active January 29, 2021 18:48
Show Gist options
  • Save dhval/75364c0985bdd661e6e81a5042aec535 to your computer and use it in GitHub Desktop.
Save dhval/75364c0985bdd661e6e81a5042aec535 to your computer and use it in GitHub Desktop.
Spring Boot Web Service Provider (clean)
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
@SpringBootApplication
@EnableWs
public class Application {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
server:
port: 8443
ssl:
enabled: true
key-alias: "server"
key-store: "keystore.jks"
key-store-password: "changeit"
key-password: "changeit"
import cce.schema.ReceiveCourtCaseEventReplyType;
import cce.schema.ResponseMetadataType;
import cce.schema.ResponseType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
@Endpoint
public class CCEEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(CCEEndpoint.class);
public static final String NAMESPACE_URI = "http://jnet.state.pa.us/message/aopc/CCERequestReply/1";
/**
* http://stackoverflow.com/questions/15282656/no-adapter-for-endpoint-in-spring-web-service-response
* @param request
* @return
* @throws Exception
*/
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "ReceiveCourtCaseEventReply")
@ResponsePayload
public JAXBElement<ResponseType> receiveCourtCaseEventReply(@RequestPayload JAXBElement<ReceiveCourtCaseEventReplyType> request) throws Exception{
LOG.info(request.getValue().getResponseMetadata().getUserDefinedTrackingID());
ResponseType response = new ResponseType();
ResponseMetadataType metadataType = new ResponseMetadataType();
metadataType.setResponseActionText("Hi");
response.setResponseStatusCode("Success");
response.setResponseStatusDescriptionText("Thank You Sir.");
QName qname = new QName(NAMESPACE_URI, "ReceiveCourtCaseEventReplyResponse");
return new JAXBElement(qname, ResponseType.class, response);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>cce-provider</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- tag::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<!-- end::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::xsd[] -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>cce.schema</packageName>
<wsdl>true</wsdl>
<xmlschema>false</xmlschema>
<schemaFiles>CCEReply-Full.wsdl</schemaFiles>
<schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
<!-- end::xsd[] -->
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment