use of java.net.SocketTimeoutException in project SmartCity-Market by TechnionYP5777.
the class Customer method viewCatalogProduct.
@Override
public CatalogProduct viewCatalogProduct(SmartCode c) throws CriticalError, CustomerNotConnected, ProductCatalogDoesNotExist {
String serverResponse;
log.info("Creating viewProductFromCatalog (in order to addPtoductToCart) command wrapper to customer with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
/* first: getting the product from the server */
try {
serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(c)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
CommandWrapper $ = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler($.getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | CriticalError | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("viewProductFromCatalog command succeed.");
return Serialization.deserialize($.getData(), CatalogProduct.class);
}
use of java.net.SocketTimeoutException in project SmartCity-Market by TechnionYP5777.
the class Customer method logout.
@Override
public void logout() throws CustomerNotConnected, CriticalError {
String serverResponse;
log.info("Creating customer logout command wrapper with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(id, CommandDescriptor.LOGOUT)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
resultDescriptorHandler(getCommandWrapper(serverResponse).getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | ProductCatalogDoesNotExist | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
customerProfile = null;
log.info("logout from server succeed.");
}
use of java.net.SocketTimeoutException in project spatial-portal by AtlasOfLivingAustralia.
the class ProgressController method get.
JSONObject get() {
try {
StringBuilder sbProcessUrl = new StringBuilder();
sbProcessUrl.append(CommonData.getSatServer()).append("/ws/job?pid=").append(pid);
LOGGER.debug("checking status every '" + timer.getDelay() + "' sec: " + sbProcessUrl.toString());
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(sbProcessUrl.toString());
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.getHttpConnectionManager().getParams().setSoTimeout(timer.getDelay());
int result = client.executeMethod(get);
if (result == 200) {
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(get.getResponseBodyAsString());
}
} catch (SocketTimeoutException e) {
LOGGER.debug("progress timeout exception, will be trying again.");
} catch (Exception e) {
LOGGER.error("error getting updated job info pid=" + pid, e);
}
return null;
}
use of java.net.SocketTimeoutException in project GNS by MobilityFirst.
the class Pinger method checkConnection.
/**
*
* @param host
* @param port
* @param timeoutMs
* @return the time to connect or NOCONNECTION
*/
public static long checkConnection(String host, int port, int timeoutMs) {
//default check value
long start = NOCONNECTION;
//default check value
long end = NOCONNECTION;
// default for bad connection
long total = NOCONNECTION;
//make an unbound socket
Socket theSock = new Socket();
try {
InetAddress address = InetAddress.getByName(host);
SocketAddress sockaddr = new InetSocketAddress(address, port);
// Create the socket with a timeout
// when a timeout occurs, we will get timout exp.
// also time our connection this gets very close to the real time
start = System.currentTimeMillis();
theSock.connect(sockaddr, timeoutMs);
end = System.currentTimeMillis();
} catch (UnknownHostException e) {
start = NOCONNECTION;
end = NOCONNECTION;
} catch (SocketTimeoutException e) {
start = NOCONNECTION;
end = NOCONNECTION;
} catch (IOException e) {
start = NOCONNECTION;
end = NOCONNECTION;
} finally {
if (theSock != null) {
try {
theSock.close();
} catch (IOException e) {
}
}
if ((start != NOCONNECTION) && (end != NOCONNECTION)) {
total = end - start;
}
}
//returns NOCONNECTION if timeout
return total;
}
use of java.net.SocketTimeoutException in project jdk8u_jdk by JetBrains.
the class JdpTestCase method run.
public void run() throws Exception {
log.fine("Test started.");
log.fine("Listening for multicast packets at " + connection.address.getHostAddress() + ":" + String.valueOf(connection.port));
log.fine(initialLogMessage());
log.fine("Pause in between packets is: " + connection.pauseInSeconds + " seconds.");
startTime = System.currentTimeMillis();
timeOut = connection.pauseInSeconds * TIME_OUT_FACTOR;
log.fine("Timeout set to " + String.valueOf(timeOut) + " seconds.");
MulticastSocket socket = connection.connectWithTimeout(timeOut * 1000);
byte[] buffer = new byte[BUFFER_LENGTH];
DatagramPacket datagram = new DatagramPacket(buffer, buffer.length);
do {
try {
socket.receive(datagram);
onReceived(extractUDPpayload(datagram));
} catch (SocketTimeoutException e) {
onSocketTimeOut(e);
}
if (hasTestLivedLongEnough()) {
shutdown();
}
} while (shouldContinue());
log.fine("Test ended successfully.");
}
Aggregations