It's all about the answers!

Ask a question

Programmatically create users (application server)


0
1
Chetna Warade (106123) | asked Oct 22 '08, 9:41 p.m.
JAZZ DEVELOPER
I am trying to programmatically create new application server users in RTC. Currently, a user can log into the url https://localhost:9443/jazz and Click User Management and add users by hand. I need to create hundreds of users which is cumbersome. I am playing with the RTC server to see if I can programmatically create new users.

As a start, any http server accepts either GET or POST messages. It is possible to use java.net technique, to open a connection (URLConnection) with the http server and manipulate the server to serve the request. I have had success with many commercial websites.

In context of RTC E,g. When I create a user by hand a url like this is autogenerated in the JavaScript and POST message is sent, so the server can process the request.

https://9.34.120.71:9443/jazz/service/com.ibm.team.repository.service.internal.IAdminRestService/contributor?emailAddress=st3&itemId=new&jsonLicenses=%7B%22add%22%3A%20%5B%22com.ibm.team.rtc.developer%22%5D%2C%20%22remove%22%3A%20%5B%5D%7D&jsonRoles=%5B%22JazzAdmins%22%2C%20%22JazzUsers%22%5D&name=st3&userId=st3

I wrote a plain java client to handle this via SSL (IBM JSSE Provider com.ibm.jsse) since now https:// is being provided with RTC. I created a client keystore file from the server keystore file and imported server keys/certificates. I am not getting any errors, but neither am I seeing any results. Nothing particular in the tomcat logs. I can post the code on request. I was looking if this is the way to go. Any alternative ideas..? Thanks for your time.

23 answers



permanent link
Matt Lavin (2.7k2) | answered Nov 04 '08, 4:08 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
My intention was for you to look at the HTTP traffic between the web UI
and the server to see what the arguments of the POST call were to assign
a license. I did that just now and it looks like the web UI uses a
method that allows multiple license assignments in one call, but a
simple approach that should work for you is to do an HTTP POST like:
https://<your>:9443/jazz/service/com.ibm.team.repository.service.internal.ILicenseAdminRestService/assignLicense?userId=<userid>&licenseId=com.ibm.team.rtc.developer

-
Matt Lavin
Jazz Server Team


On Tue, 2008-11-04 at 20:27 +0000, warade wrote:
thanks for responding to my post in the forum
I can't locate the web ui code, in either the server or client API
bundle. The server side code is password protected so I can't do wide
grep on the code?

permanent link
Matt Lavin (2.7k2) | answered Nov 04 '08, 4:18 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
Right, it doesn't and that's why I suggested taking the approach that
the web UI takes and make the HTTP POST call directly to the URL in
format I posted.

-
Matt Lavin
Jazz Server Team


On Tue, 2008-11-04 at 21:07 +0000, warade wrote:
I dont think the TeamPlatform exposes the
com.ibm.team.repository.service.internal.ILicenseAdminRestService as
a service,yet?

permanent link
Chetna Warade (106123) | answered Nov 05 '08, 10:44 a.m.
JAZZ DEVELOPER
From the browser when I tried https://localhost:9443/jazz/service/com.ibm.team.repository.service.internal.ILicenseAdminRestService/assignLicense?userId=test12&licenseId=com.ibm.team.rtc.developer

HTTP Status 400 - CRJAZ1175I Unable to get method info from service call.

--------------------------------------------------------------------------------

type Status report

message CRJAZ1175I Unable to get method info from service call.

description The request sent by the client was syntactically incorrect (CRJAZ1175I Unable to get method info from service call.).

permanent link
Matt Lavin (2.7k2) | answered Nov 05 '08, 2:08 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
It's pretty hard to execute a POST directly from a standard browser. If
you tried to go to that URL in a normal way it would execute a GET
rather than a POST request. You can use something like the
TeamRestServiceClient to execute the POST request from Java code.

-
Matt Lavin
Jazz Server Team


On Wed, 2008-11-05 at 15:47 +0000, warade wrote:
From the browser when I tried
https://localhost:9443/jazz/service/com.ibm.team.repository.service.internal.ILicenseAdminRestService/assignLicense?userId=test12&licenseId=com.ibm.team.rtc.developer

HTTP Status 400 - CRJAZ1175I Unable to get method info from service
call.

--------------------------------------------------------------------------------

type Status report

message CRJAZ1175I Unable to get method info from service call.

description The request sent by the client was syntactically incorrect
(CRJAZ1175I Unable to get method info from service call.).

permanent link
Chetna Warade (106123) | answered Nov 05 '08, 2:38 p.m.
JAZZ DEVELOPER
I also tried https sniffer program to manually send POST requests but I got connection refused error. Not sure if it is a problem with the sniffer program, but I didn't want to spend too much time debugging that. Atleast I am able to create users worst I would have to browse through them, select license and save which is little better.

It's pretty hard to execute a POST directly from a standard browser. If
you tried to go to that URL in a normal way it would execute a GET
rather than a POST request. You can use something like the
TeamRestServiceClient to execute the POST request from Java code.

-
Matt Lavin
Jazz Server Team


On Wed, 2008-11-05 at 15:47 +0000, warade wrote:
From the browser when I tried
https://localhost:9443/jazz/service/com.ibm.team.repository.service.internal.ILicenseAdminRestService/assignLicense?userId=test12&licenseId=com.ibm.team.rtc.developer

HTTP Status 400 - CRJAZ1175I Unable to get method info from service
call.

--------------------------------------------------------------------------------

type Status report

message CRJAZ1175I Unable to get method info from service call.

description The request sent by the client was syntactically incorrect
(CRJAZ1175I Unable to get method info from service call.).

permanent link
Chetna Warade (106123) | answered Nov 05 '08, 4:24 p.m.
JAZZ DEVELOPER
ITeamRestServiceClient trsc = (ITeamRestServiceClient)repository.getClientLibrary(ITeamRestServiceClient.class);

returns me null so it fails complaining null pointer exception. How can I instantiate this client service from TeamPlatform?

permanent link
Chetna Warade (106123) | answered Nov 06 '08, 9:23 p.m.
JAZZ DEVELOPER
Another attempt.


TeamRepository repo = (TeamRepository)repository;
ITeamRestServiceClient restClient = repo.getRepositoryRestService();
Location loc = Location.serviceLocation(repo.getRepositoryURI(),com.ibm.team.repository.service.internal.ILicenseAdminRestService.class,"assignLicense","userId=test10&licenseId=com.ibm.team.rtc.developer");
final IRestClientConnection connection = restClient.getConnection(loc);
connection.addRequestHeader(HttpUtil.ACCEPT, MediaType.TEXT.toString());
connection.addRequestHeader(HttpUtil.ACCEPT_CHARSET, CharsetEncoding.UTF8.toString());

............

response = connection.doPost(bais, licbytes.length, "text/json;charset=UTF-8");
..........

CRJAZ0054I Error retrieving the resource identified by "com.ibm.team.repository.service.internal.ILicenseAdminRestService": CRJAZ0103I The request for URL "/jazz/service/com.ibm.team.repository.common.internal.IRepositoryRestService/assignLicense?userId=test10&licenseId=com.ibm.team.rtc.developer" was denied with a Not Implemented status.

I debugged and step through, to find that for some reason the class loader is unable to find the class ILicenseAdminRestService even though the jar is in the workspace and also in the path. What is forcing the Location.serviceLocation to think that the service requested is IRepositoryRestService and not ILicenseAdminRestService.

Any other ideas..

permanent link
Todd Lainhart (40611) | answered Nov 07 '08, 11:18 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
warade wrote:
Another attempt.


TeamRepository repo = (TeamRepository)repository;
ITeamRestServiceClient restClient = repo.getRepositoryRestService();
Location loc =
Location.serviceLocation(repo.getRepositoryURI(),com.ibm.team.repository.service.internal.ILicenseAdminRestService.class,"assignLicense","userId=test10&licenseId=com.ibm.team.rtc.developer");
final IRestClientConnection connection =
restClient.getConnection(loc);
connection.addRequestHeader(HttpUtil.ACCEPT,
MediaType.TEXT.toString());
connection.addRequestHeader(HttpUtil.ACCEPT_CHARSET,
CharsetEncoding.UTF8.toString());



repo.getRepositoryRestService() returns the RepositoryRestService, a
very specific REST service that you're binding your location to. The
javadoc for ITeamRestServiceClient.getConnection(...) says this:

/**
* Returns a server communications connection for the location
specified
* by <code>loc</code>. Note that regardless of what server or service
* is specified in <code>loc</code>, the server that this service
client is bound to
* is the server and service that this client connection is bound to.
*

A particular service binding trumps the location's service binding. The
way to do what you're doing is something like this...

licenseRestService =
(ITeamRestServiceClient)repo.getServiceInterface(ILicenseAdminService.class);

....which may not be accessible to you, scope-wise.

However, let me suggest that you're probably on a bad path - depending
upon how the ILicenseAdminService is declared as a service, this still
may not bind correctly at run-time.

Dan Kogan's suggestion of using a tool like "curl", or even a JUnit that
uses java.net.HttpUrlConnection might be a better way to go. Because
your server is using SSL (and probably form-based auth), you'll need
some help dealing with authentication and certificates. Take a look at
the FormBasedAuth class in repository.client, and if you have the tests
source, the FeedServiceTests (readFeed()) which uses this mechanism.

--
Todd Lainhart
Jazz Repository/Foundation Team

permanent link
Chetna Warade (106123) | answered Nov 19 '08, 3:07 p.m.
JAZZ DEVELOPER
warade wrote:
Another attempt.


TeamRepository repo = (TeamRepository)repository;
ITeamRestServiceClient restClient = repo.getRepositoryRestService();
Location loc =
Location.serviceLocation(repo.getRepositoryURI(),com.ibm.team.repository.service.internal.ILicenseAdminRestService.class,"assignLicense","userId=test10&licenseId=com.ibm.team.rtc.developer");
final IRestClientConnection connection =
restClient.getConnection(loc);
connection.addRequestHeader(HttpUtil.ACCEPT,
MediaType.TEXT.toString());
connection.addRequestHeader(HttpUtil.ACCEPT_CHARSET,
CharsetEncoding.UTF8.toString());



repo.getRepositoryRestService() returns the RepositoryRestService, a
very specific REST service that you're binding your location to. The
javadoc for ITeamRestServiceClient.getConnection(...) says this:

/**
* Returns a server communications connection for the location
specified
* by <code>loc</code>. Note that regardless of what server or service
* is specified in <code>loc</code>, the server that this service
client is bound to
* is the server and service that this client connection is bound to.
*

A particular service binding trumps the location's service binding. The
way to do what you're doing is something like this...

licenseRestService =
(ITeamRestServiceClient)repo.getServiceInterface(ILicenseAdminService.class);

....which may not be accessible to you, scope-wise.

However, let me suggest that you're probably on a bad path - depending
upon how the ILicenseAdminService is declared as a service, this still
may not bind correctly at run-time.

Dan Kogan's suggestion of using a tool like "curl", or even a JUnit that
uses java.net.HttpUrlConnection might be a better way to go. Because
your server is using SSL (and probably form-based auth), you'll need
some help dealing with authentication and certificates. Take a look at
the FormBasedAuth class in repository.client, and if you have the tests
source, the FeedServiceTests (readFeed()) which uses this mechanism.

--
Todd Lainhart
Jazz Repository/Foundation Team

In the tests source bundle FeedServiceTests.class is available in team_core_client_tests.jar can't find .java file.

permanent link
Chetna Warade (106123) | answered Nov 19 '08, 3:15 p.m.
JAZZ DEVELOPER
warade wrote:
Another attempt.


TeamRepository repo = (TeamRepository)repository;
ITeamRestServiceClient restClient = repo.getRepositoryRestService();
Location loc =
Location.serviceLocation(repo.getRepositoryURI(),com.ibm.team.repository.service.internal.ILicenseAdminRestService.class,"assignLicense","userId=test10&licenseId=com.ibm.team.rtc.developer");
final IRestClientConnection connection =
restClient.getConnection(loc);
connection.addRequestHeader(HttpUtil.ACCEPT,
MediaType.TEXT.toString());
connection.addRequestHeader(HttpUtil.ACCEPT_CHARSET,
CharsetEncoding.UTF8.toString());



repo.getRepositoryRestService() returns the RepositoryRestService, a
very specific REST service that you're binding your location to. The
javadoc for ITeamRestServiceClient.getConnection(...) says this:

/**
* Returns a server communications connection for the location
specified
* by <code>loc</code>. Note that regardless of what server or service
* is specified in <code>loc</code>, the server that this service
client is bound to
* is the server and service that this client connection is bound to.
*

A particular service binding trumps the location's service binding. The
way to do what you're doing is something like this...

licenseRestService =
(ITeamRestServiceClient)repo.getServiceInterface(ILicenseAdminService.class);

....which may not be accessible to you, scope-wise.

However, let me suggest that you're probably on a bad path - depending
upon how the ILicenseAdminService is declared as a service, this still
may not bind correctly at run-time.

Dan Kogan's suggestion of using a tool like "curl", or even a JUnit that
uses java.net.HttpUrlConnection might be a better way to go. Because
your server is using SSL (and probably form-based auth), you'll need
some help dealing with authentication and certificates. Take a look at
the FormBasedAuth class in repository.client, and if you have the tests
source, the FeedServiceTests (readFeed()) which uses this mechanism.

--
Todd Lainhart
Jazz Repository/Foundation Team

In the tests source bundle FeedServiceTests.class is available in team_core_client_tests.jar can't find .java file.

Sorry found .java file. Too quick to post message :)

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.