Untitled

 avatar
unknown
java
6 months ago
3.4 kB
122
No Index
@Endpoint
@Validated
public class PerlasEndpoint {
    @Autowired
    PerlasService perlasService;
    private static final String SOAP_NAMESPACE="http://schemas.xmlsoap.org/soap/envelope/";

    @PayloadRoot(namespace = SOAP_NAMESPACE,localPart = "idcheck")
    @ResponsePayload
    public PerlasCheckIdResponseDTO checkId(@Valid @RequestPayload PerlasCheckIdRequestDTO perlasCheckIdRequestDTO) {
        Optional<PerlasCheckIdResponseDTO> validationResult=perlasService.validateCheckIdRequest(perlasCheckIdRequestDTO);

        if (validationResult.isPresent()) {
            return validationResult.get();
        }

        PerlasCheckIdResponseDTO perlasCheckIdResponseDTO = perlasService.checkId(perlasCheckIdRequestDTO);
        return perlasCheckIdResponseDTO;
    }

    @PayloadRoot(namespace = SOAP_NAMESPACE, localPart = "saleRequest")
    @ResponsePayload
    public PerlasSaleResponseDTO createSale(@Valid @RequestPayload PerlasSaleRequestDTO perlasSaleRequestDTO) {
        PerlasSaleResponseDTO perlasSaleResponseDTO=perlasService.createSale(perlasSaleRequestDTO);
        return perlasSaleResponseDTO;
    }
}
////////////////////////////////////////////////////////////
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "userId",
        "transactionId"
})
@XmlRootElement(name = "idcheck", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
@Data
public class PerlasCheckIdRequestDTO {
    @NotNull(message = "userId cant be null")
    @Size(max = 32, message = "userId too long")
    @XmlElement(name = "userid", required = true, namespace = "http://schemas.xmlsoap.org/soap/envelope/")
    private String userId;

    @NotNull(message = "transactionId cant be null")
    @Size(max = 100, message = "transactionId too long")
    @XmlElement(name = "trans_id", required = true, namespace = "http://schemas.xmlsoap.org/soap/envelope/")
    private String transactionId;
}
////////////////////////////////////////////////////////////
@EnableWs
@Configuration
public class PerlasSoapConfig extends WsConfigurerAdapter {
    private final AppConfig appConfig;

    public PerlasSoapConfig(AppConfig appConfig) {
        this.appConfig = appConfig;
    }

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
        messageDispatcherServlet.setApplicationContext(applicationContext);
        return new ServletRegistrationBean<>(messageDispatcherServlet, "/perlas/*");
    }

    @Bean(name = "perlas")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema xsdSchema) {
        DefaultWsdl11Definition defaultWsdl11Definition = new DefaultWsdl11Definition();
        defaultWsdl11Definition.setPortTypeName("Perlas");
        defaultWsdl11Definition.setLocationUri(appConfig.getPerlasLocationUri());

        defaultWsdl11Definition.setTargetNamespace("http://schemas.xmlsoap.org/soap/envelope/");
        defaultWsdl11Definition.setSchema(xsdSchema);
        return defaultWsdl11Definition;
    }

    @Bean
    public XsdSchema xsdSchema() {
        return new SimpleXsdSchema(new ClassPathResource("perlas/perlas.xsd"));
    }
}
Editor is loading...
Leave a Comment