Rest full Web Services
Representational State Transfer (REST) is an architectural style for building distributed systems. The Web is an example for such a system. REST-style applications can be built using a wide variety of technologies. REST's main principles are those of resource-oriented states and functionalities, the idea of a unique way of identifying resources, and the idea of how operations on these resources are defined in terms of a single protocol for interacting with resources. REST-oriented system design leads to systems which are open, scalable, extensible, and easy to understand.
REST Definition
REST is an acronym standing for Representational State Transfer.
Motivation for REST
The motivation for REST was to capture the characteristics of the Web which made the Web successful. Subsequently these characteristics are being used to guide the evolution of the Web.
REST Concepts
Resources are defined by URIs
Resources are manipulated through their representations
Messages are self-descriptive and stateless
There can be multiple representations for a resource
Application state is driven by resource manipulations
REST is built around the idea of simplifying agreement
nouns are required to name the resources that can be talked about
verbs are the operations that can be applied to named resources
content types define which information representations are available
For most applications, HTTP's basic methods are sufficient
GET: Fetching a resource (there must be no side-effects)
PUT: Transfers a resource to a server (overwriting if there already is one)
POST: Adds to an existing resource on the server
DELETE: Discards a resource (its name cannot be used anymore)
Expose directory structure-like URIs
From the standpoint of client applications addressing resources, the URIs determine how intuitive the REST Web service is going to be and whether the service is going to be used in ways that the designers can anticipate
Stateless nature of restfull web services
REST Web services need to scale to meet increasingly high performance demands. Clusters of servers with load-balancing and failover capabilities, proxies, and gateways are typically arranged in a way that forms a service topology, which allows requests to be forwarded from one server to the other as needed to decrease the overall response time of a Web service call. Using intermediary servers to improve scale requires REST Web service clients to send complete, independent requests; that is, to send requests that include all data needed to be fulfilled so that the components in the intermediary servers may forward, route, and load-balance without any state being held locally in between requests.
I hope to share my knowledge with the others in software and networking industry
Brief Introduction to Rest full Web Services
How to generate Axiom OMElement Using input Stream
The method showed below is generate Axiom OMElement from input stream
/*** @param inputStream Reads input stream that use to build OMElement* @return OMElement that generated from input stream* @throws Exception at error in generating parser*/public static OMElement buildOMElement(InputStream inputStream) throws Exception {XMLStreamReader parser;try {parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);}catch (XMLStreamException e) {String msg = "Error in initializing the parser to build the OMElement.";log.error(msg, e);throw new Exception(msg, e);}finally {log.info("Reading data from configuration file");}StAXOMBuilder builder = new StAXOMBuilder(parser);return builder.getDocumentElement();}
we can call this method as follows
OMElement element=buildOMElement(new FileInputStream("File path String"));
If you need more information go to this link
How to read user input at command line -Java
public String readUserInput(String printMessage) throws IOException{
System.out.println(printMessage);
InputStreamReader isr = new InputStreamReader ( System.in );
BufferedReader br = new BufferedReader (isr);
String returnString;
try {
returnString=br.readLine();
} catch (IOException e) {
String message="error while reading user input";
log.error(message,e);
throw new IOException(e);
}
finally {
br.close();
isr.close()
}
return returnString;
}
Get Present Working Directory in Java Code
Most of projects we don't use absolute path instead we use relative path thats best practice. in this discussion we will see how to get string name of current working folder so after that we can get relative path corresponding to that base location . so simple just few lines :)
public static String getCurrentDirectory(){
String cwd = null;
try{
cwd = new java.io.File( "." ).getCanonicalPath();
} catch (java.io.IOException e)
{
log.error("Error in getting present working Directory");
}
return cwd;
}
How to use regular Expressins in String manipulation
Regular expressions are power full and efficient. i used them recently for my project and here i will just show few usages of it
Its so simple
Pattern p = Pattern.compile(regexPatternString);Matcher m = p.matcher(textString);
then evaluate using
if(m.matches()){
//write what ever if that match you want to do}//pattern to get character contains only 1 to 3(1,2,3) and letter c( C and c)
Pattern p = Pattern.compile("[.1-3cC]");
//only Numerical values string that contains only digits and any number of digits
Pattern p = Pattern.compile(("[0-9].*")
//get string that only contains "sanjeewa" or "malalgoda"
Pattern p = Pattern.compile(("sanjeewa|malalgoda")
Get Tag value fro XML Document(org.w3c.dom.Document) -Blackberry Java development
/**
* @param document
* @param node
* @param index
* @return element value
* getTag(Document document, String node,int index)
*/
public static String getTag(Document document, String node,int index)
{
NodeList nodeList = document.getElementsByTagName(node);
String returnString = "";
if (nodeList != null && nodeList.getLength() > 0) {
nodeList = nodeList.item(index).getChildNodes();
if (nodeList != null && nodeList.getLength() > 0) {
returnString = nodeList.item(0).getNodeValue();
}
}
return returnString;
}
How to Read RSA Encrypted File to Encoded Image -Java BlackBerry Develpment
/**
* @param path
* @return encoded base64 string String encodeToBase64(String path)
* @throws IOException
* @throws CryptoUnsupportedOperationException
* @throws CryptoTokenException
* @throws CryptoException
*/
public static EncImage encodeToBase64(String path) throws IOException, CryptoException, CryptoTokenException, CryptoUnsupportedOperationException {
EncImage encImage = new EncImage();
FileConnection fileConToRead = null;
InputStream inputStream=null;
try {
fileConToRead = (FileConnection) Connector.open("file://" + path, Connector.READ);
int size = (int) fileConToRead.fileSize();
inputStream = fileConToRead.openInputStream();
byte bytes[] = new byte[size];
inputStream.read(bytes, 0, size);
// If RSA enables
if (Main.isRSAEncrypted) {
CryptoRSA cryptoRSA = new CryptoRSA();
bytes = cryptoRSA.decrypt(bytes);
}
EncodedImage image = EncodedImage.createEncodedImage(bytes, 0, bytes.length);
encImage.setImageHeight(image.getHeight());
encImage.setImageWidth(image.getWidth());
byte encodedBytes[] = Base64.encodeBase64(bytes);
encImage.setEncodesString(new String(encodedBytes));
} finally {
try {
// try to close the FileConnection
fileConToRead.close();
inputStream.close();
} catch (IOException e) {
//finally connection assigns to null
}
// connection set to null
fileConToRead = null;
inputStream=null;
}
return encImage;
}
Subscribe to:
Posts (Atom)
Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release
Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...
-
First you have to download the font file "filename.ttf" to you machine. Then you need some permissions to add those files to fold...
-
Remove current installation of Nginx sudo apt-get purge nginx nginx-common nginx-full Install Nginx sudo apt-get install nginx Edit c...
-
Here i'm explaining solution for manage multiple API Manager environments and external key management server to build central API r...