Bablu
Posts: 0
Joined: Sat Mar 09, 2013 3:44 pm

Json request with number parameter

My json request should look like:

https://technet.rapaport.com/HTTP/JSO...
{
"request": {
"header": {
"username": "XXXXXX",
"password": "XXXXXX"

},
"body":{
"shape": "round",
"size": 2.10,
"color": "E",
"clarity": "VS2"

} } }

what will be the setting of Rest service?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Json request with number parameter

Can you show us a curl command that works against your service? It's not clear whether 'request' is part of the body or only defines the request header parameters.

Bablu
Posts: 0
Joined: Sat Mar 09, 2013 3:44 pm

Json request with number parameter

Here is the sample code of service i am trying to use.

http://technet.rapaport.com/Info/Pric...

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Json request with number parameter

Looks like you need to upload data. You could do it in a similar fashion as uploading files: http://docs.tiggzi.com/tutorials/uplo...

We don't have an option yet to specify data to upload when defining a REST service via wizard.

Bablu
Posts: 0
Joined: Sat Mar 09, 2013 3:44 pm

Json request with number parameter

Max, no i don't need to upload data.
The example cited above showed the sample request to access the json data from their(rapaport) web service.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Json request with number parameter

It shows a POST example.. so it's to write data, not to get it.

Bablu
Posts: 0
Joined: Sat Mar 09, 2013 3:44 pm

Json request with number parameter

Yes it's post but it returns the diamonds of round shape. And i could actually get the data in a java class i wrote.But i am not able to do so from tiggzi rest service GUI.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Json request with number parameter

Can you show the code you used to send a POST request with Java?

Bablu
Posts: 0
Joined: Sat Mar 09, 2013 3:44 pm

Json request with number parameter

Yes sure. But the code is using xml,a different web service url for data exchange. If i can replicate this in tiggzi, it will be great. It prints result on console. I am sending credentials also in code.Please strip them out once u have done testing. Thanks

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public final class WebServiceCodeSample {
private static final String TECHNET_NAMESPACE_PREFIX = "technet";
private static final String WEBSERVICE_SECURE_URL =
"https://technet.rapaport.com/webservi...";
private static final String WEBSERVICE_INSECURE_URL =
"http://technet.rapaport.com/webservic...";

private enum Shapes {
ROUND("Round"), PEAR("Pear");

private final String enumString;

private Shapes(final String enumString) {
this.enumString = enumString;
}
};

public static void main(String[] args) throws Exception {
final WebServiceCodeSample webServiceCodeSample = new WebServiceCodeSample();
final String authenticationTicket = webServiceCodeSample.login("86120", "21Dricha");

webServiceCodeSample.getPrice(authenticationTicket, "Round", 0.4F, "D", "VS1");
webServiceCodeSample.getPriceSheet(authenticationTicket, Shapes.ROUND);
}

/**

  • Get the login token
    *

  • @param username

  • @param password

  • @return The authentication ticket

  • @throws SOAPException
    */
    private String login( final String username, final String password) throws SOAPException {
    final SOAPMessage soapMessage = getSoapMessage();
    final SOAPBody soapBody = soapMessage.getSOAPBody();
    final SOAPElement loginElement = soapBody.addChildElement("Login", TECHNET_NAMESPACE_PREFIX);

    loginElement.addChildElement("Username", TECHNET_NAMESPACE_PREFIX).addTextNode(username);
    loginElement.addChildElement("Password", TECHNET_NAMESPACE_PREFIX).addTextNode(password);

    soapMessage.saveChanges();

    final SOAPConnection soapConnection = getSoapConnection();
    final SOAPMessage soapMessageReply = soapConnection.call(soapMessage,WEBSERVICE_SECURE_URL);
    final String textContent = soapMessageReply.getSOAPHeader().getFirstChild().getTextContent();

    soapConnection.close();

    return textContent;
    }

    /**

  • Returns the price
    *

  • @param authenticationTicket

  • @param shape

  • @param size

  • @param color

  • @param clarity

  • @throws SOAPException
    */
    private void getPrice( final String authenticationTicket, final String shape, final float size, final String color,
    final String clarity) throws SOAPException {
    final SOAPMessage soapMessage = getSoapMessage();

    addAuthenticationTicket(authenticationTicket, soapMessage);

    final SOAPBody soapBody = soapMessage.getSOAPBody();
    final SOAPElement getPriceElement = soapBody.addChildElement("GetPrice", TECHNET_NAMESPACE_PREFIX);
    getPriceElement.addChildElement("shape", TECHNET_NAMESPACE_PREFIX).addTextNode(shape);
    getPriceElement.addChildElement("size", TECHNET_NAMESPACE_PREFIX).addTextNode(String.valueOf(size));
    getPriceElement.addChildElement("color", TECHNET_NAMESPACE_PREFIX).addTextNode(color);
    getPriceElement.addChildElement("clarity", TECHNET_NAMESPACE_PREFIX).addTextNode(clarity);

    soapMessage.saveChanges();

    final SOAPConnection soapConnection = getSoapConnection();

    final SOAPMessage soapMessageReply = soapConnection.call(soapMessage,WEBSERVICE_INSECURE_URL);

    final SOAPBody replyBody = soapMessageReply.getSOAPBody();
    final Node getPriceResponse = replyBody.getFirstChild();
    final Node getPriceResult = getPriceResponse.getFirstChild();

    final NodeList childNodes = getPriceResult.getChildNodes();
    final String replyShape = childNodes.item(0).getTextContent();
    final String lowSize = childNodes.item(1).getTextContent();

    // ... etc etc
    // You can create a bean that will encompass all elements

    soapConnection.close();
    } /**

  • Gets the price sheet
    *

  • @param authenticationTicket

  • @param shapes

  • @throws SOAPException

  • @throws TransformerException
    */
    private void getPriceSheet( final String authenticationTicket, final Shapes shapes)
    throws SOAPException, TransformerException {
    final SOAPMessage soapMessage = getSoapMessage();

    addAuthenticationTicket(authenticationTicket, soapMessage);

    final SOAPBody soapBody = soapMessage.getSOAPBody();

    final SOAPElement getPriceSheetElement =
    soapBody.addChildElement("GetPriceSheet", TECHNET_NAMESPACE_PREFIX);

    getPriceSheetElement.addChildElement(
    "shape", TECHNET_NAMESPACE_PREFIX).addTextNode(shapes.enumString);

    soapMessage.saveChanges();

    final SOAPConnection soapConnection = getSoapConnection();
    final SOAPMessage soapMessageReply = soapConnection.call(soapMessage, WEBSERVICE_INSECURE_URL);

    // this will print out the result
    // Create transformer

    final TransformerFactory tff = TransformerFactory.newInstance();
    final Transformer tf = tff.newTransformer();

    // Get reply content
    final Source sc = soapMessageReply.getSOAPPart().getContent();

    // Set output transformation
    final StreamResult result = new StreamResult(System.out);
    tf.transform(sc, result);
    System.out.println();

    // Close connection
    soapConnection.close();
    }

    /**

  • Create a SOAP Connection
    *

  • @return

  • @throws UnsupportedOperationException

  • @throws SOAPException
    */
    private SOAPConnection getSoapConnection() throws UnsupportedOperationException, SOAPException {
    final SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    final SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    return soapConnection;
    }

    /**

  • Create the SOAP Message
    *

  • @return

  • @throws SOAPException
    */
    private SOAPMessage getSoapMessage() throws SOAPException {
    final MessageFactory messageFactory = MessageFactory.newInstance();
    final SOAPMessage soapMessage = messageFactory.createMessage();

    // Object for message parts
    final SOAPPart soapPart = soapMessage.getSOAPPart();
    final SOAPEnvelope envelope = soapPart.getEnvelope();

    envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
    envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-inst...");
    envelope.addNamespaceDeclaration("enc", "http://schemas.xmlsoap.org/soap/encod...");
    envelope.addNamespaceDeclaration("env", "http://schemas.xmlsoap.org/soap/envelop/");

    // add the technet namespace as "technet"
    envelope.addNamespaceDeclaration(TECHNET_NAMESPACE_PREFIX, "http://technet.rapaport.com/");

    envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encod...");

    return soapMessage;
    }

    private void addAuthenticationTicket( final String authenticationTicket, final SOAPMessage soapMessage)
    throws SOAPException {
    final SOAPHeader header = soapMessage.getSOAPHeader();
    final SOAPElement authenticationTicketHeader =
    header.addChildElement("AuthenticationTicketHeader", TECHNET_NAMESPACE_PREFIX);
    authenticationTicketHeader.addChildElement(
    "Ticket", TECHNET_NAMESPACE_PREFIX).addTextNode(authenticationTicket);
    }
    }

Bablu
Posts: 0
Joined: Sat Mar 09, 2013 3:44 pm

Json request with number parameter

The json web service allows us to send credentials in each request, so we don't need to send authentication ticket in each request as this java example does. For me any method is fine, as long as i receive data.

Return to “Issues”