Tabnine Logo
HttpHelper
Code IndexAdd Tabnine to your IDE (free)

How to use
HttpHelper
in
org.apache.camel.http.common

Best Java code snippets using org.apache.camel.http.common.HttpHelper (Showing top 18 results out of 315)

origin: org.apache.camel/camel-http-common

protected void readHeaders(HttpServletRequest request, HttpMessage message) {
  LOG.trace("readHeaders {}", request);
  Map<String, Object> headers = message.getHeaders();
  //apply the headerFilterStrategy
  Enumeration<?> names = request.getHeaderNames();
  while (names.hasMoreElements()) {
    String name = (String)names.nextElement();
    String value = request.getHeader(name);
    // use http helper to extract parameter value as it may contain multiple values
    Object extracted = HttpHelper.extractHttpParameterValue(value);
    // mapping the content-type
    if (name.toLowerCase().equals("content-type")) {
      name = Exchange.CONTENT_TYPE;
    }
    if (headerFilterStrategy != null
        && !headerFilterStrategy.applyFilterToExternalHeaders(name, extracted, message.getExchange())) {
      HttpHelper.appendHeader(headers, name, extracted);
    }
  }
  if (request.getCharacterEncoding() != null) {
    headers.put(Exchange.HTTP_CHARACTER_ENCODING, request.getCharacterEncoding());
    message.getExchange().setProperty(Exchange.CHARSET_NAME, request.getCharacterEncoding());
  }
  try {
    populateRequestParameters(request, message);
  } catch (Exception e) {
    throw new RuntimeCamelException("Cannot read request parameters due " + e.getMessage(), e);
  }
}
origin: org.apache.camel/camel-http-common

/**
 * Deserializes the input stream to a Java object
 *
 * @param is input stream for the Java object
 * @return the java object, or <tt>null</tt> if input stream was <tt>null</tt>
 * @throws ClassNotFoundException is thrown if class not found
 * @throws IOException can be thrown
 * @deprecated Camel 3.0 
 * Please use the one which has the parameter of camel context
 */
@Deprecated
public static Object deserializeJavaObjectFromStream(InputStream is) throws ClassNotFoundException, IOException {
  return deserializeJavaObjectFromStream(is, null);
}

origin: org.apache.camel/camel-http-common

/**
 * Reads the response body from the given http servlet request.
 *
 * @param request  http servlet request
 * @param exchange the exchange
 * @return the request body, can be <tt>null</tt> if no body
 * @throws IOException is thrown if error reading response body
 */
public static Object readRequestBodyFromServletRequest(HttpServletRequest request, Exchange exchange) throws IOException {
  InputStream is = HttpConverter.toInputStream(request, exchange);
  return readResponseBodyFromInputStream(is, exchange);
}

origin: org.apache.camel/camel-http

contentType = header.getValue();
HttpHelper.setCharsetFromContentType(contentType, exchange);
  return HttpHelper.deserializeJavaObjectFromStream(is, exchange.getContext());
} else {
origin: org.apache.camel/camel-http

protected HttpMethod createMethod(Exchange exchange) throws Exception {
  String url = HttpHelper.createURL(exchange, getEndpoint());
  URI uri = HttpHelper.createURI(exchange, url, getEndpoint());
  String rewriteUrl = HttpHelper.urlRewrite(exchange, url, getEndpoint(), this);
  if (rewriteUrl != null) {
  String methodName = HttpHelper.createMethod(exchange, getEndpoint(), requestEntity != null).name();
  HttpMethods methodsToUse = HttpMethods.valueOf(methodName);
  HttpMethod method = methodsToUse.createMethod(url);
origin: org.apache.camel/camel-http-common

protected void populateRequestParameters(HttpServletRequest request, HttpMessage message) throws Exception {
  //we populate the http request parameters without checking the request method
  Map<String, Object> headers = message.getHeaders();
  Enumeration<?> names = request.getParameterNames();
  while (names.hasMoreElements()) {
    String name = (String)names.nextElement();
    // there may be multiple values for the same name
    String[] values = request.getParameterValues(name);
    LOG.trace("HTTP parameter {} = {}", name, values);
    if (values != null) {
      for (String value : values) {
        if (headerFilterStrategy != null
          && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) {
          HttpHelper.appendHeader(headers, name, value);
        }
      }
    }
  }
}
origin: org.apache.camel/camel-http-common

HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
exchange.setIn(new HttpMessage(exchange, consumer.getEndpoint(), request, response));
origin: org.apache.camel/camel-undertow

LOG.debug("Http responseCode: {}", code);
final boolean ok = HttpHelper.isStatusCodeOk(code, "200-299");
if (!ok && throwExceptionOnFailure) {
origin: org.apache.camel/camel-http-common

/**
 * Writes the given object as response body to the servlet response
 * <p/>
 * The content type will be set to {@link HttpConstants#CONTENT_TYPE_JAVA_SERIALIZED_OBJECT}
 *
 * @param response servlet response
 * @param target   object to write
 * @throws IOException is thrown if error writing
 */
public static void writeObjectToServletResponse(ServletResponse response, Object target) throws IOException {
  response.setContentType(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
  writeObjectToStream(response.getOutputStream(), target);
}
origin: org.apache.camel/camel-http-common

if (headerFilterStrategy != null
    && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) {
  HttpHelper.appendHeader(headers, name, value);
origin: codice/ddf

HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
exchange.setIn(new HttpMessage(exchange, consumer.getEndpoint(), request, response));
origin: org.apache.camel/camel-http

boolean ok = HttpHelper.isStatusCodeOk(responseCode, getEndpoint().getOkStatusCodeRange());
if (ok) {
origin: org.apache.camel/camel-http

HttpHelper.writeObjectToStream(bos, obj);
answer = new ByteArrayRequestEntity(bos.toByteArray(), HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
IOHelper.close(bos);
origin: org.apache.camel/camel-http

Object extracted = HttpHelper.extractHttpParameterValue(value);
if (strategy != null && !strategy.applyFilterToExternalHeaders(name, extracted, exchange)) {
  HttpHelper.appendHeader(answer.getHeaders(), name, extracted);
origin: org.apache.camel/camel-jetty9

HttpHelper.appendHeader(headers, name, value);
if (getHeaderFilterStrategy() != null
  && !getHeaderFilterStrategy().applyFilterToExternalHeaders(name, value, message.getExchange())) {
  HttpHelper.appendHeader(headers, name, value);
origin: org.apache.camel/camel-http

String okCodes = getOption(parameters, "okStatusCodeRange", String.class).orElse("200-299");
if (!HttpHelper.isStatusCodeOk(code, okCodes)) {
  if (code == 401) {
origin: org.apache.camel/camel-http

Object body = HttpHelper.readResponseBodyFromInputStream(method.getResponseBodyAsStream(), exchange);
origin: org.apache.camel/camel-http-common

protected void readBody(HttpServletRequest request, HttpMessage message) {
  LOG.trace("readBody {}", request);
  // lets parse the body
  Object body = message.getBody();
  // reset the stream cache if the body is the instance of StreamCache
  if (body instanceof StreamCache) {
    ((StreamCache) body).reset();
  }
  // if content type is serialized java object, then de-serialize it to a Java object
  if (request.getContentType() != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(request.getContentType())) {
    // only deserialize java if allowed
    if (allowJavaSerializedObject || isTransferException()) {
      try {
        InputStream is = message.getExchange().getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, body);
        Object object = HttpHelper.deserializeJavaObjectFromStream(is, message.getExchange().getContext());
        if (object != null) {
          message.setBody(object);
        }
      } catch (Exception e) {
        throw new RuntimeCamelException("Cannot deserialize body to Java object", e);
      }
    } else {
      // set empty body
      message.setBody(null);
    }
  }
  populateAttachments(request, message);
}
org.apache.camel.http.commonHttpHelper

Most used methods

  • appendHeader
    Appends the key/value to the headers. This implementation supports keys with multiple values. In suc
  • setCharsetFromContentType
  • deserializeJavaObjectFromStream
    Deserializes the input stream to a Java object
  • extractHttpParameterValue
    Extracts the parameter value. This implementation supports HTTP multi value parameters which is base
  • isStatusCodeOk
    Checks whether the given http status code is within the ok range
  • readResponseBodyFromInputStream
    Reads the response body from the given input stream.
  • writeObjectToStream
    Writes the given object as response body to the output stream
  • createMethod
    Creates the HttpMethod to use to call the remote server, often either its GET or POST.
  • createURI
    Creates the URI to invoke.
  • createURL
    Creates the URL to invoke.
  • getCharsetFromContentType
  • readRequestBodyFromServletRequest
    Reads the response body from the given http servlet request.
  • getCharsetFromContentType,
  • readRequestBodyFromServletRequest,
  • urlRewrite,
  • writeObjectToServletResponse

Popular in Java

  • Running tasks concurrently on multiple threads
  • putExtra (Intent)
  • getApplicationContext (Context)
  • getResourceAsStream (ClassLoader)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now