Curl commands for testing REST based services

Curl is one of the best utilities for HTTP based testing. So, naturally, it’s a great for REST based services which are built on top of HTTP.

If you want to do HTTPS testing but not validate the certificate use -k

For basic auth, use --user username:password

For a url form encoded post use -d "foo=bar". If you just want to test out a post, use an empty string like -d "".

For debugging, use -v

Here’s a sample command I regularly use with a combination of the options above.


curl -k --user admin:admin https://localhost:9443/bam/ -v
* About to connect() to localhost port 9443 (#0)
*   Trying 127.0.0.1... connected
* successfully set certificate verify locations:
*   CAfile: /opt/local/share/curl/curl-ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using DHE-RSA-AES256-SHA
* Server certificate:
* 	 subject: C=US; ST=CA; L=Mountain View; O=WSO2; CN=localhost
* 	 start date: 2010-02-19 07:02:26 GMT
* 	 expire date: 2035-02-13 07:02:26 GMT
* 	 common name: localhost (matched)
* 	 issuer: C=US; ST=CA; L=Mountain View; O=WSO2; CN=localhost
* 	 SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Server auth using Basic with user 'admin'
> GET /bam/ HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.22.0 (x86_64-apple-darwin10.8.0) libcurl/7.22.0 OpenSSL/1.0.0e zlib/1.2.5 libidn/1.22
> Host: localhost:9443
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Wed, 13 Jun 2012 06:52:01 GMT
< Content-Type: text/plain
< Content-Length: 14
< Server: WSO2 Carbon Server
< 
* Connection #0 to host localhost left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
My Sample Text

Useful commands for debugging OSGI issues and constraints

These are a few commands that I find very useful when faced with OSGI issues.

1. ss / ss <string> (abbr. for short status)

Lists down the state of all installed bundles or if followed by a string, does a wildcard match of that string. Useful for initial investigation of checking whether a bundle is active, installed or not present at all.

osgi> ss bam

Framework is launched.


id State Bundle
143 RESOLVED org.wso2.bam.styles_2.0.0.SNAPSHOT
Master=290
150 ACTIVE org.wso2.carbon.bam.analyzer.stub_4.0.0.SNAPSHOT
151 ACTIVE org.wso2.carbon.bam.core.stub_4.0.0.SNAPSHOT
152 ACTIVE org.wso2.carbon.bam.gadgetgenwizard_4.0.0.SNAPSHOT
153 ACTIVE org.wso2.carbon.bam.gadgetgenwizard.stub_4.0.0.SNAPSHOT
154 ACTIVE org.wso2.carbon.bam.gadgetgenwizard.ui_4.0.0.SNAPSHOT
155 ACTIVE org.wso2.carbon.bam.presentation.stub_4.0.0.SNAPSHOT
156 ACTIVE org.wso2.carbon.bam2.core_4.0.0.SNAPSHOT
157 ACTIVE org.wso2.carbon.bam2.core.ui_4.0.0.SNAPSHOT
158 ACTIVE org.wso2.carbon.bam2.presentation_4.0.0.SNAPSHOT
159 ACTIVE org.wso2.carbon.bam2.receiver_4.0.0.SNAPSHOT
160 ACTIVE org.wso2.carbon.bam2.service_4.0.0.SNAPSHOT


2. b  <id> (abbr. for bundle)

Displays details for the specified bundles. Useful for checking what your bundle exports and imports when narrowing down situations like uses constraints. Also, helps with the OSGI services used.

osgi> b 152
org.wso2.carbon.bam.gadgetgenwizard_4.0.0.SNAPSHOT [152]
Id=152, Status=ACTIVE Data Root=/Users/mackie/source-checkouts/carbon/platform/trunk/products/bam2/modules/distribution/product/target/wso2bam-2.0.0-SNAPSHOT/repository/components/configuration/org.eclipse.osgi/bundles/152/data
No registered services.
Services in use:
{org.wso2.carbon.utils.ConfigurationContextService}={service.id=123}
{org.wso2.carbon.base.api.ServerConfigurationService}={service.id=83}
Exported packages
org.wso2.carbon.bam.gadgetgenwizard.internal; version="4.0.0.SNAPSHOT"[exported]
org.wso2.carbon.bam.gadgetgenwizard.service; version="4.0.0.SNAPSHOT"[exported]
Imported packages
org.apache.commons.logging; version="1.1.1"
org.wso2.carbon.utils; version="4.0.0.SNAPSHOT"
org.wso2.carbon.user.core; version="4.0.0.SNAPSHOT"
org.wso2.carbon.registry.core.session; version="1.0.1"
org.wso2.carbon.registry.core.exceptions; version="1.0.1"
org.wso2.carbon.registry.core; version="1.0.1"
org.wso2.carbon.registry.common.services; version="1.0.1"
org.wso2.carbon.base.api; version="1.0.0"
org.osgi.service.component; version="1.1.0"
org.apache.commons.io; version="2.0.0"
org.apache.axiom.om.impl.jaxp; version="1.2.11.wso2v1"
org.apache.axiom.om.impl.builder; version="1.2.11.wso2v1"
org.apache.axiom.om; version="1.2.11.wso2v1"
javax.xml.transform.stream; version="0.0.0"
javax.xml.transform; version="0.0.0"
javax.xml.stream; version="1.0.1"
javax.xml.namespace; version="0.0.0"
net.sf.saxon; version="9.0.0.x"
No fragment bundles
Named class space
org.wso2.carbon.bam.gadgetgenwizard; bundle-version="4.0.0.SNAPSHOT"[provided]
No required bundles

3. p <package> (abbr. for packages)

Shows the bundles that export and import the specified packages. Extremely useful in debugging most OSGI issues.

osgi> p org.wso2.carbon.utils
org.wso2.carbon.utils; version="4.0.0.SNAPSHOT"
axis2_1.6.1.wso2v5 [19] imports
org.wso2.carbon.analytics.hive_4.0.0.SNAPSHOT [145] imports
org.wso2.carbon.application.deployer_4.0.0.SNAPSHOT [147] imports
org.wso2.carbon.bam.gadgetgenwizard_4.0.0.SNAPSHOT [152] imports
org.wso2.carbon.bam2.core_4.0.0.SNAPSHOT [156] imports
org.wso2.carbon.bam2.receiver_4.0.0.SNAPSHOT [159] imports
org.wso2.carbon.cassandra.dataaccess_4.0.0.SNAPSHOT [163] imports
org.wso2.carbon.cassandra.mgt_4.0.0.SNAPSHOT [164] imports
org.wso2.carbon.cluster.mgt.core_4.0.0.SNAPSHOT [169] imports
org.wso2.carbon.coordination.core_4.0.0.SNAPSHOT [172] imports
org.wso2.carbon.core_4.0.0.SNAPSHOT [173] imports
org.wso2.carbon.core.bootup.validator_4.0.0.SNAPSHOT [174] imports
org.wso2.carbon.core.services_4.0.0.SNAPSHOT [177] imports
org.wso2.carbon.dashboard_4.0.0.SNAPSHOT [178] imports
org.wso2.carbon.dashboard.common_4.0.0.SNAPSHOT [179] imports
org.wso2.carbon.dashboard.dashboardpopulator_4.0.0.SNAPSHOT [180] imports
org.wso2.carbon.dashboard.ui_4.0.0.SNAPSHOT [182] imports
org.wso2.carbon.datasource_4.0.0.SNAPSHOT [183] imports
org.wso2.carbon.event.client_4.0.0.SNAPSHOT [187] imports
org.wso2.carbon.event.common_4.0.0.SNAPSHOT [189] imports
org.wso2.carbon.event.core_4.0.0.SNAPSHOT [190] imports
org.wso2.carbon.event.ws_4.0.0.SNAPSHOT [191] imports
org.wso2.carbon.jaggery.app.mgt_1.0.0.SNAPSHOT [222] imports
org.wso2.carbon.jaggery.app.mgt.ui_1.0.0.SNAPSHOT [224] imports
org.wso2.carbon.jaggery.deployer_1.0.0.SNAPSHOT [226] imports
org.wso2.carbon.logging.service_4.0.0.SNAPSHOT [232] imports
org.wso2.carbon.ndatasource.core_4.0.0.SNAPSHOT [236] imports
org.wso2.carbon.ntask.core_4.0.0.SNAPSHOT [239] imports
org.wso2.carbon.registry.common_4.0.0.SNAPSHOT [246] imports
org.wso2.carbon.registry.core_4.0.0.SNAPSHOT [248] imports
org.wso2.carbon.registry.resource.ui_4.0.0.SNAPSHOT [254] imports
org.wso2.carbon.registry.server_4.0.0.SNAPSHOT [258] imports
org.wso2.carbon.registry.servlet_4.0.0.SNAPSHOT [259] imports
org.wso2.carbon.reporting.template.core_4.0.0.SNAPSHOT [263] imports
org.wso2.carbon.security.mgt_4.0.0.SNAPSHOT [273] imports
org.wso2.carbon.security.mgt.ui_4.0.0.SNAPSHOT [275] imports
org.wso2.carbon.server.admin_4.0.0.SNAPSHOT [276] imports
org.wso2.carbon.server.admin.ui_4.0.0.SNAPSHOT [279] imports
org.wso2.carbon.service.mgt_4.0.0.SNAPSHOT [280] imports
org.wso2.carbon.transport.http_4.0.0.SNAPSHOT [285] imports
org.wso2.carbon.transport.https_4.0.0.SNAPSHOT [286] imports
org.wso2.carbon.transport.mgt_4.0.0.SNAPSHOT [287] imports
org.wso2.carbon.ui_4.0.0.SNAPSHOT [290] imports
org.wso2.carbon.user.core_4.0.0.SNAPSHOT [295] imports
org.wso2.carbon.user.mgt.ui_4.0.0.SNAPSHOT [299] imports
org.wso2.carbon.webapp.mgt_4.0.0.SNAPSHOT [301] imports
org.wso2.carbon.wsdl2form_4.0.0.SNAPSHOT [302] imports

4. diag <bid> (abbr. for diagnose)

Shows any unsatisfied constraints of the bundle.

osgi> diag 159
reference:file:plugins/org.wso2.carbon.bam2.receiver_4.0.0.SNAPSHOT.jar [159]
No unresolved constraints.

 

5. ls (abbr. for list services)

Lists down the state of all OSGI services. In this list the most important would be identifying the unsatisfied components as in component 20 below.

osgi> ls
All Components:
ID State Component Name Located in bundle
1 Registered org.eclipse.equinox.frameworkadmin.equinox org.eclipse.equinox.frameworkadmin.equinox(bid=108)
2 Active org.eclipse.equinox.p2.artifact.repository org.eclipse.equinox.p2.artifact.repository(bid=114)
3 Active org.eclipse.equinox.p2.core.eventbus org.eclipse.equinox.p2.core(bid=116)
4 Active org.eclipse.equinox.p2.di.agentProvider org.eclipse.equinox.p2.core(bid=116)
5 Registered org.eclipse.equinox.p2.director org.eclipse.equinox.p2.director(bid=117)
6 Active org.eclipse.equinox.p2.planner org.eclipse.equinox.p2.director(bid=117)
7 Active org.eclipse.equinox.p2.engine.registry org.eclipse.equinox.p2.engine(bid=120)
8 Active org.eclipse.equinox.p2.engine org.eclipse.equinox.p2.engine(bid=120)
9 Active org.eclipse.equinox.p2.garbagecollector org.eclipse.equinox.p2.garbagecollector(bid=122)
10 Active org.eclipse.equinox.p2.metadata.repository org.eclipse.equinox.p2.metadata.repository(bid=125)
11 Registered org.eclipse.equinox.p2.repository org.eclipse.equinox.p2.repository(bid=128)
12 Registered org.eclipse.equinox.p2.transport.ecf org.eclipse.equinox.p2.transport.ecf(bid=132)
13 Registered org.eclipse.equinox.p2.updatechecker org.eclipse.equinox.p2.updatechecker(bid=133)
14 Registered org.eclipse.equinox.simpleconfigurator.manipulator org.eclipse.equinox.simpleconfigurator.manipulator(bid=138)
15 Active bam.hive.component org.wso2.carbon.analytics.hive(bid=145)
16 Active application.deployer.dscomponent org.wso2.carbon.application.deployer(bid=147)
17 Active gadgetgenwizard.component org.wso2.carbon.bam.gadgetgenwizard(bid=152)
18 Active bam.utils.component org.wso2.carbon.bam2.core(bid=156)
19 Active bam.presentation.component org.wso2.carbon.bam2.presentation(bid=158)
20 Unsatisfied bam.receiver.component org.wso2.carbon.bam2.receiver(bid=159)
21 Active org.wso2.carbon.cassandra.dataaccess.component org.wso2.carbon.cassandra.dataaccess(bid=163)
22 Active org.wso2.carbon.cassandra.mgt.component org.wso2.carbon.cassandra.mgt(bid=164)

6. comp <component id> or ls -c <bundleid>

Lists component specific information regarding OSGI declarative services. Useful for debugging issues with declarative services.

osgi> ls -c 152
Components in bundle org.wso2.carbon.bam.gadgetgenwizard:
ID Component details
17 Component[
name = gadgetgenwizard.component
factory = null
autoenable = true
immediate = true
implementation = org.wso2.carbon.bam.gadgetgenwizard.internal.GadgetGenWizardServiceComponent
state = Unsatisfied
properties = {service.pid=gadgetgenwizard.component}
serviceFactory = false
serviceInterface = null
references = {
Reference[name = config.context.service, interface = org.wso2.carbon.utils.ConfigurationContextService, policy = dynamic, cardinality = 1..1, target = null, bind = setConfigurationContextService, unbind = unsetConfigurationContextService]
Reference[name = server.configuration, interface = org.wso2.carbon.base.api.ServerConfigurationService, policy = dynamic, cardinality = 1..1, target = null, bind = setServerConfiguration, unbind = unsetServerConfiguration]
}
located in bundle = org.wso2.carbon.bam.gadgetgenwizard_4.0.0.SNAPSHOT [152]
]
Dynamic information :
The component is satisfied
All component references are satisfied
Component configurations :
Configuration properties:
service.pid = gadgetgenwizard.component
component.name = gadgetgenwizard.component
component.id = 16
Instances:
org.eclipse.equinox.internal.ds.impl.ComponentInstanceImpl@3fabb84d
Bound References:
String[org.wso2.carbon.utils.ConfigurationContextService]
-> org.wso2.carbon.utils.ConfigurationContextService@22d0e7e3
String[org.wso2.carbon.base.api.ServerConfigurationService]
-> org.wso2.carbon.base.ServerConfiguration@4127f9f0