本文整理汇总了Java中eu.fusepool.p3.transformer.HttpRequestEntity类的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestEntity类的具体用法?Java HttpRequestEntity怎么用?Java HttpRequestEntity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestEntity类属于eu.fusepool.p3.transformer包,在下文中一共展示了HttpRequestEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
public void transform(HttpRequestEntity entity, String requestId)
throws IOException {
logMessage(entity.getRequest());
if (!fActive.add(requestId)) {
throw new IllegalStateException("A request with ID " + requestId + " was already in progress.");
}
File output = output(requestId);
ImmutablePair<MimeType, Properties> pair = exporterOptions(entity);
fEngine.transform(
downloadInput(entity).toURI(),
fetchTransform(entity),
output.toURI(),
pair.getRight(),
new CallbackWrapper(requestId, output, pair.getLeft())
);
}
示例2: transform
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
public Entity transform(HttpRequestEntity entity) throws IOException {
final MimeType mimeType = entity.getType();
final InputStream in = entity.getData();
final Entity output = new WritingEntity() {
@Override
public MimeType getType() {
return mimeType;
}
@Override
public void writeData(OutputStream out) throws IOException {
IOUtils.copy(in, out);
}
};
return output;
}
示例3: generateRdf
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
/**
* Get SIOC content from the RDF as text and return it.
*
* @param entity
* @return
* @throws IOException
*/
@Override
protected TripleCollection generateRdf(HttpRequestEntity entity) throws IOException {
String text = "";
Graph graph = Parser.getInstance().parse(entity.getData(), "text/turtle");
Iterator<Triple> triples = graph.filter(null, SIOC.content, null);
if (triples.hasNext()) {
Literal literal = (Literal) triples.next().getObject();
text = literal.getLexicalForm();
}
final TripleCollection result = new SimpleMGraph();
final Resource resource = entity.getContentLocation() == null
? new BNode()
: new UriRef(entity.getContentLocation().toString());
final GraphNode node = new GraphNode(resource, result);
node.addProperty(RDF.type, TEXUAL_CONTENT);
node.addPropertyValue(SIOC.content, text);
node.addPropertyValue(new UriRef("http://example.org/ontology#textLength"), text.length());
return result;
}
示例4: getDocuementURI
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
/**
* Get docuemt URI either from content location header, or generate one if it's null.
*
* @param entity
* @return
*/
protected static String getDocuementURI(HttpRequestEntity entity) {
String documentURI;
if (entity.getContentLocation() == null) {
HttpServletRequest request = entity.getRequest();
String baseURL = getBaseURL(request);
String requestID = request.getHeader("X-Request-ID");
if (StringUtils.isNotEmpty(requestID)) {
documentURI = baseURL + requestID;
} else {
documentURI = baseURL + UUID.randomUUID().toString();
}
} else {
documentURI = entity.getContentLocation().toString();
}
return documentURI;
}
示例5: generateRdf
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
protected TripleCollection generateRdf(HttpRequestEntity entity) throws IOException {
String rdfDataFormat = SupportedFormat.TURTLE;
InputStream configIn = null;
String queryString = entity.getRequest().getQueryString();
log.info("Query string: " + queryString);
//String configUri = getRequestParamValue(queryString, "config");
String configUri = entity.getRequest().getParameter("config");
log.info("Config file URI: " + configUri);
if(configUri != null) {
configIn = getRemoteConfigFile(configUri);
}
final InputStream inputRdfData = entity.getData();
TripleCollection duplicates = findSameEntities(inputRdfData, rdfDataFormat, configIn);
return duplicates;
}
示例6: processRequest
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
public void processRequest(String requestId) {
HttpRequestEntity entity = fActive.get(requestId);
if (entity == null) {
fCallback.reportException(requestId,
new IllegalStateException("Request " + requestId + " is no longer active. " +
"Maybe there was an ID collision?"));
return;
}
try {
fCallback.responseAvailable(requestId, transform(entity));
} catch (Exception ex) {
fCallback.reportException(requestId, ex);
}
}
示例7: fetchTransform
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
protected JSONArray fetchTransform(HttpRequestEntity request)
throws IOException {
String transformURI = getSingleParameter(TRANSFORM_PARAMETER,
request.getRequest());
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
try {
HttpGet get = new HttpGet(transformURI);
get.addHeader("Accept", "application/json");
client = HttpClients.createDefault();
response = performRequest(get, client);
HttpEntity responseEntity = response.getEntity();
if (responseEntity == null) {
// TODO proper error reporting
throw new IOException("Could not GET transform JSON from "
+ transformURI + ".");
}
String encoding = null;
if (responseEntity.getContentType() != null) {
encoding = MimeTypes.getCharsetFromContentType(responseEntity.getContentType().getValue());
}
String transform = IOUtils.toString(responseEntity.getContent(),
encoding == null ? "UTF-8" : encoding);
return ParsingUtilities.evaluateJsonStringToArray(transform);
} finally {
IOUtils.closeQuietly(response);
IOUtils.closeQuietly(client);
}
}
示例8: containsRDFMapping
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
protected boolean containsRDFMapping(HttpRequestEntity request) throws IOException {
JSONArray transform = fetchTransform(request);
for (int i = 0; i < transform.length(); i++) {
JSONObject operation = transform.optJSONObject(i);
if (operation != null && operation.get("op") == "rdf-extension/save-rdf-schema")
return true;
}
return false;
}
示例9: transform
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
public Entity transform(HttpRequestEntity entity) throws IOException {
logMessage(entity.getRequest());
final HttpRequestEntity request = cast(entity);
final ImmutablePair<MimeType, Properties> options = exporterOptions(request);
options.right.putAll(transformerConfig);
final File input = downloadInput(entity);
final File output = File.createTempFile("reply", "tmp");
final ITransformEngine engine = getEngine();
return new WritingEntity() {
@Override
public void writeData(OutputStream out) throws IOException {
try {
// Can't allow more than one transform at a time as OpenRefine is not
// designed for that.
synchronized (SynchronousTransformer.this) {
engine.transform(input.toURI(), fetchTransform(request), output.toURI(),
options.right);
}
try (FileInputStream stream = new FileInputStream(output)) {
IOUtils.copy(stream, out);
}
} finally {
input.delete();
output.delete();
}
}
@Override
public MimeType getType() {
return options.left;
}
};
}
示例10: cast
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
private HttpRequestEntity cast(Entity entity) throws IOException {
// TODO have to discuss with Reto how to properly:
// 1 - handle/report error conditions (for now I just throw
// IOException);
// 2 - properly get the parameters from the enclosing HTTP request.
if (!(entity instanceof HttpRequestEntity)) {
throw new IOException("BatchRefineTransformer requires a "
+ HttpRequestEntity.class.getName());
}
return (HttpRequestEntity) entity;
}
示例11: transform
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
public Entity transform(HttpRequestEntity entity) throws IOException {
// get mimetype of content
final MimeType mimeType = entity.getType();
// convert content to byte array
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(entity.getData(), baos);
final byte[] bytes = baos.toByteArray();
// get content location header
final URI contentLocation = entity.getContentLocation();
// create Entity from content
final Entity input = new InputStreamEntity() {
@Override
public MimeType getType() {
return mimeType;
}
@Override
public InputStream getData() throws IOException {
return new ByteArrayInputStream(bytes);
}
@Override
public URI getContentLocation() {
return contentLocation;
}
};
// run pipeline
final Entity output = pipeline.run(input, accept);
return output;
}
示例12: generateRdf
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
protected TripleCollection generateRdf(HttpRequestEntity entity) throws IOException {
final String text = IOUtils.toString(entity.getData(), "UTF-8");
final TripleCollection result = new SimpleMGraph();
final Resource resource = entity.getContentLocation() == null
? new BNode()
: new UriRef(entity.getContentLocation().toString());
final GraphNode node = new GraphNode(resource, result);
node.addProperty(RDF.type, TEXUAL_CONTENT);
node.addPropertyValue(SIOC.content, text);
node.addPropertyValue(new UriRef("http://example.org/ontology#textLength"), text.length());
return result;
}
示例13: generateRdf
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
/**
* Takes the RDF data sent by the client and the graph name (url) of the knowledge base to search
* for points of interest nearby the locations described in the client graph and sends it back enriched with
* information about the points of interest that have been found. It looks for the knowledge base name in the triple store
* before fetching the data from the url.
*/
@Override
protected TripleCollection generateRdf(HttpRequestEntity entity) throws IOException {
TripleCollection resultGraph = null;
String mediaType = entity.getType().toString();
Parser parser = Parser.getInstance();
TripleCollection requestGraph = parser.parse( entity.getData(), mediaType);
resultGraph = spatialDataEnhancer.enhance(kbDataUrl, requestGraph);
return resultGraph;
}
示例14: transform
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
public void transform(HttpRequestEntity entity, String requestId) throws IOException {
if (!fQueue.offer(requestId)) {
throw new TooManyRequests("Too many requests on backlog.");
}
// This should generally not be a problem as we don't expect requestId
// collisions.
fActive.put(requestId, entity);
}
示例15: transform
import eu.fusepool.p3.transformer.HttpRequestEntity; //导入依赖的package包/类
@Override
public Entity transform(HttpRequestEntity entity) throws IOException {
InputStream inputData = entity.getData();
String sedSpec = checkedGet(entity, PAR_SCRIPT);
final String transformed = Unix4j
.from(inputData)
.sed(sedSpec)
.toStringResult();
fLogger.info("transforming inputstream with: " + sedSpec);
return wrapInEntity(transformed);
}