use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.
the class ClientBase method initializeTask.
/**
* Initializes a FutureTask for polling for the signature via StatusRequests.
*
* This is used by {@link #call(MssRequest, ResponseHandler)}.
*
* @param req The request object to send
* @param sigResp A response to the original signature request
* @param handler A response handler for receiving asynch responses.
* @return A FutureTask wrapping the StatusRequest poll logic
*
* @throws IOException if an HTTP communication error occurs or if the service returns a SOAP Fault
*/
protected FutureTask<Resp> initializeTask(final Req req, final MSSSignatureResp sigResp, final ResponseHandler<Req, Resp> handler) throws IOException {
Callable<Resp> callable = new Callable<Resp>() {
@Override
public Resp call() throws Exception {
long timeout = ClientBase.this.timeout;
long now = System.currentTimeMillis();
// Note that the transaction generally times out at the server at 180 s
long deadline = now + timeout;
Resp resp = null;
ProgressUpdate update = new ProgressUpdate(timeout, now);
MSSStatusResp statResp = null;
long waitPeriod = ClientBase.this.initialWait;
while (true) {
// Sleep for the rest of the interval
long timeToWait = waitPeriod - (System.currentTimeMillis() - now);
if (timeToWait > 0)
Thread.sleep(timeToWait);
now = System.currentTimeMillis();
waitPeriod = ClientBase.this.subsequentWait;
if (now > deadline) {
log.trace("Timed out");
handler.onError(req, new MssException("Timed out"));
break;
}
MSSStatusReq statReq = null;
try {
statReq = ClientBase.this.mssClient.createStatusRequest(sigResp, req.sigReq.getAPInfo().getAPTransID());
} catch (Throwable t) {
log.trace("Failed creating status request", t);
handler.onError(req, t);
break;
}
try {
log.trace("Sending statReq");
statResp = ClientBase.this.mssClient.send(statReq);
log.trace("Got statResp");
resp = ClientBase.this.createResp(req.sigReq, sigResp, statResp);
boolean done = isDone(resp);
boolean batchSignDone = resp.isBatchSignatureComplete();
long statusCode = parseStatus(statResp.getStatus());
if (StatusCodes.OUTSTANDING_TRANSACTION.equals(statusCode) || !batchSignDone) {
log.trace("Got an outstanding Status Response. Continuing to wait for a final answer.");
handler.onOutstandingProgress(req, update);
continue;
} else if (done) {
log.info("Got a final Status Response. Ending the wait.");
handler.onResponse(req, resp);
break;
} else {
log.warn("Got an abnormal Status Response. (" + statusCode + ") Ending the wait.");
MssException fe = new MssException("Abnormal status code " + statusCode);
handler.onError(req, fe);
break;
}
} catch (AxisFault af) {
log.trace("Got SOAP fault", af);
handler.onError(req, af);
break;
} catch (IOException ioe) {
log.trace("Got IOException", ioe);
throw ioe;
}
}
return resp;
}
};
return new FutureTask<Resp>(callable);
}
use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.
the class ClientBase method call.
/**
* Sends a request and waits for the response.
* Polls the server with status requests while waiting.
*
* <p>Response and exceptions are mainly delivered to the given response handler.
* May also throw SOAP faults also as IOException, which is why using
* {@link #send(MssRequest, ResponseHandler) or #callSynch(MssRequest)} instead is preferred.
*
* <p>Usage example:
* <pre>
* try {
* Req req = client.call(req, new ResponseHandler<Req, Resp>() {
* @Override
* public void onError(Req req, Throwable throwable) {
* // Handle error
* }
* @Override
* public void onResponse(Req req, Resp resp) {
* // Handle response
* }
* @Override
* public void onOutstandingProgress(Req req, ProgressUpdate prgUpdate) {
* // Handle outstanding request
* }
* });
* } catch (IOException e) {
* // Handle error
* }
* </pre>
*
* @param req The request object to send
* @param handler A response handler for receiving asynch responses.
*
* @return The request object being sent. This can be used to cancel the polling.
*
* @throws IllegalArgumentException if handler is null
* @throws IOException if an IOException was caught when sending the request.
* @deprecated Use {@link #send(MssRequest, ResponseHandler) or #callSynch(MssRequest)} instead
*/
@Deprecated
public Req call(final Req req, final ResponseHandler<Req, Resp> handler) throws IOException {
if (handler == null) {
throw new IllegalArgumentException("Null response handler not allowed.");
}
LavercaContext _context = new LavercaContext();
MSSSignatureResp _sigResp = null;
try {
log.debug("Sending sigReq");
_sigResp = this.mssClient.send(req.sigReq, _context);
log.debug("Got resp");
req.sigResp = _sigResp;
req.context = _context;
} catch (AxisFault af) {
log.error("Got SOAP fault", af);
handler.onError(req, af);
return req;
} catch (IOException ioe) {
log.error("Got IOException ", ioe);
throw ioe;
}
// Init the task and add it to the Req object
req.ft = this.initializeTask(req, _sigResp, handler);
log.debug("Starting calling");
this.threadExecutor.execute(req.ft);
return req;
}
use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.
the class ClientBase method send.
/**
* Sends a request without waiting for a response. {@link ResponseHandler} is used to deliver the response and possible errors.
*
* <p>Usage example:
* <pre>
* Req req = client.send(req, ResponseHandler<Req, Resp>() {
* @Override
* public void onError(Req req, Throwable throwable) {
* // Handle error
* }
* @Override
* public void onResponse(Req req, Resp resp) {
* // Handle response
* }
* @Override
* public void onOutstandingProgress(Req req, ProgressUpdate prgUpdate) {
* // Handle outstanding request
* }
* });
* </pre>
*
* @param req The request object to send
* @param handler A response handler for receiving asynch responses.
*
* @return The request object being sent. This can be used to cancel the polling.
*/
public Req send(final Req req, final ResponseHandler<Req, Resp> handler) {
if (handler == null) {
throw new IllegalArgumentException("Null response handler not allowed.");
}
LavercaContext _context = new LavercaContext();
MSSSignatureResp _sigResp = null;
try {
log.debug("Sending sigReq");
_sigResp = this.mssClient.send(req.sigReq, _context);
log.debug("Got resp");
req.sigResp = _sigResp;
req.context = _context;
// Init the task and add it to the Req object
req.ft = this.initializeTask(req, _sigResp, handler);
} catch (IOException ioe) {
handler.onError(req, ioe);
return req;
}
log.debug("Starting calling");
this.threadExecutor.execute(req.ft);
return req;
}
use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.
the class ClientBase method send.
/**
* Sends a request and waits for the response.
*
* <p>Usage example:
* <pre>
* try {
* Response resp = client.send(req);
* // Handle response
* } catch (IOException ioe) {
* // Handle error
* }
* </pre>
*
* @param req The request object to send
* @return The request object being sent. This can be used to cancel the polling.
*
* @throws IOException if an HTTP communication error occurs or if the service returns a SOAP Fault
*/
public Resp send(final Req req) throws IOException {
LavercaContext _context = new LavercaContext();
MSSSignatureResp _sigResp = null;
log.debug("Sending sigReq");
_sigResp = this.mssClient.send(req.sigReq, _context);
log.debug("Got resp");
if (req.isSynchronous()) {
return this.createResp(req.sigReq, _sigResp, null);
} else {
req.sigResp = _sigResp;
req.context = _context;
// Init the task and add it to the Req object
try {
req.ft = this.initializeTask(req, _sigResp, new SynchHandler<Req, Resp>());
} catch (SynchHandlerException e) {
if (e.getCause() instanceof IOException)
throw e;
else
throw new IOException(e.getCause());
}
log.debug("Starting calling");
this.threadExecutor.execute(req.ft);
try {
return req.waitForResponse();
} catch (InterruptedException | ExecutionException e) {
throw new IOException(e);
}
}
}
use of fi.laverca.jaxb.mss.MSSSignatureResp in project laverca by laverca.
the class MSS_SignatureBindingStub method MSS_Signature.
@Override
public MSSSignatureResp MSS_Signature(MSSSignatureReq req) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
Call _call1 = this.createCall(SOAPConstants.SOAP12_CONSTANTS, null, _operations[0]);
_call1.setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call1.setProperty(AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call1.setSOAPActionURI("#MSS_Signature");
this.setRequestHeaders(_call1);
Object _resp = _call1.invoke(new Object[] { req });
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException) _resp;
} else {
return (MSSSignatureResp) _resp;
}
}
Aggregations