Spring Boot - API GUSJAVA

Программисты JAVA общаются здесь
Anonymous
 Spring Boot - API GUS

Сообщение Anonymous »

У меня есть проблема с конфигурацией API GUS. У меня есть все инструкции в соответствии с которыми я сделал класс Gusapiservice, но когда я пытаюсь войти на сервер, я получаю ошибку 400.
ниже мой класс Gusapiservice < /p>
сможет помочь, если у вас есть какие -либо вопросы, пожалуйста, напишите < /p>
@Service
public class GusApiService {
@Autowired private JuzersyRepository Repo;

private static final String API_KEY = ""; // Wstaw poprawny klucz API
private static final String LOGIN_URL = "https://wyszukiwarkaregontest.stat.gov. ... wnPubl.svc";
private static final String SEARCH_URL = "https://wyszukiwarkaregontest.stat.gov. ... ajPodmioty";

private final WebServiceTemplate webServiceTemplate;
private String sessionId;

public GusApiService() {
SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
messageFactory.afterPropertiesSet();
this.webServiceTemplate = new WebServiceTemplate(messageFactory);

Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(SoapRequest.class, SoapResponse.class, ObjectFactory.class);
marshaller.setMtomEnabled(true);
this.webServiceTemplate.setMarshaller(marshaller);
this.webServiceTemplate.setUnmarshaller(marshaller);

HttpComponentsMessageSender sender = new HttpComponentsMessageSender();
sender.setConnectionTimeout(5000);
sender.setReadTimeout(10000);
this.webServiceTemplate.setMessageSender(sender);
}

public void login() {
System.out.println("🔄 Logowanie do GUS...");

String requestXml = String.format("""


https://wyszukiwarkaregontest.stat.gov. ... wnPubl.svc
http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj



%s



""", API_KEY);

System.out.println("📤 Wysyłane XML (logowanie):");
System.out.println(requestXml);

try {
SoapResponse response = (SoapResponse) webServiceTemplate.marshalSendAndReceive(
LOGIN_URL,
new SoapRequest(requestXml),
new CustomSoapActionCallback("")
);

System.out.println("✅ Odpowiedź serwera GUS (logowanie): " + response.getResult());

this.sessionId = response.getResult();
if (sessionId == null || sessionId.isEmpty()) {
throw new RuntimeException("❌ Nie udało się pobrać sessionId.");
}
System.out.println("✅ Zalogowano do GUS, sessionId: " + sessionId);
} catch (Exception ex) {
System.err.println("❌ Błąd logowania do GUS: " + ex.getMessage());
throw new RuntimeException("Błąd logowania do GUS.", ex);
}
}

< /code>
public class CustomSoapActionCallback implements WebServiceMessageCallback {
private final String soapAction;

public CustomSoapActionCallback(String soapAction) {
this.soapAction = soapAction;
}

@Override
public void doWithMessage(org.springframework.ws.WebServiceMessage message) throws IOException {
SaajSoapMessage soapMessage = (SaajSoapMessage) message;
soapMessage.setSoapAction(soapAction);
MimeHeaders headers = soapMessage.getSaajMessage().getMimeHeaders();
headers.addHeader("Content-Type", "application/soap+xml; charset=UTF-8");
}
}

< /code>
I have read the entire manual and have no idea where the error could be

Подробнее здесь: https://stackoverflow.com/questions/794 ... ot-api-gus

Вернуться в «JAVA»