mirror of https://github.com/apache/nifi.git
NIFI-1332 Fixed HTTP-204 handling + unit test
This closes #259. Signed-off-by: Aldrin Piri <aldrin@apache.org>
This commit is contained in:
parent
b44b177039
commit
e7a254f78e
|
@ -439,7 +439,7 @@ public class GetHTTP extends AbstractSessionFactoryProcessor {
|
||||||
}
|
}
|
||||||
final String statusExplanation = response.getStatusLine().getReasonPhrase();
|
final String statusExplanation = response.getStatusLine().getReasonPhrase();
|
||||||
|
|
||||||
if (statusCode >= 300) {
|
if ((statusCode >= 300) || (statusCode == 204)) {
|
||||||
logger.error("received status code {}:{} from {}", new Object[]{statusCode, statusExplanation, url});
|
logger.error("received status code {}:{} from {}", new Object[]{statusCode, statusExplanation, url});
|
||||||
// doing a commit in case there were flow files in the input queue
|
// doing a commit in case there were flow files in the input queue
|
||||||
session.commit();
|
session.commit();
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.nifi.processors.standard;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to mock HTTP errors responses
|
||||||
|
*/
|
||||||
|
public class HttpErrorServlet extends HttpServlet {
|
||||||
|
/** serial UID */
|
||||||
|
private static final long serialVersionUID = 7428077098486751916L;
|
||||||
|
|
||||||
|
/** error to return */
|
||||||
|
private int errorToReturn = HttpServletResponse.SC_NOT_FOUND;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
resp.sendError(this.errorToReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the HTTP error to return
|
||||||
|
* @param errorToReturn error to return
|
||||||
|
*/
|
||||||
|
public void setErrorToReturn(int errorToReturn) {
|
||||||
|
this.errorToReturn = errorToReturn;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.processors.standard;
|
package org.apache.nifi.processors.standard;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.nifi.components.state.Scope;
|
import org.apache.nifi.components.state.Scope;
|
||||||
import org.apache.nifi.flowfile.attributes.CoreAttributes;
|
import org.apache.nifi.flowfile.attributes.CoreAttributes;
|
||||||
import org.apache.nifi.reporting.InitializationException;
|
import org.apache.nifi.reporting.InitializationException;
|
||||||
|
@ -278,6 +280,52 @@ public class TestGetHTTP {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for HTTP errors
|
||||||
|
* @throws Exception exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public final void testHttpErrors() throws Exception {
|
||||||
|
// set up web service
|
||||||
|
ServletHandler handler = new ServletHandler();
|
||||||
|
handler.addServletWithMapping(HttpErrorServlet.class, "/*");
|
||||||
|
HttpErrorServlet servlet = (HttpErrorServlet) handler.getServlets()[0].getServlet();
|
||||||
|
|
||||||
|
// create the service
|
||||||
|
TestServer server = new TestServer();
|
||||||
|
server.addHandler(handler);
|
||||||
|
|
||||||
|
try {
|
||||||
|
server.startServer();
|
||||||
|
String destination = server.getUrl();
|
||||||
|
|
||||||
|
this.controller = TestRunners.newTestRunner(GetHTTP.class);
|
||||||
|
this.controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
|
||||||
|
this.controller.setProperty(GetHTTP.URL, destination+"/test_${literal(1)}.pdf");
|
||||||
|
this.controller.setProperty(GetHTTP.FILENAME, "test_${now():format('yyyy/MM/dd_HH:mm:ss')}");
|
||||||
|
this.controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
|
||||||
|
this.controller.setProperty(GetHTTP.USER_AGENT, "testUserAgent");
|
||||||
|
|
||||||
|
// 204 - NO CONTENT
|
||||||
|
servlet.setErrorToReturn(HttpServletResponse.SC_NO_CONTENT);
|
||||||
|
this.controller.run();
|
||||||
|
this.controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0);
|
||||||
|
|
||||||
|
// 404 - NOT FOUND
|
||||||
|
servlet.setErrorToReturn(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
this.controller.run();
|
||||||
|
this.controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0);
|
||||||
|
|
||||||
|
// 500 - INTERNAL SERVER ERROR
|
||||||
|
servlet.setErrorToReturn(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
this.controller.run();
|
||||||
|
this.controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0);
|
||||||
|
} finally {
|
||||||
|
// shutdown web service
|
||||||
|
server.shutdownServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void testSecure_oneWaySsl() throws Exception {
|
public final void testSecure_oneWaySsl() throws Exception {
|
||||||
// set up web service
|
// set up web service
|
||||||
|
|
Loading…
Reference in New Issue