ping CDC device in to Machine(our desktop or notebook)

step 1: config the device into system and vice versa
this configuration in linux machine
1. ifconfig usb0 ip1 netmask maskid (this at linux machine) - machine -1
eg:- ifconfig 10.100.100.101 usb0 netmask 255.255.255.0
2. ifconfig usb0 ip2 netmask maskid (this is at device machine) - machine 2
eg:- ifconfig 10.100.100.102 usb0 netmask 255.255.255.0

Call webservice

private DataGenerator() throws Exception {
ResourceBundle bundle = ResourceBundle.getBundle("configuration");
URL url = new URL(bundle.getString("Delegator_Service_WSDL"));
soapHandler = new SOAPMessageHandler(url);
}


/**
* Constructor for SOAPMessageHandler. It takes the endpoint URL as a
* parameter.
*
* @param endPoint -
* The service endpoint URL.
*/
public SOAPMessageHandler(URL endPoint) {
this.endPoint = endPoint;
StringBuffer sb = new StringBuffer("")
.append(
"")
.append("");
soapEnvBegin = sb.toString();
soapEnvEnd = "" + "";
}

/**
* This method writes the XML section to call the authenticate method on
* Delegator
*
* @param username -
* The username to access Delegator.
* @param password -
* The password to access Delegator.
* @return 0 if the username/password is invalid else will return the
* non-zero userid.
* @throws DelegatorServiceException
*/
public String authenticate(String username, String password)
throws DelegatorServiceException {
String requestSOAPMessage = new StringBuffer(soapEnvBegin).append(
"").append(username).append(
"").append(password).append(
"").append(soapEnvEnd).toString();
String result = null;
try {
result = callService(requestSOAPMessage, "");
result = getBodyData(result);
if (result != null) {
if (!result.startsWith("")) {
result = getBodyData(result);
} else {
GetResultSet getResult = new GetResultSet();
result = getResult.getErrorCode(result);
result = getCode(result);
}
}
} catch (Exception e) {
throw new DelegatorServiceException(
Constants.APPLICATION_OUT_OF_ORDER);
}
return result;
}

/**
* This method takes the soap request envelope and the soap action to be
* called & returns the response from server
*
* @param soapPacket -
* SOAP request envelope.
* @param soapAction -
* SOAPACTION to be used.
* @return SOAP response envelope.
* @throws IOException
*/
private String callService(String soapPacket, String soapAction)
throws Exception {
String result = "";
HttpURLConnection connection = (HttpURLConnection) endPoint
.openConnection();
connection.setRequestMethod("POST");
// connection.setRequestProperty("SOAPACTION", soapAction);
connection.setRequestProperty(soapPacket, "SOAPACTION");
connection
.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setDoOutput(true);
connection.setDoInput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection
.getOutputStream());
writer.write(soapPacket);
writer.flush();
InputStream is = null;
try {
is = connection.getInputStream();
} catch (Exception e) {
is = connection.getErrorStream();
} finally {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
String str = null;
StringBuffer str2;
str2 = new StringBuffer("");
while ((str = reader.readLine()) != null) {
str2.append(str);
}
result = str2.toString();
// System.out.println("*^*^*^*^*^*^*^*^*^*^*^*"+result);
reader.close();
writer.close();
connection.disconnect();
}
return result;
}


Comments

Popular posts from this blog

Spring MVC with Sqlite sample

Struts Tutorial Page