use of java.io.InputStreamReader in project camel by apache.
the class CMSenderOneMessageImpl method doHttpPost.
private void doHttpPost(final String urlString, final String requestString) {
final HttpClient client = HttpClientBuilder.create().build();
final HttpPost post = new HttpPost(urlString);
post.setEntity(new StringEntity(requestString, Charset.forName("UTF-8")));
try {
final HttpResponse response = client.execute(post);
final int statusCode = response.getStatusLine().getStatusCode();
LOG.debug("Response Code : {}", statusCode);
if (statusCode == 400) {
throw new CMDirectException("CM Component and CM API show some kind of inconsistency. " + "CM is complaining about not using a post method for the request. And this component only uses POST requests. What happens?");
}
if (statusCode != 200) {
throw new CMDirectException("CM Component and CM API show some kind of inconsistency. The component expects the status code to be 200 or 400. New api released? ");
}
// So we have 200 status code...
// The response type is 'text/plain' and contains the actual
// result of the request processing.
// We obtaing the result text
final BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
final StringBuffer result = new StringBuffer();
String line = null;
while ((line = rd.readLine()) != null) {
result.append(line);
}
// ... and process it
line = result.toString();
if (!line.isEmpty()) {
// Line is not empty = error
LOG.debug("Result of the request processing: FAILED\n{}", line);
if (line.contains(CMConstants.ERROR_UNKNOWN)) {
throw new UnknownErrorException();
} else if (line.contains(CMConstants.ERROR_NO_ACCOUNT)) {
throw new NoAccountFoundForProductTokenException();
} else if (line.contains(CMConstants.ERROR_INSUFICIENT_BALANCE)) {
throw new InsufficientBalanceException();
} else if (line.contains(CMConstants.ERROR_UNROUTABLE_MESSAGE)) {
throw new UnroutableMessageException();
} else if (line.contains(CMConstants.ERROR_INVALID_PRODUCT_TOKEN)) {
throw new InvalidProductTokenException();
} else {
// responsibility
throw new CMResponseException("CHECK ME. I am not expecting this. ");
}
}
// Ok. Line is EMPTY - successfully submitted
LOG.debug("Result of the request processing: Successfully submited");
} catch (final IOException io) {
throw new CMDirectException(io);
} catch (Throwable t) {
if (!(t instanceof CMDirectException)) {
// Chain it
t = new CMDirectException(t);
}
throw (CMDirectException) t;
}
}
use of java.io.InputStreamReader in project camel by apache.
the class CxfRsRelayTest method testJaxrsRelayRoute.
/**
* That test builds a route chaining two cxfrs endpoints. It shows a request
* sent to the first one will be correctly transferred and consumed by the
* other one.
*/
@Test
public void testJaxrsRelayRoute() throws Exception {
final Main main = new Main();
try {
main.setApplicationContextUri("org/apache/camel/component/cxf/jaxrs/CxfRsSpringRelay.xml");
main.start();
Thread t = new Thread(new Runnable() {
/**
* Sends a request to the first endpoint in the route
*/
public void run() {
try {
JAXRSClientFactory.create("http://localhost:" + port6 + "/CxfRsRelayTest/rest", UploadService.class).upload(CamelRouteBuilder.class.getResourceAsStream(SAMPLE_CONTENT_PATH), SAMPLE_NAME);
} catch (Exception e) {
log.warn("Error uploading to http://localhost:" + port6 + "/CxfRsRelayTest/rest", e);
}
}
});
t.start();
LATCH.await(10, TimeUnit.SECONDS);
assertEquals(SAMPLE_NAME, name);
StringWriter writer = new StringWriter();
IOUtils.copyAndCloseInput(new InputStreamReader(CamelRouteBuilder.class.getResourceAsStream(SAMPLE_CONTENT_PATH)), writer);
assertEquals(writer.toString(), content);
} finally {
main.stop();
}
}
use of java.io.InputStreamReader in project camel by apache.
the class OrderTest method checkWsdl.
public void checkWsdl(InputStream in) throws Exception {
boolean containsOrderComplexType = false;
LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("complexType name=\"order\"")) {
containsOrderComplexType = true;
// break;
}
}
if (!containsOrderComplexType) {
throw new RuntimeException("WSDL does not contain complex type defintion for class Order");
}
}
use of java.io.InputStreamReader in project camel by apache.
the class FlatpackEndpoint method createDelimitedParser.
public Parser createDelimitedParser(Exchange exchange) throws InvalidPayloadException, IOException {
Reader bodyReader = exchange.getIn().getMandatoryBody(Reader.class);
Parser parser;
if (ObjectHelper.isEmpty(getResourceUri())) {
parser = getParserFactory().newDelimitedParser(bodyReader, delimiter, textQualifier);
} else {
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), resourceUri);
InputStreamReader reader = new InputStreamReader(is, IOHelper.getCharsetName(exchange));
parser = getParserFactory().newDelimitedParser(reader, bodyReader, delimiter, textQualifier, ignoreFirstRecord);
}
if (isAllowShortLines()) {
parser.setHandlingShortLines(true);
parser.setIgnoreParseWarnings(true);
}
if (isIgnoreExtraColumns()) {
parser.setIgnoreExtraColumns(true);
parser.setIgnoreParseWarnings(true);
}
return parser;
}
use of java.io.InputStreamReader in project camel by apache.
the class FlatpackEndpoint method createFixedParser.
protected Parser createFixedParser(String resourceUri, Reader bodyReader) throws IOException {
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), resourceUri);
InputStreamReader reader = new InputStreamReader(is);
Parser parser = getParserFactory().newFixedLengthParser(reader, bodyReader);
if (isAllowShortLines()) {
parser.setHandlingShortLines(true);
parser.setIgnoreParseWarnings(true);
}
if (isIgnoreExtraColumns()) {
parser.setIgnoreExtraColumns(true);
parser.setIgnoreParseWarnings(true);
}
return parser;
}
Aggregations