use of org.geotoolkit.sml.xml.v100.Connection in project developer-be by EdgeGallery.
the class ShhFileUploadUtil method remoteUploadFile.
private void remoteUploadFile(ScpConnectEntity scpConnectEntity, File file, String remoteFileName) throws JSchException, IOException {
LOGGER.info("start remote upload file.");
Connection connection = null;
ch.ethz.ssh2.Session session = null;
SCPOutputStream scpo = null;
FileInputStream fis = null;
try {
createDir(scpConnectEntity);
} catch (JSchException e) {
LOGGER.error("create directory failed, {}", e.getMessage());
throw e;
}
try {
connection = new Connection(scpConnectEntity.getUrl());
connection.connect();
if (!connection.authenticateWithPassword(scpConnectEntity.getUserName(), scpConnectEntity.getPassWord())) {
LOGGER.error("connect failed on authentication.");
throw new RuntimeException("connect failed on authentication.");
}
LOGGER.info("file length = " + file.length());
session = connection.openSession();
SCPClient scpClient = connection.createSCPClient();
scpo = scpClient.put(remoteFileName, file.length(), scpConnectEntity.getTargetPath(), "0666");
fis = new FileInputStream(file);
byte[] buf = new byte[10240];
int dataSize = fis.read(buf);
while (dataSize != -1) {
scpo.write(buf);
scpo.flush();
dataSize = fis.read(buf);
}
} catch (IOException e) {
LOGGER.error("upload file failed, {}", e.getMessage());
throw e;
} finally {
if (null != fis) {
try {
fis.close();
} catch (IOException e) {
LOGGER.error("close fis failed, {}", e.getMessage());
}
}
if (null != scpo) {
try {
scpo.close();
} catch (IOException e) {
LOGGER.error("close scpo failed, {}", e.getMessage());
}
}
if (null != session) {
session.close();
}
if (null != connection) {
connection.close();
}
}
}
use of org.geotoolkit.sml.xml.v100.Connection in project AGREE by loonwerks.
the class AgreeASTBuilder method getConnectionStatements.
private List<AgreeOverriddenConnection> getConnectionStatements(EList<SpecStatement> specs) {
List<AgreeOverriddenConnection> conns = new ArrayList<>();
for (SpecStatement spec : specs) {
if (spec instanceof ConnectionStatement) {
Expr expr = doSwitch(((ConnectionStatement) spec).getExpr());
Connection conn = (Connection) ((ConnectionStatement) spec).getConn();
AgreeOverriddenConnection agreeConn = new AgreeOverriddenConnection(new AgreeStatement("", expr, spec), conn);
conns.add(agreeConn);
}
}
return conns;
}
use of org.geotoolkit.sml.xml.v100.Connection in project AGREE by loonwerks.
the class AgreeValidator method checkConnectionStatement.
@Check(CheckType.FAST)
public void checkConnectionStatement(ConnectionStatement conn) {
Classifier container = conn.getContainingClassifier();
if (container instanceof ComponentImplementation) {
NamedElement aadlConn = conn.getConn();
if (aadlConn == null) {
return;
}
if (!(aadlConn instanceof Connection)) {
error(conn, "The connection label in the connection statement is not a connection");
return;
}
TypeDef rhsType = (AgreeTypeSystem.infer(conn.getExpr()));
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, rhsType)) {
error(conn, "The expression for the connection statement is of type '" + nameOfTypeDef(rhsType) + "' but must be of type 'bool'");
}
} else {
error(conn, "Connection statements are allowed only in component implementations.");
}
warning(conn, "Connection statements are deprecated and will be removed in a future version of AGREE.");
}
use of org.geotoolkit.sml.xml.v100.Connection in project AGREE by loonwerks.
the class AgreeValidator method checkLiftContract.
@Check(CheckType.FAST)
public void checkLiftContract(LiftContractStatement lcst) {
Classifier comp = lcst.getContainingClassifier();
if (comp instanceof ComponentImplementation) {
ComponentType ct = ((ComponentImplementation) comp).getType();
List<AnnexSubclause> agreeAnnexes = AnnexUtil.getAllAnnexSubclauses(ct, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (agreeAnnexes.size() > 0) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whose type has an AGREE annex.");
}
List<Subcomponent> subcomps = ((ComponentImplementation) comp).getAllSubcomponents();
if (subcomps.size() == 1) {
Subcomponent subcomp = subcomps.get(0);
Classifier subCls = subcomp.getClassifier();
ComponentType subCt = null;
if (subCls instanceof ComponentImplementation) {
subCt = ((ComponentImplementation) subCls).getType();
} else if (subCls instanceof ComponentType) {
subCt = (ComponentType) subCls;
} else {
throw new RuntimeException();
}
{
Set<String> usedParentInPorts = new HashSet<>();
Set<String> usedParentOutPorts = new HashSet<>();
Set<String> usedChildInPorts = new HashSet<>();
Set<String> usedChildOutPorts = new HashSet<>();
EList<Classifier> ctPlusAllExtended = ct.getSelfPlusAllExtended();
EList<Classifier> subCtPlusAllExtended = subCt.getSelfPlusAllExtended();
for (Connection conn : ((ComponentImplementation) comp).getAllConnections()) {
{
NamedElement sourceNe = conn.getSource().getConnectionEnd();
if (subCtPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
if (usedChildOutPorts.contains(sourceNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same output " + sourceNe.getQualifiedName() + ".");
}
usedChildOutPorts.add(sourceNe.getName());
}
if (ctPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
if (usedParentInPorts.contains(sourceNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same input " + sourceNe.getQualifiedName() + ".");
}
usedParentInPorts.add(sourceNe.getName());
}
}
{
NamedElement destNe = conn.getDestination().getConnectionEnd();
if (subCtPlusAllExtended.contains(destNe.getContainingClassifier())) {
if (usedChildInPorts.contains(destNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same input " + destNe.getQualifiedName() + ".");
}
usedChildInPorts.add(destNe.getName());
}
if (ctPlusAllExtended.contains(destNe.getContainingClassifier())) {
if (usedParentOutPorts.contains(destNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same output " + destNe.getQualifiedName() + ".");
}
usedParentOutPorts.add(destNe.getName());
}
}
}
for (Feature feat : comp.getAllFeatures()) {
boolean isIn = false;
if (feat instanceof DataPort) {
isIn = ((DataPort) feat).isIn();
} else if (feat instanceof EventDataPort) {
isIn = ((EventDataPort) feat).isIn();
} else if (feat instanceof EventPort) {
isIn = ((EventPort) feat).isIn();
}
if (isIn) {
if (!usedParentInPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection from input " + feat.getQualifiedName() + ".");
}
} else {
if (!usedParentOutPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection to output " + feat.getQualifiedName() + ".");
}
}
}
for (Feature feat : subCt.getAllFeatures()) {
boolean isIn = false;
if (feat instanceof DataPort) {
isIn = ((DataPort) feat).isIn();
} else if (feat instanceof EventDataPort) {
isIn = ((EventDataPort) feat).isIn();
} else if (feat instanceof EventPort) {
isIn = ((EventPort) feat).isIn();
}
if (isIn) {
if (!usedChildInPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection into " + feat.getQualifiedName() + ".");
}
} else {
if (!usedChildOutPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection out of " + feat.getQualifiedName() + ".");
}
}
}
}
} else {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout exactly one subcomponent.");
}
} else {
error(lcst, "'lift contract;' statement is not allowed in component interface.");
}
}
use of org.geotoolkit.sml.xml.v100.Connection in project spring-cloud-square by spring-projects-experimental.
the class TracingOkHttpInterceptor method parseRouteAddress.
private static void parseRouteAddress(Chain chain, Span span) {
if (span.isNoop()) {
return;
}
Connection connection = chain.connection();
if (connection == null) {
return;
}
InetSocketAddress socketAddress = connection.route().socketAddress();
span.remoteIpAndPort(socketAddress.getHostString(), socketAddress.getPort());
}
Aggregations