4 Replies Latest reply on Feb 9, 2015 6:50 AM by Sueleyman Vurucu

    Webservice Authentifaction from jsf app

    Sueleyman Vurucu Expert

      Hi guys,

       

      I have a strange situation here. I try to call a company internal webservice from microsoft navision. In java SE envorinment works everything as excpected. But if i try to call the same logic from a EJB then the webservice returns the response 401. So the authentifaction not works.

       

      I create the webservice with the maven plugin

      <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.1</version>
      </dependency>
      

       

      For the webservice client I follow the suggestions form this msdn blog.

       

      I assume that I modify the outgoing http request with user information.

       

      My environment:

      Wildfly 8.1.0.Final

      JDK 1.8 U 25

      Window7

        • 1. Re: Webservice Authentifaction from jsf app
          Tomaz Cerar Master

          Start by marking dependency as provided

           

          <dependency> 

            <groupId>com.sun.xml.ws</groupId> 

            <artifactId>jaxws-rt</artifactId> 

            <version>2.1</version> 

          <scope>provided</scope>

          </dependency> 

          • 2. Re: Webservice Authentifaction from jsf app
            Sueleyman Vurucu Expert

            Hı tomaz. Thanks for quick reply. I have this dependency not in my war project. I separate it in another jar project. But this dependency is transitive of course. I'll try it tomorrow. Thanks again.

            • 3. Re: Webservice Authentifaction from jsf app
              Sueleyman Vurucu Expert

              Hi Tomaz,

               

              that depependency is the plugin dependency and not project. The webserivce project has therefore no transitive dependencies.

               

                 <plugin>

                              <groupId>org.jvnet.jax-ws-commons</groupId>

                              <artifactId>jaxws-maven-plugin</artifactId>

                              <executions>

                                  <execution>

                                      <id>Generate CustomerList</id>

                                      <goals>

                                          <goal>wsimport</goal>

                                      </goals>

                                      <configuration>

                                          <!-- The name of your generated source package -->

                                          <packageName>foo.bar</packageName>

                                          <wsdlFiles>

                                              <wsdlFile>

                                                  ${project.basedir}/src/main/resources/wsdl/MyWsdl.wsdl

                                              </wsdlFile>

                                          </wsdlFiles>

                                          <encoding>${project.build.sourceEncoding}</encoding>

                                          <verbose>true</verbose>

                                          <wsdlLocation>

                                            my url

                                          </wsdlLocation>

                                          <xdisableAuthenticator>false</xdisableAuthenticator>

                                          <xauthFile>auth.txt</xauthFile>

                                      </configuration>

                                  </execution>

                              <executions>

                              <!-- if you want to use a specific version of JAX-WS, you can do so like this -->

                              <dependencies>

                                  <dependency>

                                      <groupId>com.sun.xml.ws</groupId>

                                      <artifactId>jaxws-tools</artifactId>

                                      <version>2.2.10</version>

                                  </dependency>

                              </dependencies>

                          </plugin>

              • 4. Re: Webservice Authentifaction from jsf app
                Sueleyman Vurucu Expert

                If I authentifacate the WS from Java SE then the Authenticator.getPasswordAuthentication is alled for every ws request. But in wildfly it called only once. Any ideas?

                 

                    Authenticator.setDefault(new Authenticator() {
                        @Override
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(
                                    "user",
                                    "pass".toCharArray());
                        }
                    });
                    URL url =  new URL("http://server:7047/DynamicsNAV/WS/S%20I%20E%20M%20A%20G/Page/CustomerList");
                    QName qNamePort = new QName("urn:microsoft-dynamics-schemas/page/customerlist", "CustomerList_Port");
                    QName qnameService = new QName("urn:microsoft-dynamics-schemas/page/customerlist", "CustomerList_Service");

                 

                    Service service = Service.create(url,qnameService);
                    CustomerListPort port = service.getPort(qNamePort, CustomerListPort.class);

                //

                //    BindingProvider prov = (BindingProvider) port;
                //    prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,
                //            "user");
                //    prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,
                //            "passwd");

                 

                    CustomerListFilter customerListFilter = new CustomerListFilter();
                    customerListFilter.setField(CustomerListFields.NO);
                    customerListFilter.setCriteria(">0");
                    List<CustomerListFilter> filters = new ArrayList<>();
                    filters.add(customerListFilter);

                 

                    CustomerListList customerListList = port.readMultiple(filters, null, 0);

                  customerListList.getCustomerList().forEach(System.err::println);