@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("
String requestXml = String.format("""
https://wyszukiwarkaregontest.stat.gov. ... wnPubl.svc
http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj
%s
""", API_KEY);
System.out.println("
System.out.println(requestXml);
try {
SoapResponse response = (SoapResponse) webServiceTemplate.marshalSendAndReceive(
LOGIN_URL,
new SoapRequest(requestXml),
new CustomSoapActionCallback("")
);
System.out.println("
this.sessionId = response.getResult();
if (sessionId == null || sessionId.isEmpty()) {
throw new RuntimeException("
}
System.out.println("
} catch (Exception ex) {
System.err.println("
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
here you have how the logging function call should look like and what it returns
enter image description here