i used rxtx serial api in spring frame work. i can use it in my local host but it doesnt working hosting site - web-hosting

i used rxtx serial api in spring frame work.
i can use it in my local host but it doesnt working hosting site
i can not use rxtx serial communication jar in web page ?
""#SuppressWarnings("restriction")
public Map<String,Object> printbarcode(Map<String, Object> paramMap) throws Exception {
//new barcode
String barcode = String.valueOf(paramMap.get("barcode"));
String equipcd = String.valueOf(paramMap.get("equipcd"));
Map<String,Object> rtnMap = new HashMap<String, Object>();
System.out.println("barcode : " + barcode);
System.out.println("바코드 기기전송 서비스 call " + barcode);
RequestParams<EquipMasterVO> Params = new RequestParams<EquipMasterVO>();
Params.put("company", "1000");
Params.put("equipCd", "QRPRINTER");
List<EquipMasterVO> EquipList = equipMasterMapper.getEquipList(Params);
if(EquipList.size() > 0){
String EquipCd = EquipList.get(0).getEquipCd();
String EquipSpec = EquipList.get(0).getEquipSpec();
String EquipType = EquipList.get(0).getEquipType();
String EquipNm = EquipList.get(0).getEquipNm();
System.out.println("EquipCd : " + EquipCd);
System.out.println("EquipSpec : " + EquipSpec);
System.out.println("EquipType : " + EquipType);
System.out.println("Equip : " + EquipNm);
try{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(EquipSpec);
System.out.println("portIdentifier : " + portIdentifier);
if (portIdentifier.isCurrentlyOwned())
{
System.out.println("Error: Port is currently in use");
//비정상 동작
rtnMap.put("MSG", "QR코드 인쇄처리 중 에러가 발생하였습니다. \n사용 중인 포트 입니다.");
}
else
{
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
if (commPort instanceof SerialPort)
{
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
try {
// Add the serial port event listener
serialPort.addEventListener(new SerialEventHandler());
serialPort.notifyOnDataAvailable(true);
} catch (TooManyListenersException ex) {
System.err.println(ex.getMessage());
}
in = serialPort.getInputStream();
OutputStream out = serialPort.getOutputStream();
byte[] sendData = new byte[] {0x1b, 0x02, 0x00, 0x1c, 0x00, 0x00, 0x1e,
0x06, 0x51, 0x52, 0x43, 0x4f, 0x44, 0x45, 0x01, 0x04, 0x00, 0x03,
0x00, 0x03, 0x16, 0x03, 0x04, 0x00, 0x00, 0x01, 0x01, 0x09, 0x42,
0x32, 0x32, 0x30, 0x35, 0x30, 0x30, 0x35, 0x30, 0x1b, 0x03, 0x00};
byte[] sendPrintMessage = new byte[] { 0x1b, 0x02, 0x00, 0x01, 0x1b, 0x03, (byte)0xC4 };
byte[] sendStartPrintCommand = new byte[] { 0x1b, 0x02, 0x00, 0x11, 0x1b, 0x03, (byte)0xB4 };
byte[] qrData = barcode.getBytes();
System.arraycopy(qrData, 0, sendData, 28, qrData.length);
sendData[39] = ComputeAdditionChecksum(sendData);
out.write(sendData);
Thread.sleep(500);
out.write(sendPrintMessage);
Thread.sleep(500);
out.write(sendStartPrintCommand);
Thread.sleep(300);
if(keyVal)
{
//정상 동작
System.out.println("test good");
rtnMap.put("MSG", "QR코드 인쇄처리 되었습니다.");
}
else
{
//비정상 동작
System.out.println("test bad");
rtnMap.put("MSG", "QR코드 인쇄처리 중 에러가 발생하였습니다. \n시스템 관리자에게 문의하세요.");
}
serialPort.removeEventListener();
serialPort.close();
in.close();
out.close();
readBuffer = null;
keyVal = false;
}
else
{
//비정상 동작
System.out.println("Error: Only serial ports are handled by this example.");
rtnMap.put("MSG", "Error: Only serial ports are handled by this example.");
}
}
}catch (NoSuchPortException e) {
// TODO: handle exception
System.out.println("Error: Equip Port Nosuch");
rtnMap.put("MSG", "포트연결 에러");
}
}else{
//비정상 동작
System.out.println("설비가 존재하지 않습니다. 먼저 해당설비를 등록하세요.");
rtnMap.put("MSG", "설비가 존재하지 않습니다. 먼저 해당설비를 등록하세요.");
}
return rtnMap;
}
""""
i uesed this code and that code just liked with jsp button.

Related

Where does this ThisAdminToolGuid value come from in Modify Group Policy?

I see this guid value a lot in my references and I get the effect I want, but I don't know where ThisAdminToolGuid comes from?
And I didn't find this value in C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\um\GPEdit.h
GUID ThisAdminToolGuid =
/*{ CLSID_PolicySnapinUser/* */
{
0x0F6B957E,
0x509E,
0x11D1,
{ 0xA7, 0xCC, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3 }
};

How to add smime certificate to outlook contacts programmatically?

We're currently working on a project that requires adding S/MIME certificates to outlook contacts. Currently there's no api to add or retrieve S/MIME related information with existing solutions (We looked into Graph API but it doesn't provide the functionality. We've also looked into outlook addin JS docs. It also, doesn't reference anything related to S/MIME).
Our guess is that we need to add the certificates in the local device. We got this code snippet on Github which we think adds S/MIME certificate to our own email only but not contacts.
So, how to add or import S/MIME certificate of outlook contacts Programmatically?
I found a dated solution attempt in this post:
private static object[] BuildProperty(byte[] rawData)
{
using (MemoryStream ms = new MemoryStream())
{
byte[] headerWithoutLength = { 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00 };
ms.Write(headerWithoutLength, 0, headerWithoutLength.Length);
byte[] lengthBytes = BitConverter.GetBytes((short)(rawData.Length + 4));
ms.WriteByte(lengthBytes[0]);
ms.WriteByte(lengthBytes[1]);
ms.Write(rawData, 0, rawData.Length);
byte[] footer = { 0x06, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x08, 0x00,
0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00 };
ms.Write(footer, 0, footer.Length);
object[] o = new object[] { ms.ToArray() };
return o;
}
}
private static void Create()
{
OutLook.Application outlookObj = new OutLook.Application();
try
{
X509Certificate2 existingCert = new X509Certificate2(#"[path to my certificate].cer");
byte[] result = existingCert.RawData;
OutLook.MAPIFolder fldContacts = (OutLook.MAPIFolder)outlookObj.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts);
OutLook.ContactItem newContact = (OutLook.ContactItem)fldContacts.Items.Add(OutLook.OlItemType.olContactItem);
newContact.FirstName = "Test Name";
newContact.FileAs = "Test Name";
object[] o = BuildProperty(result);
newContact.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3A701102", o);
newContact.Save();
}
finally
{
Marshal.ReleaseComObject(outlookObj);
}
}
It creates a new contact and assigns a certificate to it.
To assign a certificate to an existing contact should be similar.
Additional error checking is required to make this snippet useful and trustworthy.

How to understand ACPI _OSC method defined in DSDT table

I am new to ACPI.
And I am trying to understand _OSC method defined in following DSDT table within Linux host.
Name (SUPP, 0x00)
Name (CTRL, 0x00)
Method (_OSC, 4, NotSerialized)
{
CreateDWordField (Arg3, 0x00, CDW1)
CreateDWordField (Arg3, 0x04, CDW2)
CreateDWordField (Arg3, 0x08, CDW3)
If (LEqual (Arg0, Buffer (0x10)
{
/* 0000 */ 0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40,
/* 0008 */ 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66
}))
{
Store (CDW2, SUPP)
Store (CDW3, CTRL)
And (CTRL, 0x0C, CTRL)
If (LNotEqual (Arg1, 0x01))
{
Or (CDW1, 0x0A, CDW1)
}
If (LNotEqual (CDW3, CTRL))
{
Or (CDW1, 0x10, CDW1)
}
Store (CTRL, CDW3)
}
Else
{
Or (CDW1, 0x06, CDW1)
}
Return (Arg3)
}
What does this method do, such as where are the SUPP/CTRL ?

How to initialize Nfc Tag if tag is empty and make it password protected in Xamarin Android?

I am using code for charge data in nfc tag and it's working if tag is already initialized and password protected. But I am facing problem to initialize an empty tag and I want to set Password to tag. How it can be done?
My code for authenticated tag is :
commandResponse = mifareUltralight.Transceive(getAuthenticateCmd());
Authenticate method is :
internal byte[] getAuthenticateCmd()
{
return new byte[5] {
0x1b,
password[0],
password[1],
password[2],
password[3]
};
}
Where Password is :
internal byte[] password = new byte[4] { 0x39, 0x39, 0x39, 0x39 };
When I am trying this code to authenticate empty tag it throws TagLostException.
first of all you should to check if the tag is protected by reading auth0, I would recommand this snip of code:
boolean isTagProtected() {
MifareUltralight mu = MifareUltralight.get(tag);
boolean passExist;
try {
mu.connect();
byte[] answer = mu.readPages(227);
byte auth0 = answer[3];
String text = String.format("%02x", auth0);
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
passExist = auth0 < (byte) 0xEB;
mu.close();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(context, "cannot make authentication", Toast.LENGTH_SHORT).show();
passExist = true;
}
return passExist;
}
if the tag is not protected you could set new password by this code:
private static final byte[] SET_PACK_VALUE = {(byte) 0xA2, (byte) 0xE6, (byte) 0x11, (byte) 0x11, (byte) 0x00, (byte) 0x00};
private static final byte[] SET_PASSWORD = {(byte) 0xA2, (byte) 0xE5, (byte) 0x75, (byte) 0x6C, (byte) 0x66, (byte) 0x30};
private static final byte[] SET_AUTH0_VALUE = {(byte) 0xA2, (byte) 0xE3, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA1};
if (isTagProtected()) {
Toast.makeText(context, "The tag is already Locked", Toast.LENGTH_LONG).show();
} else {
NfcA nfcaTag = NfcA.get(maintag);
try {
nfcaTag.connect();
nfcaTag.transceive(SET_PACK_VALUE);
nfcaTag.transceive(SET_PASSWORD);
nfcaTag.transceive(SET_AUTH0_VALUE);
nfcaTag.close();
Toast.makeText(context, "The tag is locked", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(context, "Error happend", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
it the tag is protected you could auth it to be able to read and write on tag for just one session.
Here how to clear the password :
private final byte[] pwd_auth = new byte[]{(byte) 0x1b,
//here write your pass (4 bytes)
};
public static final byte[] RESET_PACK_VALUE = {(byte) 0xA2, (byte) 0xE6, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
public static final byte[] RESET_AUTH0_VALUE = {(byte) 0xA2, (byte) 0xE3, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xFF};
MifareUltralight mfu = MifareUltralight.get(maintag);
try {
byte[] answer;
mfu.connect();
answer = mfu.transceive(pwd_auth);
mfu.transceive(MainActivity.RESET_AUTH0_VALUE);
mfu.transceive(MainActivity.RESET_PACK_VALUE);
mfu.close();
Toast.makeText(context, "The Password is deleted", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(context, "Error happend , wrong pass", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
in other words, you are trying to authenticate a tag wich dosen't have any password.
you should to set a password and then authenicate it.
more general details:
here are more details about tag tech:
the four parameters you need to edit some of them when you are dealing with password are :
PWD 32-bit password used for memory access protection.
Reading PWD always returns 00000000h .
PACK 16-bit password acknowledge used during the password
authentication process.
Reading PACK always returns 0000h
AUTH0 Page address of Sector 0 from which onwards the password
authentication is required to access the user memory from NFC
perspective, dependent on NFC_PROT bit.
If AUTH0 is set to a page address greater than EBh, the
password protection is effectively disabled. Password protected
area starts from page AUTH0 and ends at page EBh.
AUTHLIM no need to explain here.
P.S: I am using NT3H2111_2211 u should to read the link from Andrew in comments to know exactly where should you write PACK, PWD,and AUTH0.

validating format video file with HttpPostedFileBase

Is there a way to use the HttpPostedFileBase elements to find out if its a valid video file fomart (except of validating the extension). Im using aspnet mvc 3 by the way.
If you want to be absolutely certain, it is best to check the stream of the HttpPostedFileBase for magic bytes. This is because some applications may write it as an extension that you think you can process (such as MP4), but in reality it is another format such as M4V.
For example, to check if a stream is an MP4 variation stream, you can check if the stream starts with the bytes 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70 and 0x34. You can find more formats here.
Something like this may work:
public static bool IsMP4(System.IO.Stream stream)
{
return HasMagicBytes(stream, 0, 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34);
}
public static bool HasMagicBytes (System.IO.Stream stream, int offset, params byte[] magicBytes)
{
try {
bool match = false;
byte[] bytes = new byte[magicBytes.Length];
if (stream.Read (bytes, offset, magicBytes.Length) == magicBytes.Length) {
for (int i = 0; i < magicBytes.Length; i++) {
if (bytes [i] != magicBytes [i]) {
return false;
}
}
return true;
} else {
return false;
}
} finally {
stream.Seek (0, System.IO.SeekOrigin.Begin);
}
}
Some care should be taken whether the stream is seekable. This technique is rather efficient for larger files. To make this reusable, you can write a ValidationAttribute so it may be possible to define your model like this:
public class MyModel
{
[CheckFormat(0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34)]
public HttpPostedFileBase MyFile { get; set; }
}
But I'll leave that to you to investigate further.
There is no way of validating. You need to validate the file's extension. Maybe this will help : http://blog.tomasjansson.com/2011/08/creating-custom-unobtrusive-file-extension-validation-in-asp-net-mvc-3-and-jquery/

Resources