javaweb-servicessoapjax-wssoapui

Integrating with TERYT - Polish Government web service


I am trying to connect (without success) to the following WS using Java:

I tried to use soapui without success. Tried Basic and NTLM authentication, and I always get the following error:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
   </s:Header>
   <s:Body>
      <s:Fault>
         <faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</faultcode>
         <faultstring xml:lang="en-US">An error occurred when verifying security for the message.</faultstring>
      </s:Fault>
   </s:Body>
</s:Envelope>

The official instructions for this web service shows following example to connect using C#. I havn't tested this, but I assume it works correctly.

try { 
  var proxy = new ChannelFactory<ServiceReferenceWCF.ITerytWs1>("custom");
  proxy.Credentials.UserName.UserName = login;
  proxy.Credentials.UserName.Password = haslo;
  var result = proxy.CreateChannel(); 
  var test = result.CzyZalogowany(); // should return true if connected correctly
} catch (Exception ex) { }

And below setting:

   <client>
      <endpoint address="https://uslugaterytws1.stat.gov.pl/TerytWs1.svc" binding="customBinding" bindingConfiguration="custom" contract="ServiceReference1.ITerytWs1" name="custom" />
   </client>
   <bindings>
      <customBinding>
         <binding name="custom">
            <security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
               <localClientSettings detectReplays="false" />
               <localServiceSettings detectReplays="false" />
            </security>
            <textMessageEncoding messageVersion="Soap11WSAddressing10" />
            <httpsTransport maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" />
         </binding>
      </customBinding>
   </bindings>

So I tried to connect using Java following way:

public static void main(String[] args) {
    try {
        final String wsdlResourcePath = "wsdl/jaxb/teryt/terytws1.wsdl";
        final String url = "https://uslugaterytws1test.stat.gov.pl/TerytWs1.svc";
        ITerytWs1 teryt = createSoapEndpoint((wsdlLocation) -> new TerytWs1(wsdlLocation).getCustom(), wsdlResourcePath, url);
        System.out.println(teryt.czyZalogowany());
    } catch (Exception e) { }
}

private static <SOAP> SOAP createSoapEndpoint(SoapCreator<SOAP> soapCreator, String wsdlResourcePath, String url) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL wsdlLocation = cl.getResource(wsdlResourcePath);
    SOAP soap = soapCreator.create(wsdlLocation);

    BindingProvider provider = (BindingProvider) soap;

    Map<String, Object> context = provider.getRequestContext();
    context.put(BindingProvider.USERNAME_PROPERTY, "TestPubliczny");
    context.put(BindingProvider.PASSWORD_PROPERTY, "1234abcd");
    context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    return soap;
}

Unfortunately the code freezes during call "teryt.czyZalogowany()". Gives no timeout - anything, just processing this line for ever, or is being blocked at it.

My Java code produces following warning messages:

WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}SignedSupportingTokens" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}TransportBinding" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}Trust10" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}Wss11" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0075: Policy assertion "{http://www.w3.org/2006/05/addressing/wsdl}UsingAddressing" was evaluated as "UNKNOWN". lip 27, 2017 11:58:35 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives WARNING: WSP0019: Suboptimal policy alternative selected on the client side with fitness "UNKNOWN".

Perhaps someone knows more about this kind of problem, or will be able to connect to this WS straight away with his own config - at the moment I don't have a single clue what could be the issue, and I see a "time-wasting" perspective in front of me... so please help.


Solution

  • This is my old question and I just came here after long time, because I got ping during Christmas break. Someone is still struggling with this, and the question was left in an un-solved state. This is probably my bad :)

    If you still struggle with this, below is the working sample request, so whatever language/tool/framework you are using, you can treat as cool reference.

    curl --location 'https://uslugaterytws1test.stat.gov.pl/TerytWs1.svc' \
    --header 'Content-Type: text/xml' \
    --header 'Authorization: Bearer Bearer cR5WPpUvRVnVbYdTifxUCsCGajoa20EnUAndUery' \
    --data '<?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
        <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
            <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                <wsse:UsernameToken wsu:Id="UsernameToken-2018-01-11T00:16:02+00:00">
                    <wsse:Username>TestPubliczny</wsse:Username>
                    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234abcd</wsse:Password>
                    <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NWE5MTJkOWEyZTMyMDhhYWM0YWY2YTVmMmNjM2I0NDQ=</wsse:Nonce>
                    <wsu:Created>2018-01-11T00:16:02+00:00</wsu:Created>
                </wsse:UsernameToken>
            </wsse:Security>
            <wsa:Action>http://tempuri.org/ITerytWs1/PobierzSlownikRodzajowJednostek</wsa:Action>
        </soapenv:Header>
        <soapenv:Body><ns1:PobierzSlownikRodzajowJednostek/></soapenv:Body></soapenv:Envelope>
    '
    

    And response:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://tempuri.org/ITerytWs1/PobierzSlownikRodzajowJednostekResponse</a:Action>
        <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <u:Timestamp u:Id="_0">
                <u:Created>2024-12-27T12:13:46.917Z</u:Created>
                <u:Expires>2024-12-27T12:18:46.917Z</u:Expires>
            </u:Timestamp>
        </o:Security>
    </s:Header>
    <s:Body>
        <PobierzSlownikRodzajowJednostekResponse xmlns="http://tempuri.org/">
            <PobierzSlownikRodzajowJednostekResult xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <b:string>1, gmina miejska</b:string>
                <b:string>2, gmina wiejska</b:string>
                <b:string>3, gmina miejsko-wiejska</b:string>
                <b:string>4, miasto w gminie miejsko-wiejskiej</b:string>
                <b:string>5, obszar wiejski w gminie miejsko-wiejskiej</b:string>
                <b:string>8, dzielnice m. st. Warszawy</b:string>
                <b:string>9, delegatury miast: Kraków, Łódź, Poznań, Wrocław</b:string>
            </PobierzSlownikRodzajowJednostekResult>
        </PobierzSlownikRodzajowJednostekResponse>
    </s:Body>
    </s:Envelope>
    

    If this is helpful for you, and using the above you were able to make your implementation working, please share, so others can benefit from this.