Version's list from SOAP webservice with redirect

apache_commons_compress
Terekhin Alexandr 5 years ago
parent 877407711a
commit be9dc4f97d
  1. 26
      pom.xml
  2. 85
      src/main/java/me/bearns/fias/service/FiasUpdater.java
  3. 10
      src/main/java/me/bearns/fias/service/Updater.java
  4. 18
      src/main/java/me/bearns/fias/webapi/API.java
  5. 1
      src/main/resources/DownloadService.wsdl
  6. 4
      src/main/resources/db/changelog/db.changelog-master.yaml

@ -56,6 +56,32 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.3.6</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<extraargs>
<extraarg>-p</extraarg>
<extraarg>ru.nalog.fias</extraarg>
</extraargs>
<wsdl>${basedir}/src/main/resources/DownloadService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>

@ -0,0 +1,85 @@
package me.bearns.fias.service;
import org.springframework.stereotype.Component;
import ru.nalog.fias.ArrayOfDownloadFileInfo;
import ru.nalog.fias.DownloadFileInfo;
import ru.nalog.fias.IDownloadService;
import ru.nalog.fias.IDownloadService_Service;
import sun.net.www.protocol.http.HttpURLConnection;
import javax.xml.namespace.QName;
import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import java.net.URL;
import java.util.Map;
import static javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY;
import static ru.nalog.fias.IDownloadService_Service.BasicHttpBindingIDownloadService;
@Component
public class FiasUpdater implements Updater {
@Override
public void update() {
IDownloadService_Service service = new IDownloadService_Service();
//QName BasicHttpBindingIDownloadService = new QName("https://fias.nalog.ru/WebServices/Public/DownloadService.asmx/", "BasicHttpBinding_IDownloadService");
//String wsUrl="http://fias.nalog.ru/WebServices/Public/DownloadService.asmx";
//service.addPort(BasicHttpBindingIDownloadService, javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING, wsUrl);
IDownloadService downloadService = service.getBasicHttpBindingIDownloadService();
//BindingProvider bindingProvider = (BindingProvider) service.getPort(IDownloadService.class);
//Map map = bindingProvider.getRequestContext();
//map.put(ENDPOINT_ADDRESS_PROPERTY, "https://fias.nalog.ru/WebServices/Public/DownloadService.asmx");
if(downloadService instanceof BindingProvider ) {
checkRedirect((BindingProvider) downloadService);
}
//HttpURLConnection.setFollowRedirects(true);
//BindingProvider.ENDPOINT_ADDRESS_PROPERTY
ArrayOfDownloadFileInfo info = downloadService.getAllDownloadFileInfo();
if(info != null){
for (DownloadFileInfo fileInfo : info.getDownloadFileInfo()) {
System.out.println("id=" + fileInfo.getVersionId());
System.out.println("text=" + fileInfo.getTextVersion());
System.out.println("full=" + fileInfo.getFiasCompleteXmlUrl());
System.out.println("delta" + fileInfo.getFiasDeltaXmlUrl());
}
}
System.out.println("get Ok");
}
private static void checkRedirect(final BindingProvider bindingProvider) {
try {
final URL url = new URL((String) bindingProvider.getRequestContext().get(ENDPOINT_ADDRESS_PROPERTY));
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/html; charset='UTF-8'");
connection.setDoOutput(true);
final int responseCode = connection.getResponseCode();
if(responseCode >= 300 && responseCode < 400) {
final String redirectToUrl = connection.getHeaderField("location");
bindingProvider.getRequestContext().put(ENDPOINT_ADDRESS_PROPERTY, redirectToUrl);
}
} catch(final Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,10 @@
package me.bearns.fias.service;
public interface Updater {
/**
* Run online update for fias database
*/
public void update();
}

@ -0,0 +1,18 @@
package me.bearns.fias.webapi;
import me.bearns.fias.service.Updater;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class API {
@Autowired
Updater service;
@GetMapping("/update")
void update(){
service.update();
}
}

@ -0,0 +1 @@
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="https://fias.nalog.ru/WebServices/Public/DownloadService.asmx/" targetNamespace="https://fias.nalog.ru/WebServices/Public/DownloadService.asmx/" name="IDownloadService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><wsdl:types><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="https://fias.nalog.ru/WebServices/Public/DownloadService.asmx/"><xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/><xs:import namespace="http://schemas.datacontract.org/2004/07/System"/><xs:element name="GetAllDownloadFileInfo"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="GetAllDownloadFileInfoResponse"><xs:complexType><xs:sequence><xs:element minOccurs="0" maxOccurs="1" name="GetAllDownloadFileInfoResult" nillable="true" type="tns:ArrayOfDownloadFileInfo"/></xs:sequence></xs:complexType></xs:element><xs:element name="GetLastDownloadFileInfo"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="GetLastDownloadFileInfoResponse"><xs:complexType><xs:sequence><xs:element minOccurs="0" maxOccurs="1" name="GetLastDownloadFileInfoResult" type="tns:DownloadFileInfo"/></xs:sequence></xs:complexType></xs:element><xs:complexType name="ArrayOfDownloadFileInfo"><xs:sequence><xs:element minOccurs="0" maxOccurs="unbounded" nillable="true" name="DownloadFileInfo" type="tns:DownloadFileInfo"/></xs:sequence></xs:complexType><xs:element name="ArrayOfDownloadFileInfo" nillable="true" type="tns:ArrayOfDownloadFileInfo"/><xs:complexType name="DownloadFileInfo"><xs:sequence><xs:element minOccurs="1" maxOccurs="1" name="VersionId" type="xs:long"/><xs:element minOccurs="0" maxOccurs="1" name="TextVersion" type="xs:string"/><xs:element minOccurs="0" maxOccurs="1" name="FiasCompleteDbfUrl" type="xs:string"/><xs:element minOccurs="0" maxOccurs="1" name="FiasCompleteXmlUrl" type="xs:string"/><xs:element minOccurs="0" maxOccurs="1" name="FiasDeltaDbfUrl" type="xs:string"/><xs:element minOccurs="0" maxOccurs="1" name="FiasDeltaXmlUrl" type="xs:string"/><xs:element minOccurs="0" maxOccurs="1" name="Kladr4ArjUrl" type="xs:string"/><xs:element minOccurs="0" maxOccurs="1" name="Kladr47ZUrl" type="xs:string"/></xs:sequence></xs:complexType><xs:element name="DownloadFileInfo" nillable="true" type="tns:DownloadFileInfo"/></xs:schema></wsdl:types><wsdl:message name="IDownloadService_GetAllDownloadFileInfo_InputMessage"><wsdl:part name="parameters" element="tns:GetAllDownloadFileInfo"/></wsdl:message><wsdl:message name="IDownloadService_GetAllDownloadFileInfo_OutputMessage"><wsdl:part name="parameters" element="tns:GetAllDownloadFileInfoResponse"/></wsdl:message><wsdl:message name="IDownloadService_GetLastDownloadFileInfo_InputMessage"><wsdl:part name="parameters" element="tns:GetLastDownloadFileInfo"/></wsdl:message><wsdl:message name="IDownloadService_GetLastDownloadFileInfo_OutputMessage"><wsdl:part name="parameters" element="tns:GetLastDownloadFileInfoResponse"/></wsdl:message><wsdl:portType name="IDownloadService"><wsdl:operation name="GetAllDownloadFileInfo"><wsdl:input message="tns:IDownloadService_GetAllDownloadFileInfo_InputMessage"/><wsdl:output message="tns:IDownloadService_GetAllDownloadFileInfo_OutputMessage"/></wsdl:operation><wsdl:operation name="GetLastDownloadFileInfo"><wsdl:input message="tns:IDownloadService_GetLastDownloadFileInfo_InputMessage"/><wsdl:output message="tns:IDownloadService_GetLastDownloadFileInfo_OutputMessage"/></wsdl:operation></wsdl:portType><wsdl:binding name="BasicHttpBinding_IDownloadService" type="tns:IDownloadService"><soap:binding transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="GetAllDownloadFileInfo"><soap:operation soapAction="https://fias.nalog.ru/WebServices/Public/DownloadService.asmx/GetAllDownloadFileInfo" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetLastDownloadFileInfo"><soap:operation soapAction="https://fias.nalog.ru/WebServices/Public/DownloadService.asmx/GetLastDownloadFileInfo" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="IDownloadService"><wsdl:port name="BasicHttpBinding_IDownloadService" binding="tns:BasicHttpBinding_IDownloadService"><soap:address location="http://fias.nalog.ru/WebServices/Public/DownloadService.asmx"/></wsdl:port></wsdl:service></wsdl:definitions>

@ -0,0 +1,4 @@
databaseChangeLog:
- changeSet:
id: 1
author: alex@bearns.me
Loading…
Cancel
Save