1 Reply Latest reply on Mar 14, 2017 9:58 AM by Saro

    Header Handler Java class issue

    Saro

      Hi friends,

       

      Im not aware of JAVA much. Hence for one of my OBIEE scenario on invoking webservices for changing password im using the below java code and creating the web service using that code by turning that into war file using jdeveloper 11g, and after that im deploying it in Weblogic server using jdeveloper. The below is the code

       

      package Changepwd;

       

      import java.io.IOException;

       

      import java.net.MalformedURLException;

       

      import javax.jws.WebMethod;

      import javax.jws.WebService;

       

      import javax.management.MBeanServerConnection;

      import javax.management.ObjectName;

      import javax.management.remote.JMXConnector;

      import javax.management.remote.JMXConnectorFactory;

      import javax.management.remote.JMXServiceURL;

       

      import java.util.HashMap;

      import java.util.Hashtable;

      import javax.naming.Context;

       

       

      @WebService

      public class Changepwd

      {

          private static JMXConnector jmxConnector = null;

          private static MBeanServerConnection mBeanServerConnection = null;

       

          private static String webLogicHostname = "obiee.domain.com"; // Set to the weblogic host

          private static String webLogicPort = "7001"; // Set to the port of the admin server on the weblogic instance

          private static String webLogicUsername = "weblogic"; // Set to the weblogic admin user

          private static String webLogicPassword = "password"; // Set to the password of the weblogic admin user

         

          private static final String validationFailed = "[Security:090237]";

          private static final String mustBeEightChars = "[Security:090285]";

          private static final String missingSpecialChars = "[Security:099116]";

         

          public Changepwd() {} // for JAXB

       

          @WebMethod(exclude = true)

          public String changeUserPassword( String userId, String oldPassword, String newPassword, String confirmPassword ) throws Exception

          {  

              ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefaultAuthenticator");

              Object objUser[] = new Object[]{(userId), (oldPassword), (newPassword) };

              String objStr[] = new String[]{("java.lang.String"), ("java.lang.String"), ("java.lang.String") };

             

              try

              {

                  if ( confirmPassword.equals(newPassword) )

                  {

                      mBeanServerConnection.invoke(securityMBeanName, "changeUserPassword", objUser, objStr);

                      return "Password successfully changed.";

                  }

                  else

                  {

                      return "New passwords do not match.";

                  }

              }

              catch (Exception e)

              {

                 

                  if( e.getCause().getMessage().contains( validationFailed ) )

                      return "Validation of old password failed.";

                  else if ( e.getCause().getMessage().contains( mustBeEightChars ) )

                      return "Password must be at least 8 characters long.";

                  else if ( e.getCause().getMessage().contains( missingSpecialChars ) )

                      return "Password must contain at least 1 number or special character.";

                  else

                      return "Can not reset password at this time. Please contact an Administrator.";

                 

              }

          }

       

          @WebMethod(exclude = true)

          public static void initConnection(String hostname, String portString) throws IOException, MalformedURLException

          {

              Integer portInteger = Integer.valueOf(portString);

              int port = portInteger.intValue();

              String mserver = "/weblogic.management.mbeanservers.runtime";

              JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:iiop:///jndi/iiop://" + hostname + ":" + port + mserver);

       

              Hashtable h = new Hashtable();

              String[] credentials = new String[] {webLogicUsername, webLogicPassword };

              h.put("jmx.remote.credentials", credentials);

             

              jmxConnector = JMXConnectorFactory.connect(serviceURL, h);

              //jmxConnector = JMXConnectorFactory.connect(serviceURL);

              mBeanServerConnection = jmxConnector.getMBeanServerConnection();

          }

       

          /*@WebMethod(exclude = true)

          public static void main(String[] args) throws Exception

          {

             

          }*/

       

          public String passwordChange( String userId, String oldPassword, String newPassword, String confirmPassword ) throws Exception

          {

              Changepwd c = new Changepwd();

             

              initConnection(webLogicHostname, webLogicPort);

             

              String result = c.changeUserPassword( userId, oldPassword, newPassword, confirmPassword );

             

              jmxConnector.close();

             

              return result;

          }

      }

       

      The above code is working fine, as i created the above code as a webservice and deployed it in weblogic server. But the problem is while im invoking the above code as a webservice in obiee im getting the below error like

       

      soap issue.PNG

       

      Hence for the above error i got the below link stating like

       

      web services - SOAP UI Generated JAVA client throwing MustUnderstandHeaders are not understood error - Stack Overflow

       

      The reason the client is throwing these errors is because when it receives the response back from the web service the mustUnderstand is set to '1'. Now since the WSDL policy did not include the security components, the client does not know what to do with it. The work around is to add the following method in your HeaderHandler.java class.

      public Set getHeaders() {
        
      final QName securityHeader = new QName( 
        
      "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 
        
      "Security", "wsse"); 

        
      final HashSet<QName> headers = new HashSet<QName>(); 
        headers
      .add(securityHeader); 
        
      return headers; 

        
      //throw new UnsupportedOperationException("Not supported yet.");
        
      }

       

      But im not sure where to add the above work around code in my java code. Hence they said like to add in the HeaderHandler java class.

       

      Can you friends help me like whether to add the above work around code in my header handler java class.

       

      Thanks in advance.

       

      Regards,

      Saro