Accessing Spira test using rest web services in java

Thursday, February 16, 2017
Avatar
Hi All,

I am new to Spira test and its API. Can anyone help me with a sample java code which authenticates and does request and response using the Spira API.

Also I am trying to do a maven repository set up, please provide me dependency if any.

Thanks,
Manoj
2 Replies
Friday, February 17, 2017
Avatar
re: manojsingh7 Thursday, February 16, 2017

Hi Manoj

Please try this out:

https://www.inflectra.com/Support/KnowledgeBase/KB49.aspx

Regards

Adam

Monday, February 20, 2017
Avatar
re: inflectra.david Friday, February 17, 2017

Hi Adam,

I am going through this example. But this example uses SOAP services. However i am looking for rest api which i am able to connect through java code.

    public final String BASE_URL = "http://api.inflectra.com/Spira/Services/v4_0/RestService.svc";
    public final String USER_NAME = "";
    public final String API_KEY="";
      
    public static void main( String[] args )
    {
        try
        {
            ClientConfig clientConfig = new DefaultClientConfig();
            Client client = Client.create(clientConfig);
            
            WebResource resource = client.resource(BASE_URL);
//            resource.header("username", USER_NAME);
//            resource.header("api-key", API_KEY);
            resource.queryParam("username", USER_NAME);
            resource.queryParam("api-key", API_KEY);
            
            ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
            
            System.out.println(response.getStatus());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

 

this is my sample code for connecting spira rest url. i am getting exception as fallows

com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: api.inflectra.com
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
    at com.sun.jersey.api.client.Client.handle(Client.java:652)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509)
    at com.iDRT.controller.SpiraConnection.main(SpiraConnection.java:34)
Caused by: java.net.UnknownHostException: api.inflectra.com
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:253)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:153)
    ... 5 more

 

 

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Thursday, February 16, 2017
  • Last Reply: Monday, February 20, 2017
  • Replies: 2
  • Views: 7488