List of usage examples for java.net URI toASCIIString
public String toASCIIString()
From source file:org.eclipse.jetty.demo.Main.java
/** * Setup the basic application "context" for this application at "/" * This is also known as the handler tree (in jetty speak) *///from w ww . ja v a 2 s. c om private WebAppContext getWebAppContext(URI baseUri, File scratchDir) { WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setAttribute("javax.servlet.context.tempdir", scratchDir); context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$"); System.out.println(baseUri.toASCIIString()); context.setResourceBase(baseUri.toASCIIString()); context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers()); context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager()); context.addBean(new ServletContainerInitializersStarter(context), true); context.setClassLoader(getUrlClassLoader()); context.addServlet(jspServletHolder(), "*.jsp"); // Add Application Servlets context.addServlet(DateServlet.class, "/date/"); context.addServlet(exampleJspFileMappedServletHolder(), "/test/foo/"); context.addServlet(defaultServletHolder(baseUri), "/"); return context; }
From source file:jails.http.HttpHeaders.java
/** * Set the (new) location of a resource, as specified by the {@code Location} header. * @param location the location// w w w . ja v a 2 s . c o m */ public void setLocation(URI location) { set(LOCATION, location.toASCIIString()); }
From source file:com.splout.db.common.SploutClient.java
public QueryStatus query(String tablespace, String key, String query, String partition) throws IOException { URI uri; try {/* ww w. j a va 2 s . c o m*/ uri = new URI("http", qNodesNoProtocol[(int) (Math.random() * qNodes.length)], "/api/query/" + tablespace, "&sql=" + query + (key != null ? "&key=" + key : "") + (partition != null ? "&partition=" + partition : ""), null); HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri.toASCIIString())); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch (JSONSerDeException e) { throw new IOException(e); } } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer.java
protected ResWrap<ServiceDocument> doDeserialize(final JsonParser parser) throws IOException { final ObjectNode tree = parser.getCodec().readTree(parser); ServiceDocumentImpl serviceDocument = new ServiceDocumentImpl(); final String metadataETag; if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) { metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue(); tree.remove(Constants.JSON_METADATA_ETAG); } else {//from www. j a va 2 s. co m metadataETag = null; } final URI contextURL; if (tree.hasNonNull(Constants.JSON_CONTEXT)) { contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue()); tree.remove(Constants.JSON_CONTEXT); } else if (tree.hasNonNull(Constants.JSON_METADATA)) { contextURL = URI.create(tree.get(Constants.JSON_METADATA).textValue()); tree.remove(Constants.JSON_METADATA); } else { contextURL = null; } serviceDocument.setMetadata(contextURL == null ? null : contextURL.toASCIIString()); for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).elements(); itor.hasNext();) { final JsonNode node = itor.next(); final ServiceDocumentItemImpl item = new ServiceDocumentItemImpl(); item.setName(node.get("name").asText()); JsonNode titleNode = node.get("title"); if (titleNode != null) { item.setTitle(titleNode.asText()); } item.setUrl(node.get("url").asText()); final String kind = node.has("kind") ? node.get("kind").asText() : null; if (StringUtils.isBlank(kind) || "EntitySet".equals(kind)) { serviceDocument.getEntitySets().add(item); } else if ("Singleton".equals(kind)) { serviceDocument.getSingletons().add(item); } else if ("FunctionImport".equals(kind)) { serviceDocument.getFunctionImports().add(item); } else if ("ServiceDocument".equals(kind)) { serviceDocument.getRelatedServiceDocuments().add(item); } } return new ResWrap<ServiceDocument>(contextURL, metadataETag, serviceDocument); }
From source file:com.almende.eve.transport.xmpp.XmppTransport.java
@Override public void send(final URI receiverUri, final String message, final String tag) throws IOException { // Check and deliver local shortcut. if (sendLocal(receiverUri, message)) { return;/*ww w .j a v a 2s . c o m*/ } if (!isConnected()) { connect(); } if (isConnected()) { // send the message final Message msg = new Message(); msg.setTo(receiverUri.toASCIIString().replace("xmpp:", "")); msg.setBody(message); conn.sendPacket(msg); } else { throw new IOException("Cannot send request, not connected"); } }
From source file:mecard.security.PAPISecurity.java
/** * /*w w w . ja v a 2 s .c o m*/ * @param HTTPMethod POST, or GET * @param uri the authentication URI, like 'http://localhost/PAPIService/REST/public/v1/1033/100/1/patron/21756003332022' * @param patronPassword This, in the case of public methods (of which PatronRegistrationCreate and PatronUpdate both are) * is the staff authentication secret that is hashed with the URL to authenticate the desired transaction. See page 9 * Polaris Application Programming Interface (PAPI) Reference Guide, Polaris 4.1, PAPI version 1, Document revision 8. * @return the signature used on the end of the Authorization HTTP header. */ public String getSignature(String HTTPMethod, URI uri, String patronPassword) { // Authorization - PWS [PAPIAccessKeyID]:[Signature] // PWS must be in caps // No space before or after : // [PAPIAccessKeyID] - Assigned by Polaris // [Signature] - The signature is the following, encoded with SHA1 UTF-8: // [HTTPMethod][URI][Date][PatronPassword] String signature = this.getPAPIHash(this.PAPISecret, // From the properties file. HTTPMethod, uri.toASCIIString(), this.getPolarisDate(), patronPassword // Optional, may be empty. ); return signature; }
From source file:org.apache.taverna.scufl2.wfdesc.WfdescSerialiser.java
protected OntModel save(final WorkflowBundle bundle) { final OntModel model = ModelFactory.createOntologyModel(); bundle.accept(new VisitorWithPath() { Scufl2Tools scufl2Tools = new Scufl2Tools(); public boolean visit() { WorkflowBean node = getCurrentNode(); // System.out.println(node); if (node instanceof WorkflowBundle) { return true; }// w w w . j ava 2 s . c om // @SuppressWarnings("rawtypes") if (node instanceof org.apache.taverna.scufl2.api.core.Workflow) { entityForBean(node, Wfdesc.Workflow); } else if (node instanceof Processor) { Processor processor = (Processor) node; Individual process = entityForBean(processor, Wfdesc.Process); Individual wf = entityForBean(processor.getParent(), Wfdesc.Workflow); wf.addProperty(Wfdesc.hasSubProcess, process); } else if (node instanceof InputPort) { WorkflowBean parent = ((Child) node).getParent(); Individual input = entityForBean(node, Wfdesc.Input); Individual process = entityForBean(parent, Wfdesc.Process); process.addProperty(Wfdesc.hasInput, input); } else if (node instanceof OutputPort) { WorkflowBean parent = ((Child) node).getParent(); Individual output = entityForBean(node, Wfdesc.Output); Individual process = entityForBean(parent, Wfdesc.Process); process.addProperty(Wfdesc.hasOutput, output); } else if (node instanceof DataLink) { WorkflowBean parent = ((Child) node).getParent(); DataLink link = (DataLink) node; Individual dl = entityForBean(link, Wfdesc.DataLink); Individual source = entityForBean(link.getReceivesFrom(), Wfdesc.Output); dl.addProperty(Wfdesc.hasSource, source); Individual sink = entityForBean(link.getSendsTo(), Wfdesc.Input); dl.addProperty(Wfdesc.hasSink, sink); Individual wf = entityForBean(parent, Wfdesc.Workflow); wf.addProperty(Wfdesc.hasDataLink, dl); } else if (node instanceof Profile) { // So that we can get at the ProcessorBinding - buy only if // it is the main Profile return node == bundle.getMainProfile(); } else if (node instanceof ProcessorBinding) { ProcessorBinding b = (ProcessorBinding) node; Activity a = b.getBoundActivity(); Processor boundProcessor = b.getBoundProcessor(); Individual process = entityForBean(boundProcessor, Wfdesc.Process); // Note: We don't describe the activity and processor // binding in wfdesc. Instead we // assign additional types and attributes to the parent // processor try { URI type = a.getType(); Configuration c = scufl2Tools.configurationFor(a, b.getParent()); JsonNode json = c.getJson(); if (type.equals(BEANSHELL)) { process.addRDFType(Wf4ever.BeanshellScript); String s = json.get("script").asText(); process.addProperty(Wf4ever.script, s); JsonNode localDep = json.get("localDependency"); if (localDep != null && localDep.isArray()) { for (int i = 0; i < localDep.size(); i++) { String depStr = localDep.get(i).asText(); // FIXME: Better class for dependency? Individual dep = model.createIndividual(OWL.Thing); dep.addLabel(depStr, null); dep.addComment("JAR dependency", "en"); process.addProperty(Roterms.requiresSoftware, dep); // Somehow this gets the whole thing to fall // out of the graph! // QName depQ = new // QName("http://google.com/", ""+ // UUID.randomUUID()); // sesameManager.rename(dep, depQ); } } } if (type.equals(RSHELL)) { process.addRDFType(Wf4ever.RScript); String s = json.get("script").asText(); process.addProperty(Wf4ever.script, s); } if (type.equals(WSDL)) { process.addRDFType(Wf4ever.SOAPService); JsonNode operation = json.get("operation"); URI wsdl = URI.create(operation.get("wsdl").asText()); process.addProperty(Wf4ever.wsdlURI, wsdl.toASCIIString()); process.addProperty(Wf4ever.wsdlOperationName, operation.get("name").asText()); process.addProperty(Wf4ever.rootURI, wsdl.resolve("/").toASCIIString()); } if (type.equals(REST)) { process.addRDFType(Wf4ever.RESTService); // System.out.println(json); JsonNode request = json.get("request"); String absoluteURITemplate = request.get("absoluteURITemplate").asText(); String uriTemplate = absoluteURITemplate.replace("{", ""); uriTemplate = uriTemplate.replace("}", ""); // TODO: Detect {} try { URI root = new URI(uriTemplate).resolve("/"); process.addProperty(Wf4ever.rootURI, root.toASCIIString()); } catch (URISyntaxException e) { logger.warning("Potentially invalid URI template: " + absoluteURITemplate); // Uncomment to temporarily break // TestInvalidURITemplate: // rest.getWfRootURI().add(URI.create("http://example.com/FRED")); } } if (type.equals(TOOL)) { process.addRDFType(Wf4ever.CommandLineTool); JsonNode desc = json.get("toolDescription"); // System.out.println(json); JsonNode command = desc.get("command"); if (command != null) { process.addProperty(Wf4ever.command, command.asText()); } } if (type.equals(NESTED_WORKFLOW)) { Workflow nestedWf = scufl2Tools.nestedWorkflowForProcessor(boundProcessor, b.getParent()); // The parent process is a specialization of the // nested workflow // (because the nested workflow could exist as // several processors) specializationOf(boundProcessor, nestedWf); process.addRDFType(Wfdesc.Workflow); // Just like the Processor specializes the nested // workflow, the // ProcessorPorts specialize the WorkflowPort for (ProcessorPortBinding portBinding : b.getInputPortBindings()) { // Map from activity port (not in wfdesc) to // WorkflowPort WorkflowPort wfPort = nestedWf.getInputPorts() .getByName(portBinding.getBoundActivityPort().getName()); if (wfPort == null) { continue; } specializationOf(portBinding.getBoundProcessorPort(), wfPort); } for (ProcessorPortBinding portBinding : b.getOutputPortBindings()) { WorkflowPort wfPort = nestedWf.getOutputPorts() .getByName(portBinding.getBoundActivityPort().getName()); if (wfPort == null) { continue; } specializationOf(portBinding.getBoundProcessorPort(), wfPort); } } } catch (IndexOutOfBoundsException ex) { } return false; } else { // System.out.println("--NO!"); return false; } for (Annotation ann : scufl2Tools.annotationsFor(node, bundle)) { String annotationBody = ann.getBody().toASCIIString(); String baseURI = bundle.getGlobalBaseURI().resolve(ann.getBody()).toASCIIString(); InputStream annotationStream; try { annotationStream = bundle.getResources().getResourceAsInputStream(annotationBody); try { // FIXME: Don't just assume Lang.TURTLE RDFDataMgr.read(model, annotationStream, baseURI, Lang.TURTLE); } catch (RiotException e) { logger.log(Level.WARNING, "Can't parse RDF Turtle from " + annotationBody, e); } finally { annotationStream.close(); } } catch (IOException e) { logger.log(Level.WARNING, "Can't read " + annotationBody, e); } } if (node instanceof Named) { Named named = (Named) node; entityForBean(node, OWL.Thing).addLabel(named.getName(), null); } return true; } private void specializationOf(WorkflowBean special, WorkflowBean general) { Individual specialEnt = entityForBean(special, Prov_o.Entity); Individual generalEnt = entityForBean(general, Prov_o.Entity); specialEnt.addProperty(Prov_o.specializationOf, generalEnt); } private Individual entityForBean(WorkflowBean bean, Resource thing) { return model.createIndividual(uriForBean(bean), thing); } // @Override // public boolean visitEnter(WorkflowBean node) { // if (node instanceof Processor // || node instanceof org.apache.taverna.scufl2.api.core.Workflow // || node instanceof Port || node instanceof DataLink) { // visit(node); // return true; // } // // The other node types (e.g. dispatch stack, configuration) are // // not (directly) represented in wfdesc //// System.out.println("Skipping " + node); // return false; // }; }); return model; }
From source file:org.apache.olingo.client.core.op.AbstractODataBinder.java
@Override public Entry getEntry(final ODataEntity entity, final Class<? extends Entry> reference, final boolean setType) { final Entry entry = ResourceFactory.newEntry(reference); entry.setType(entity.getName());//from ww w . j a v a 2 s . c om // ------------------------------------------------------------- // Add edit and self link // ------------------------------------------------------------- final URI editLink = entity.getEditLink(); if (editLink != null) { final LinkImpl entryEditLink = new LinkImpl(); entryEditLink.setTitle(entity.getName()); entryEditLink.setHref(editLink.toASCIIString()); entryEditLink.setRel(Constants.EDIT_LINK_REL); entry.setEditLink(entryEditLink); } if (entity.isReadOnly()) { final LinkImpl entrySelfLink = new LinkImpl(); entrySelfLink.setTitle(entity.getName()); entrySelfLink.setHref(entity.getLink().toASCIIString()); entrySelfLink.setRel(Constants.SELF_LINK_REL); entry.setSelfLink(entrySelfLink); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append navigation links (handling inline entry / feed as well) // ------------------------------------------------------------- // handle navigation links for (ODataLink link : entity.getNavigationLinks()) { // append link LOG.debug("Append navigation link\n{}", link); entry.getNavigationLinks() .add(getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append edit-media links // ------------------------------------------------------------- for (ODataLink link : entity.getEditMediaLinks()) { LOG.debug("Append edit-media link\n{}", link); entry.getMediaEditLinks() .add(getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append association links // ------------------------------------------------------------- for (ODataLink link : entity.getAssociationLinks()) { LOG.debug("Append association link\n{}", link); entry.getAssociationLinks() .add(getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- if (entity.isMediaEntity()) { entry.setMediaContentSource(entity.getMediaContentSource()); entry.setMediaContentType(entity.getMediaContentType()); } for (ODataProperty property : entity.getProperties()) { entry.getProperties().add(getProperty(property, reference, setType)); } return entry; }
From source file:org.jclouds.mezeo.pcs2.PCSClientLiveTest.java
private FileInfoWithMetadata validateFileInfoAndNameIsInMetadata(URI container, URI objectURI, String name, Long size) throws InterruptedException, ExecutionException, TimeoutException { FileInfoWithMetadata response;//from w w w. j ava2s .com connection.putMetadataItem(objectURI, "name", name); response = connection.getFileInfo(objectURI); validateFileInfo(response, container, name, size, "text/plain"); assertEquals(response.getMetadataItems().get("name"), URI.create(objectURI.toASCIIString() + "/metadata/name")); validateMetadataItemNameEquals(objectURI, name); return response; }
From source file:eu.uqasar.service.dataadapter.CubesDataService.java
public List<Measurement> cubesAdapterQuery(String bindedSystem, String cubeName, String queryExpression) throws uQasarException { URI uri = null; LinkedList<Measurement> measurements = new LinkedList<>(); try {/*from w w w. j a v a 2 s.c o m*/ uri = new URI(bindedSystem + "/" + queryExpression); String url = uri.toASCIIString(); JSONResource res = getJSON(url); us.monoid.json.JSONObject json = res.toObject(); logger.info(json.toString()); JSONArray measurementResultJSONArray = new JSONArray(); JSONObject bp = new JSONObject(); bp.put("self", url); bp.put("key", cubeName); bp.put("name", queryExpression); measurementResultJSONArray.put(bp); logger.info(measurementResultJSONArray.toString()); measurements.add(new Measurement(uQasarMetric.PROJECTS_PER_SYSTEM_INSTANCE, measurementResultJSONArray.toString())); } catch (URISyntaxException | org.apache.wicket.ajax.json.JSONException | JSONException | IOException e) { e.printStackTrace(); } return measurements; }