java

Preventing SQL-Injection in a Java application

Sql-Injection is a technique to inject (or execute) SQL commands within an application (database). It is mainly used to gain access to a databases content for which one has no authorization. The method injects SQL commands by providing input to a SQL statement which contains SQL meta-characters. Example statement: <strong>select * from user where username='input'</strong> SQL injected input:<strong>user' OR '1'='1</strong> The final statement:<strong>select * from user where username='user' OR '1'='1'</strong> Since 1 always equals 1, this statement would return all the users in the database! Depending on the SQL command, an attacker could insert, modify, extract and delete data in the database.

Send SMS in Java

 You can use this free Java sample program to send SMS from your PC using GSM modem connected to your computer to your COM port. You also need to download and install the Java comm api from Sun.This program needs the following java files to function.1. SerialConnection.java (This file is used to connect to your COM port from your java program)2. SerialConnectionException.java (This file is for handling serial connection exceptions in your Java program)3. SerialParameters.java (This program is used to set your COM port properties for connecting to your com port from your java program)4. Sender.java (This is the program that implements runnable and sends SMS using the serial connection)5. SMSClient.java (This java class is the main class that can be instantiated in your own java program and called to send SMS. This program in turn will use all the above four files internally to send out your SMS). /*
*
* A free Java sample program
* A list of java programs to send SMS using your COM serial connection
* and a GSM modem
*
* @author William Alexander
* free for use as long as this comment is included
* in the program as it is
*
* More Free Java programs available for download
* at http://www.java-samples.com
*
*
* Note: to use this program you need to download all the 5 java files
* mentioned on top
*
*/
public class SMSClient implements Runnable{

public final static int SYNCHRONOUS=0;
public final static int ASYNCHRONOUS=1;
private Thread myThread=null;

private int mode=-1;
private String recipient=null;
private String message=null;

public int status=-1;
public long messageNo=-1;

public SMSClient(int mode) {
this.mode=mode;
}

public int sendMessage (String recipient, String message){
this.recipient=recipient;
this.message=message;
//System.out.println("recipient: " + recipient + " message: " + message);
myThread = new Thread(this);
myThread.start();
// run();
return status;
}
public void run(){

Sender aSender = new Sender(recipient,message);

try{
//send message
aSender.send ();

// System.out.println("sending ... ");

//in SYNCHRONOUS mode wait for return : 0 for OK,
//-2 for timeout, -1 for other errors
if (mode==SYNCHRONOUS) {
while (aSender.status == -1){
myThread.sleep (1000);
}
}
if (aSender.status == 0) messageNo=aSender.messageNo ;

}catch (Exception e){

e.printStackTrace();

}

this.status=aSender.status ;

aSender=null;

}
}  

Taggings:

How to Send SMS in Java

<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;"><span style="mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-font-kerning: 18.0pt;">We want to write a java code and use it in order to be able to send SMS</span><span style="mso-bidi-language: AR-SY; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-font-kerning: 18.0pt;">&acute;s to a mobile phone through http </span></span></span></span></p>

prepare an application server to handle secure connections

<p>In a web application users can collect information on their (or their company's) assets and plan future actions.</p><p>This information is of great value, so the user wants to keep it safe.</p><p>One basic task for a trustworthy service provider is, to let the user know if the connection is established indeed between the two.</p><p>In web applications this is usually accomplished by using a secure connection during user authentication.</p><p>So, an application server should be able to provide such secure connections.</p><p>For this task a SSL/TLS certificate is required. too bad, that there is none for this machine yet.</p>

Securing a service using WS-Security

<p>We have an existing Web-Service accessible to everyone who knows the address of the endpoint. The software used on the server:</p><ul><li>Java 6</li><li>Apache CXF 2.2.3</li><li>SOAP Webservice</li></ul><p>Because of massive abuse in the past the access should be limited to authorized people only. The login credentials are stored in a database and should be checked with every request made on the service. The login data should be transmitted in the SOAP-Envelope header and an interceptor should&nbsp; verify the data before the actual invocation of a webservice method. The solution should be based on an open standard which is well defined.</p>

Connect remotely located Java applications and database

<p>A library has a management software implemented by Java. This software is going to be used as a server application which is located in Vienna. A database including all book informations of the same library is located in London. Find out an appropriate technology by which a client Java application located in Paris can search the book informations of the library remotely.</p>

Converting XML to JSON and JSON to XML by using Javascript or Java

 There are several tested solutions available on the Internet already: JAVASCRIPT Solution approach:  It provides 

  • XML to JSON

   Download Skript: http://www.thomasfrank.se/downloadableJS/xml2json.js  Usage as documented on this site: <head><script type="text/javascript" src="xml2json.js"></script>...</head>Then it can be called in these different variants: 

  1. V1: /*A simple call - myXML is a string containing your XML:*/ myJsonObject=xml2json.parser(myXML);
  2. V2: /*A 2:nd, optional, parameter is "tags not to convert" - for example <b> and <i>:*/ myJsonObject=xml2json.parser(myXML,'b,i')
  3. V3: /*A 3:rd, optional, parameter gives us a string showing us the JSON structure instead of the actual JSON object: */ myString=xml2json.parser(myXML,'','html');

 V1 ("compact") can be used for output without linebreaks or tabbing. V2 for normal output with linebreaks ant tabbing. V3 for HTML representation.JAVA solution approach  (which is solution I have already tested and which is provided by Json.org):    The Source files are available at http://json.org/java/ for many JSON issues in Java.    The relevant class is called XML and is viewable at:  

  It provides 

  • XML to JSON
  • JSON to XML

 

  1. Create your class
  2. Import org.json.XML;
  3. Prepare an xml input value: String xmlValue = "<..>";
  4. /*XML to JSON*/ Type: JSONObject jsonResult = XML.toJSONObject(xmlValue);
  5. /*JSON to XML*/ Type: String xmlResult = XML.toString(jsonResult);

  Naturally, the XML has to be well-formed and valid to produce a JSON object. The JSON objcect istself has to be valid again. It can be assumed that always correct outputs for valid inputs are retrieved according its high adoption in real world usage. 

Taggings:

How to convert XML to JSON by using JavaScript or Java?

<p>&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">Over the last years the simple data format JSON had a great inpetus in the service-oriented architecture and especially in the area of internet services. It is widely used because of its compactness and easy understandability.</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">&nbsp;</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">JSON is lightweight and was used for several of my projects. However, the convertion by hand (Or by an own routine) is an unacceptable quality problem.</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">&nbsp;</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">A transformation could look like the this example:</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">&nbsp;</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">The&nbsp;<strong>XML </strong>of image xml.png&nbsp;<span style="font-family: 'Trebuchet MS', sans-serif; font-size: 13px;">should be transformed to the&nbsp;<strong>JSON</strong> representation of image json.png.</span></p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px 'Trebuchet MS'; min-height: 15.0px;">So to a simple representation using curly braces.</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 13.0px 'Trebuchet MS';"><span style="font-family: Helvetica, sans-serif; font-size: small;"><span style="font-size: 12px;"><span style="font-family: 'Trebuchet MS', sans-serif; font-size: small;"><span style="font-size: 13px;"><br /></span></span></span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px Helvetica;">JavaScript could be used to convert the data before it is passed on to the Java application. The conversion could also be done in Java itself.</p><p>&nbsp;</p>

How to remote deploy a Web service to Apache Tomcat from within a Java program

The deployment of servlets to a Servlet container like Tomcat is usually a simple task: Just copy the developed servlet to a specific target directory. The container will then hot deploy it. The proposed task is however more complex: The goal is to make a programmatical remote deployment of a Web service. In other words, an already developed Web service is to be deployed from a PC to a remote server which is running a Tomcat Servlet container. This task has three major requirements: - First, the deployment has to be remote: The Web service is to be deployed onto a different machine. - Second, it is to be accomplished programmatically, which means that it is necessary to develop a software component (for example in Java) which will carry out that task. - Third, the deployment has to be “hot”, which means that the deployed Web service has to run after a short time, without the need to restart the server or its Servlet container. As an addition to the above it is interesting to know, how to use a Servlet container like Tomcat for Web service deployment. In short the goal is to develop an application which can “hot deploy” a Servlet containing one or more Web services onto a remote machine, which is only known to run an Apache Tomcat Servlet container. The process could be called: “Programmatical-remote-hot-deployment of a Web service to an Apache Tomcat Servlet container.”

RPC in the Java Platform

In distributed computing, there is an essential need for the applications in the distributed environment to be able to use the functionalities offered by each application without knowing how these functionalities are implemented. One common possibility for this is the Remote procedure call (RPC), which is an Inter-Proccess communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network). Java Remote Method Invocation is the Java implementation of Remote Procedure Call. In the solution for this "Problem", we will take a look at the mechanism of Java RMI.

Pages

Subscribe to java