Skip to content

Commit

Permalink
Merge pull request #3 from hashmapinc/get_tagdata_dev
Browse files Browse the repository at this point in the history
changing to logger
  • Loading branch information
cherrera2001 authored May 30, 2017
2 parents c36ad0e + 8708355 commit 7f1622d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,46 +169,45 @@ public void onTrigger(ProcessContext context, ProcessSession session) throws Pro
}
// Write the results back out to a flow file
FlowFile flowFile = session.create();
if ( flowFile == null ) {
logger.error("Flowfile is null");
}



try{
flowFile = session.write(flowFile, new OutputStreamCallback() {
public void process(OutputStream out) throws IOException {
if ( flowFile != null ) {
try{
flowFile = session.write(flowFile, new OutputStreamCallback() {
public void process(OutputStream out) throws IOException {

switch (remove_opc_string) {
switch (remove_opc_string) {

case "Yes":{
String str = stringBuilder.toString();
String parts[] = str.split("\\r?\\n");
String outString = "";
for (int i = 0; i < parts.length; i++){
if (parts[i].startsWith("nsu")){
continue;
}
outString = outString + parts[i] + System.getProperty("line.separator");;
}
outString.trim();
out.write(outString.getBytes());
break;
}
case "No":{
out.write(stringBuilder.toString().getBytes());
break;
}
}
}
});
case "Yes":{
String str = stringBuilder.toString();
String parts[] = str.split("\\r?\\n");
String outString = "";
for (int i = 0; i < parts.length; i++){
if (parts[i].startsWith("nsu")){
continue;
}
outString = outString + parts[i] + System.getProperty("line.separator");;
}
outString.trim();
out.write(outString.getBytes());
break;
}
case "No":{
out.write(stringBuilder.toString().getBytes());
break;
}
}
}
});

// Transfer data to flow file
session.transfer(flowFile, SUCCESS);
}catch (ProcessException ex) {
logger.error("Unable to process", ex);
session.transfer(flowFile, FAILURE);
}
// Transfer data to flow file
session.transfer(flowFile, SUCCESS);
}catch (ProcessException ex) {
logger.error("Unable to process", ex);
session.transfer(flowFile, FAILURE);
}
}else{
logger.error("Flowfile is null");
session.transfer(flowFile, FAILURE);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
@CapabilityDescription("Provides client API for working with OPC servers")
public interface OPCUAService extends ControllerService {

//byte[] getValue(String reqTagname) throws ProcessException;
byte[] getValue(List<String> reqTagname) throws ProcessException;

String getNameSpace(String print_indentation, int max_recursiveDepth, List<ExpandedNodeId> expandedNodeIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,12 @@ public byte[] getValue(List<String> reqTagnames) throws ProcessException {
ReadValueId nodesToRead[] = new ReadValueId[reqTagnames.size()];

for (int i = 0; i < reqTagnames.size(); i++){
nodesToRead[i] = (new ReadValueId(NodeId.parseNodeId(reqTagnames.get(i)), Attributes.Value, null, null));
}
try{
nodesToRead[i] = (new ReadValueId(NodeId.parseNodeId(reqTagnames.get(i)), Attributes.Value, null, null));
}catch(Exception ex){
logger.error("error reading nodeId for" + reqTagnames.get(i));
}
}

String serverResponse = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import org.opcfoundation.ua.transport.security.SecurityPolicy;
import org.opcfoundation.ua.utils.CertificateUtils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Utils {

private static final Logger logger = LoggerFactory.getLogger(Utils.class);
static String PRIVKEY_PASSWORD = "Opc.Ua";

public static KeyPair getCert(String applicationName) {
Expand All @@ -49,9 +51,10 @@ public static KeyPair getCert(String applicationName, String cert, String key, o
PrivKey myServerPrivateKey = PrivKey.load( privKeyFile, PRIVKEY_PASSWORD );
return new KeyPair(myServerCertificate, myServerPrivateKey);
} catch (CertificateException e) {
System.out.println(e.toString());
logger.debug("Error while loading certificate ");
logger.error(e.getMessage());
} catch (NoSuchAlgorithmException e) {
System.out.println(e.toString());
logger.error(e.getMessage());
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down Expand Up @@ -107,7 +110,7 @@ public static KeyPair getCert(String applicationName, String cert, String key, o
return keys;

} catch (Exception e1) {
System.out.println(e1.toString());
logger.error(e1.getMessage());
}
}
return null;
Expand All @@ -122,14 +125,14 @@ public static KeyPair getHttpsCert(String applicationName){
return new KeyPair(myServerCertificate, myServerPrivateKey);
} catch (CertificateException e) {

System.out.println(e.toString());
logger.error(e.getMessage());
} catch (NoSuchAlgorithmException e) {

System.out.println(e.toString());
logger.error(e.getMessage());
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block

System.out.println(e.toString());
logger.error(e.getMessage());
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block

Expand Down Expand Up @@ -164,7 +167,7 @@ public static KeyPair getHttpsCert(String applicationName){
keys.save(certFile, privKeyFile, PRIVKEY_PASSWORD);
return keys;
} catch (Exception e1) {
System.out.println(e1.toString());
logger.error(e1.getMessage());
}
}
return null;
Expand All @@ -178,18 +181,18 @@ public static KeyPair getCACert(){
PrivKey myServerPrivateKey = PrivKey.load( privKeyFile, PRIVKEY_PASSWORD );
return new KeyPair(myServerCertificate, myServerPrivateKey);
} catch (CertificateException e) {
System.out.println(e.toString());
logger.error(e.getMessage());
} catch (IOException e) {
try {
KeyPair keys = CertificateUtils.createIssuerCertificate("NifiCA", 3650, null);
keys.getCertificate().save(certFile);
keys.getPrivateKey().save(privKeyFile, PRIVKEY_PASSWORD);
return keys;
} catch (Exception e1) {
System.out.println(e1.toString());
logger.error(e1.getMessage());
}
} catch (NoSuchAlgorithmException e) {
System.out.println(e.toString());
logger.error(e.getMessage());
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit 7f1622d

Please sign in to comment.