Federschuh - API GUSJava

Java-Forum
Guest
 Federschuh - API GUS

Post by Guest »

Ich habe ein Problem mit der API -GUS -Konfiguration. Ich habe alle Anweisungen, nach denen ich die Gusapiservice -Klasse erstellt habe, aber wenn ich versuche, mich bei dem Server anzumelden kann helfen können, wenn Sie Fragen haben, bitte schreiben Sie < /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
here you have how the logging function call should look like and what it returns
enter image description here

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post