Thursday, February 26, 2015

Browse built-in H2 database of WSO2 Products

WSO2 products in default are shipped with H2 database which is good for development, testing, experimental work and for some production systems. WSO2 products also support industry-standard RDBMS such as Oracle, PostgreSQL, MySQL, MS SQL.

When you develop, test and experiment with default H2 database, sometimes you want to go inside the database and see.

And this is how to do it.

1. Go to the <PRODUCT_HOME>/repository/conf/

2. Open the carbon.xml file to edit.

3. Enable the H2DatabaseConfiguration as follows and Save changes.


<H2DatabaseConfiguration>
        <property name="web"/>
        <property name="webPort">8082</property>
        <property name="webAllowOthers"/>        
</H2DatabaseConfiguration>

4. Go to <PRODUCT_HOME>/bin and start the the server as follows.
    e.g.: > sh wso2server.sh

5. Open URL http://localhost:8082/ from browser.



6. Complete the following fields with appropriate values.
Driver Class: org.h2.Driver
JDBC URL  : jdbc:h2:<PRODUCT_HOME>/repository/database/WSO2CARBON_DB
Username    : wso2carbon
Password     : wso2carbon

7. Once you connect to the database you will see a similar UI as follows.

In this example I have used WSO2 API Manager 1.7.0 and connected to the WSO2AM_DB database at <product_home>/repository/database/WSO2AM_DB

Friday, February 20, 2015

Monday, February 9, 2015

Generate JAX-WS client from WSDL file/URL using wsimport tool

wsimport tool available in $JDK/bin folder.

We can use this wsimport tool to parse a certain WSDL file of the server and generate client files (JAX-WS portable artifacts) to access server's published service.

Suhans-MacBook-Pro:client suhanr$ ls
RemoteUserStoreManagerService.wsdl
Suhans-MacBook-Pro:client suhanr$ wsimport -d /WSO2/wsimport_test/client/ RemoteUserStoreManagerService.wsdl
parsing WSDL...

[WARNING] src-resolve: Cannot resolve the name 'ax2605:UserStoreException' to a(n) 'type definition' component.
  line 83 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl#types?schema4

[WARNING] src-resolve: Cannot resolve the name 'ax2609:ClaimDTO' to a(n) 'type definition' component.
  line 147 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl#types?schema4

[WARNING] src-resolve: Cannot resolve the name 'ax2612:Tenant' to a(n) 'type definition' component.
  line 462 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl#types?schema4

[WARNING] Ignoring SOAP port "RemoteUserStoreManagerServiceHttpsSoap12Endpoint": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
  line 1785 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl

[WARNING] ignoring port "RemoteUserStoreManagerServiceHttpsEndpoint": no SOAP address specified. try running wsimport with -extension switch.
  line 1788 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl

[WARNING] src-resolve: Cannot resolve the name 'ax2605:UserStoreException' to a(n) 'type definition' component.
  line 83 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl#types?schema4

[WARNING] src-resolve: Cannot resolve the name 'ax2609:ClaimDTO' to a(n) 'type definition' component.
  line 147 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl#types?schema4

[WARNING] src-resolve: Cannot resolve the name 'ax2612:Tenant' to a(n) 'type definition' component.
  line 462 of file:/WSO2/wsimport_test/client/RemoteUserStoreManagerService.wsdl#types?schema4

generating code...

compiling code...

If you are locally having the server up and running, get the wsdl link and make sure it is accessible via local web browser.

Your command may look like this,


Suhans-MacBook-Pro:client suhanr$ wsimport -d /WSO2/wsimport_test/client/ http://localhost:9763/services/RemoteUserStoreManagerService?wsdl

After generating the code,

Suhans-MacBook-Pro:client suhanr$ tree
.
├── RemoteUserStoreManagerService.wsdl
└── org
    └── wso2
        └── carbon
            ├── um
            │   └── ws
            │       └── service
            │           ├── AddRole.class
            │           ├── AddUser.class
            │           ├── AddUserClaimValue.class
            │           ├── AddUserClaimValues.class
            │           ├── ArrayOfString.class
            │           ├── Authenticate.class
            │           ├── AuthenticateResponse.class
            │           ├── DeleteRole.class
            │           ├── DeleteUser.class
            │           ├── DeleteUserClaimValue.class
            │           ├── DeleteUserClaimValues.class
            │           ├── GetAllProfileNames.class
            │           ├── GetAllProfileNamesResponse.class
            │           ├── GetHybridRoles.class
            │           ├── GetHybridRolesResponse.class
            │           ├── GetPasswordExpirationTime.class
            │           ├── GetPasswordExpirationTimeResponse.class
            │           ├── GetProfileNames.class
            │           ├── GetProfileNamesResponse.class
            │           ├── GetProperties.class
            │           ├── GetPropertiesResponse.class
            │           ├── GetRoleListOfUser.class
            │           ├── GetRoleListOfUserResponse.class
            │           ├── GetRoleNames.class
            │           ├── GetRoleNamesResponse.class
            │           ├── GetTenantId.class
            │           ├── GetTenantIdResponse.class
            │           ├── GetTenantIdofUser.class
            │           ├── GetTenantIdofUserResponse.class
            │           ├── GetUserClaimValue.class
            │           ├── GetUserClaimValueResponse.class
            │           ├── GetUserClaimValues.class
            │           ├── GetUserClaimValuesForClaims.class
            │           ├── GetUserClaimValuesForClaimsResponse.class
            │           ├── GetUserClaimValuesResponse.class
            │           ├── GetUserId.class
            │           ├── GetUserIdResponse.class
            │           ├── GetUserList.class
            │           ├── GetUserListOfRole.class
            │           ├── GetUserListOfRoleResponse.class
            │           ├── GetUserListResponse.class
            │           ├── IsExistingRole.class
            │           ├── IsExistingRoleResponse.class
            │           ├── IsExistingUser.class
            │           ├── IsExistingUserResponse.class
            │           ├── IsReadOnly.class
            │           ├── IsReadOnlyResponse.class
            │           ├── ListUsers.class
            │           ├── ListUsersResponse.class
            │           ├── ObjectFactory.class
            │           ├── RemoteUserStoreManagerService.class
            │           ├── RemoteUserStoreManagerServicePortType.class
            │           ├── RemoteUserStoreManagerServiceUserStoreException.class
            │           ├── RemoteUserStoreManagerServiceUserStoreException_Exception.class
            │           ├── SetUserClaimValue.class
            │           ├── SetUserClaimValues.class
            │           ├── UpdateCredential.class
            │           ├── UpdateCredentialByAdmin.class
            │           ├── UpdateRoleListOfUser.class
            │           ├── UpdateRoleName.class
            │           ├── UpdateUserListOfRole.class
            │           ├── dao
            │           │   └── xsd
            │           │       ├── ClaimDTO.class
            │           │       ├── ObjectFactory.class
            │           │       ├── PermissionDTO.class
            │           │       └── package-info.class
            │           └── package-info.class
            └── user
                ├── api
                │   └── xsd
                │       ├── ObjectFactory.class
                │       ├── RealmConfiguration.class
                │       ├── Tenant.class
                │       ├── UserStoreException.class
                │       └── package-info.class
                ├── core
                │   ├── tenant
                │   │   └── xsd
                │   │       ├── ObjectFactory.class
                │   │       ├── Tenant.class
                │   │       └── package-info.class
                │   └── xsd
                │       ├── ObjectFactory.class
                │       ├── UserStoreException.class
                │       └── package-info.class
                └── mgt
                    └── common
                        └── xsd
                            ├── ClaimValue.class
                            ├── ObjectFactory.class
                            └── package-info.class

18 directories, 81 files

SOAPUI - Test WSDL of the Admin Service - HTTP 401 Unauthorized

I'm currently trying to test WSDL of the Admin Service of WSO2 Identity Server 5.0.0 via SOAPUI 5.0.0

I followed the documentation [1] and [2].

I have set the <HideAdminServiceWSDLs> element to false in <IS_HOME>/repository/conf/carbon.xml file and started the IS server.

In SOAPUI, after creating a project by giving WSDL url as per [1], I tried to invoke addUser().

There, I got the following error as the response.
HTTP/1.1 401 Unauthorized
Set-Cookie: JSESSIONID=9F134766CCA3D8AD2C495678A71FF1FC; Path=/; Secure; HttpOnly
Server: WSO2 Carbon Server
Date: Mon, 09 Feb 2015 09:00:21 GMT
WWW-Authenticate: Basic realm="WSO2 Identity Server"
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding

Solution is as follows [refer below image].

1. Click on the Auth icon just below the soap request, then click on "Add new Authorization"
2. In add authorization dialog box select Basic as type.
3. Now enter authentication credentials(e.g.: admin:admin), and select "authenticate pre-emptively" radio button.



After resending the SOAP request, HTTP Accepted response received.
HTTP/1.1 202 Accepted
Set-Cookie: JSESSIONID=EE298AD95DC943C70C01757ABA545DE8; Path=/; Secure; HttpOnly
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 09 Feb 2015 09:28:12 GMT
Server: WSO2 Carbon Server


Reference:
[1] https://docs.wso2.com/display/IS500/Managing+Users+and+Roles+with+APIs
[2] https://docs.wso2.com/display/Carbon420/Calling+Admin+Services+from+Apps