Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 6 of 6

Thread: SM 7.11 web service authentication with java??

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    24

    Question SM 7.11 web service authentication with java??

    Hey kids,
    I am trying to write a web service client in java to consume an SM 7.11 web service. I can't for the life of me figure out where the heck to put the username and password. The example code found in "<SM HOME>\webservices\sample\sm7webservices\Axis2Sampl e" uses method found in ServiceUtility.java:

    Code:
      
    public static void initServiceAuthentication(Stub servicePort, Map arguments) {
      String username = (String) arguments.get(ARGUMENT_USERNAME);
      String password = (String) arguments.get(ARGUMENT_PASSWORD);
    
      HttpTransportProperties.Authenticator authenticator = new Authenticator();
      List<String> auth = new ArrayList<String>();
      auth.add(Authenticator.BASIC);
      authenticator.setAuthSchemes(auth);
      authenticator.setUsername(username);
      authenticator.setPassword(password);
      authenticator.setPreemptiveAuthentication(true);
    
      servicePort._getServiceClient().getOptions().setProperty(
      HTTPConstants.AUTHENTICATE, authenticator);
    }
    Doing some searching of the other files, this method is called as so:

    Code:
        
        IncidentManagementStub stub = new IncidentManagementStub(address);
        
        // set connection: close
        Header hdr = new Header(HTTPConstants.HEADER_CONNECTION, HTTPConstants.HEADER_CONNECTION_CLOSE);
        ArrayList<Header> headers = new ArrayList<Header>();
        headers.add(hdr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headers);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.ENABLE_MTOM,
            Constants.VALUE_TRUE);
        ServiceUtility.initServiceAuthentication(stub, arguments);
    Ok, sweet. But wtf is an IncidentManagementStub? Obviously that is not a native object and I can only find imports and references of this object.
    Any ideas on where this is coming from?
    Has anyone else found a different way of doing authentication with java and SM 7.11?
    I know with SOAPUI in SM 7.11 you have to set the basic authentication in the header. But I don't see any available objects that have anything to do with authentication.

    Ideas?

  2. #2
    Senior Member
    Join Date
    Sep 2008
    Posts
    115

    Default

    The java examples expect the username and password on the command line when calling them, as "-username blah -password blah".

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    24

    Default

    Yep, I suspect that is where these two lines come in:

    Code:
      
      String username = (String) arguments.get(ARGUMENT_USERNAME);
      String password = (String) arguments.get(ARGUMENT_PASSWORD);


    But I need to understand how they get from the command line to the SOAP message.

  4. #4
    Senior Member
    Join Date
    Sep 2008
    Posts
    115

    Default

    Check the ArgumentUtility.java file

    Code:
    /*
     * (C) Copyright Hewlett-Packard Company, LP - All Rights Reserved.
     */
    package com.hp.sm.webservice.sample;
    
    import java.util.List;
    import java.util.Map;
    
    /**
     * A utility class for parsing command line arguments.
     */
    public class ArgumentUtility
    {
    
      /**
       * Parses the given arguments based on the given list of valid required
       * arguments, filling the given map with the argument's value.
       *
       * @param arguments The command line arguments to parse
       * @param validArguments A list of valid required arguments
       * @param argumentValues Map of argument to value
       */
      public static void parseArguments(String[] arguments, List validArguments,
          Map<String, String> argumentValues)
      {
        if (arguments.length == 0 && validArguments.size() != 0) {
          throw new IllegalArgumentException("No arguments given.");
        }
    
        for (int index = 0; index < arguments.length; index++)
        {
          String argument = arguments[index];
          String value = null;
    
          index++;
          if (index < arguments.length)
          {
            value = arguments[index];
          }
          else
          {
            throw new IllegalArgumentException("No value for argument '" + argument
                + "' provided.");
          }
    
          if (validArguments.contains(argument))
          {
            argumentValues.put(argument, value);
          }
          else
          {
            throw new IllegalArgumentException("Invalid argument '" + argument
                + "'.");
          }
        }
    
      }
    }

  5. #5
    Junior Member
    Join Date
    May 2008
    Posts
    24

    Default

    Thanks for the replies leonv. I am not being very clear. Sorry.

    I am writing a custom web services client and I don't know where to set the user name and password. Here is my code thus far.

    Code:
        BomgarUpdatesService.BomgarUpdates_Service serv = new BomgarUpdatesService.BomgarUpdates_Service();
        BomgarUpdatesService.BomgarUpdates port = serv.getBomgarUpdates();
    
    
        StringType s = new StringType();
        BomgarUpdatesInstanceType instance = new BomgarUpdatesInstanceType();
    
        s.setValue("test");
        instance.setLSID(s);
    
        s.setValue("IM10001");
        instance.setExternalKey(s);
    
        s.setValue( "NEW");
        instance.setStatus(s);
    
        BomgarUpdatesModelType model = new BomgarUpdatesModelType();
        model.setInstance(instance);
    
    
        InsertBomgarUpdatesRequest req = new InsertBomgarUpdatesRequest();
        req.setModel(model);
    
        InsertBomgarUpdatesResponse res = port.insertBomgarUpdates(req);
    But none of the object have any place to put any credentials/authentication/username/pw. I was referencing the sample code to see how they did it, but it is not helpful because I don't know where this "IncidentManagementStub" object comes from.

    I looked at the php examples in this forum and that code sticks the username/pw in the soap header, but I am unsure how to reference the soap header in java. In my experience that is abstracted out by java objects.

    Any ideas?

  6. #6
    Junior Member
    Join Date
    May 2008
    Posts
    24

    Default

    Well..... This seems to be a problem with Netbeans not properly generating the "Stubs". I created a new project using eclipse and a few new classes were created. One being a "IncidentManagement_BindingStub" that happens to have the necessary methods to set the username and password. Damn. I really like netbeans

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts