public void reset( IOperationContext context, String statements, String statementsFormat, java.util.Collection<org.openanzo.rdf.Statement> checks, java.io.Writer output) throws AnzoException { if (!combusConnection.isConnected()) { throw new AnzoException(ExceptionConstants.CLIENT.CLIENT_NOT_CONNECTED); // combusConnection.connect(); } long start = 0; if (stats.isEnabled()) { start = System.currentTimeMillis(); } try { TextMessage request = combusConnection.createMessage(); org.openanzo.combus.JMSMessageWrapper messageWrapper = new org.openanzo.combus.JMSMessageWrapper(request); messageWrapper.setProperty(SerializationConstants.operation, RESET); if (context.getAttribute(SerializationConstants.userDescription) != null) { messageWrapper.setProperty( SerializationConstants.userDescription, context.getAttribute(SerializationConstants.userDescription, String.class)); } messageWrapper.setProperty(PARAM_STATEMENTSFormat, statementsFormat); messageWrapper.setBody(statements); messageWrapper.setProperty( PARAM_CHECKSFormat, org.openrdf.rio.RDFFormat.TRIG.getDefaultMIMEType()); if (checks != null) org.openanzo.services.serialization.transport.StatementsSerializer.serialize( checks, PARAM_CHECKS, org.openrdf.rio.RDFFormat.TRIG.getDefaultMIMEType(), messageWrapper); TextMessage response = combusConnection.requestResponse( context, org.openanzo.datasource.IResetService.SERVICE_NAME, request, getTimeout()); try { if (response != null && response.getText() != null) { output.write(response.getText()); output.flush(); } } catch (IOException ioe) { throw new AnzoException(ExceptionConstants.IO.WRITE_ERROR, ioe); } catch (JMSException jmsex) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER, jmsex); } } finally { if (stats.isEnabled()) { stats.use("reset", (System.currentTimeMillis() - start)); } } }
public void reset( IOperationContext context, java.util.Collection<org.openanzo.rdf.Statement> statements, java.util.Collection<org.openanzo.rdf.Statement> checks) throws AnzoException { java.io.StringWriter responseWriter = new java.io.StringWriter(); String _requestBody = null; if (statements != null) { _requestBody = org.openanzo.services.serialization.transport.StatementsSerializer.serialize( statements, org.openrdf.rio.RDFFormat.TRIG.getDefaultMIMEType()); } String statementsFormat = org.openrdf.rio.RDFFormat.TRIG.getDefaultMIMEType(); reset(context, _requestBody, statementsFormat, checks, responseWriter); }
public void publishNanopub(Nanopub nanopub) throws IOException { if (serverInfo == null) { if (serverUrls == null || serverUrls.isEmpty()) { serverIterator = new ServerIterator(); } else { serverIterator = new ServerIterator(serverUrls); } serverInfo = serverIterator.next(); } artifactCode = TrustyUriUtils.getArtifactCode(nanopub.getUri().toString()); if (verbose) { System.out.println("---"); System.out.println("Trying to publish nanopub: " + artifactCode); } while (serverInfo != null) { String serverUrl = serverInfo.getPublicUrl(); try { if (!ServerInfo.load(serverUrl).isPostNanopubsEnabled()) { serverInfo = serverIterator.next(); continue; } } catch (ServerInfoException ex) { serverInfo = serverIterator.next(); continue; } if (verbose) { System.out.println("Trying server: " + serverUrl); } try { HttpPost post = new HttpPost(serverUrl); String nanopubString = NanopubUtils.writeToString(nanopub, RDFFormat.TRIG); post.setEntity(new StringEntity(nanopubString, "UTF-8")); post.setHeader("Content-Type", RDFFormat.TRIG.getDefaultMIMEType()); HttpResponse response = HttpClientBuilder.create().build().execute(post); int code = response.getStatusLine().getStatusCode(); if (code >= 200 && code < 300) { if (usedServers.containsKey(serverUrl)) { usedServers.put(serverUrl, usedServers.get(serverUrl) + 1); } else { usedServers.put(serverUrl, 1); } if (verbose) { System.out.println("Published: " + artifactCode); } return; } else { if (verbose) { System.out.println( "Response: " + code + " " + response.getStatusLine().getReasonPhrase()); } } } catch (IOException ex) { if (verbose) { System.out.println(ex.getClass().getName() + ": " + ex.getMessage()); } } catch (OpenRDFException ex) { if (verbose) { System.out.println(ex.getClass().getName() + ": " + ex.getMessage()); } } serverInfo = serverIterator.next(); } serverInfo = null; throw new IOException("Failed to publish the nanopub"); }