Nifi定制的处理器没有响应,也没有显示任何问题。

huangapple go评论63阅读模式
英文:

Nifi customized processor do not response and do not show any probleme

问题

我正在使用Nifi尝试创建一个Apache Nifi处理器但它没有响应处理器已构建在处理器列表中显示并且工作但没有任何输入!!它没有显示任何内容<br>
以下是我的代码

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    final AtomicReference<String> value = new AtomicReference<>();
    Integer Somme = new Integer(1254 + 5520);

    FlowFile flowFile = session.get();
    session.read(flowFile, new InputStreamCallback() {
        @Override
        public void process(InputStream in) throws IOException {
            HttpGet request = new HttpGet(URL);

            HttpHost target = new HttpHost(localhost, 8080, "http");
            CredentialsProvider provider = new BasicCredentialsProvider();
            provider.setCredentials(
                new AuthScope(target.getHostName(), target.getPort()),
                new UsernamePasswordCredentials(Username, paswd)
            );

            AuthCache authCache = new BasicAuthCache();
            authCache.put(target, new BasicScheme());

            HttpClientContext localContext = HttpClientContext.create();
            localContext.setAuthCache(authCache);

            try (CloseableHttpClient httpClient = HttpClientBuilder.create()
                    .setDefaultCredentialsProvider(provider)
                    .build();
                CloseableHttpResponse response = httpClient.execute(target, request, localContext)) {

                // 401 if wrong user/password
                System.out.println(response.getStatusLine().getStatusCode());

                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    // return it as a String
                    String result = EntityUtils.toString(entity);
                    System.out.println(result.getBytes());
                    value.set(result);
                }
            }
        }
    });

    // Write the results to an attribute
    String results = value.get();
    if (results != null && !results.isEmpty()) {
        flowFile = session.putAttribute(flowFile, "match", results);
    }

    // To write the results back out ot flow file
    flowFile = session.write(flowFile, new OutputStreamCallback() {
        @Override
        public void process(OutputStream out) throws IOException {
            out.write(value.get().getBytes());
        }
    });

    session.transfer(flowFile, Success);
}

任何帮助将不胜感激!已经过了几天,但似乎一切都不对 Nifi定制的处理器没有响应,也没有显示任何问题。

英文:

I'm working with Nifi and I'm trying to create an Apache Nifi processor but it doesn't react ! The processor is built, it shows up in the processors list and it works but without any inputs !! it does not show me anything. <br>
Here is my code :

    @Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
final AtomicReference&lt;String&gt; value = new AtomicReference&lt;&gt;();	  
Integer Somme=new Integer(1254+5520);
FlowFile flowFile = session.get();
session.read(flowFile, new InputStreamCallback() {
@Override
public void process(InputStream in) throws IOException {
HttpGet request = new HttpGet(URL);
HttpHost target = new HttpHost(localhost, 8080, &quot;http&quot;);
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(
new AuthScope(target.getHostName(), target.getPort()),
new UsernamePasswordCredentials(Username, paswd)
);
AuthCache authCache = new BasicAuthCache();
authCache.put(target, new BasicScheme());
HttpClientContext localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);
try (CloseableHttpClient httpClient = HttpClientBuilder.create()
.setDefaultCredentialsProvider(provider)
.build();
CloseableHttpResponse response = httpClient.execute(target, request, localContext)) {
// 401 if wrong user/password
System.out.println(response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
if (entity != null) {
// return it as a String
String result = EntityUtils.toString(entity);
System.out.println(result.getBytes());
value.set(result);
}
}
}
});
// Write the results to an attribute
String results = value.get();
if(results != null &amp;&amp; !results.isEmpty()){
flowFile = session.putAttribute(flowFile, &quot;match&quot;, results);
}
// To write the results back out ot flow file
flowFile = session.write(flowFile, new OutputStreamCallback() {
@Override
public void process(OutputStream out) throws IOException {
out.write(value.get().getBytes());
}
});
session.transfer(flowFile, Success);
}
}

Any help please ! It's been days and nothing seems right Nifi定制的处理器没有响应,也没有显示任何问题。

答案1

得分: 1

当实现源处理器(表示没有输入)时,您希望使用session.create()来创建全新的流文件。使用session.get()将尝试从传入的队列中获取流文件,但由于没有队列,它将始终为空。

英文:

When implementing a source processor (meaning there is no input), then you want to use session.create() to create a brand new flow file. Using session.get() will attempt to get a flow file from incoming queues, but since there are none, it will always be null.

huangapple
  • 本文由 发表于 2020年4月8日 19:38:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/61099779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定