Java Code Examples for org.apache.olingo.commons.api.http.HttpMethod#GET

The following examples show how to use org.apache.olingo.commons.api.http.HttpMethod#GET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractODataInvokeRequest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc }
 */
@Override
public ODataInvokeResponse<T> execute() {
  final InputStream input = getPayload();

  if (!this.parameters.isEmpty()) {
    if (this.method == HttpMethod.GET) {
      ((HttpRequestBase) this.request).setURI(
          URIUtils.buildFunctionInvokeURI(this.uri, parameters));
    } else if (this.method == HttpMethod.POST) {
      ((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));

      setContentType(getActualFormat(getPOSTParameterFormat()));
    }
  }

  try {
    return new ODataInvokeResponseImpl(odataClient, httpClient, doExecute());
  } finally {
    IOUtils.closeQuietly(input);
  }
}
 
Example 2
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void invalidMethodForChangeset() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF
      + CRLF
      + "--" + CHANGESET_BOUNDARY + CRLF
      + MIME_HEADERS
      + HttpHeader.CONTENT_ID + ": 1" + CRLF
      + CRLF
      + HttpMethod.GET + " " + PROPERTY_URI + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + CRLF
      + "--" + CHANGESET_BOUNDARY + "--"
      + CRLF
      + "--" + BOUNDARY + "--";

  parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CHANGESET_METHOD);
}
 
Example 3
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void noContentType() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + HttpHeader.ODATA_VERSION + ": 4.0" + CRLF
      + CRLF
      + HttpMethod.GET + " " + PROPERTY_URI + HTTP_VERSION + CRLF
      + CRLF
      + "--" + BOUNDARY + "--";

  parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE);
}
 
Example 4
Source File: ODataChangesetImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc }
 */
@Override
public ODataChangeset addRequest(final ODataBatchableRequest request) {
  if (!isOpen()) {
    throw new IllegalStateException("Current batch item is closed");
  }

  if (request.getMethod() == HttpMethod.GET) {
    throw new IllegalArgumentException("Invalid request. GET method not allowed in changeset");
  }

  if (!hasStreamedSomething) {
    stream((HttpHeader.CONTENT_TYPE + ": "
        + ContentType.MULTIPART_MIXED + ";boundary=" + boundary).getBytes(DEFAULT_CHARSET));

    newLine();
    newLine();

    hasStreamedSomething = true;
  }

  contentId++;

  // preamble
  newLine();

  // stream batch-boundary
  stream(("--" + boundary).getBytes(DEFAULT_CHARSET));
  newLine();

  // stream the request
  streamRequestHeader(String.valueOf(contentId));

  request.batch(req, String.valueOf(contentId));

  // add request to the list
  expectedResItem.addResponse(String.valueOf(contentId), ((AbstractODataRequest) request).getResponseTemplate());
  return this;
}
 
Example 5
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void mimeHeaderContentType() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + HttpHeader.CONTENT_TYPE + ": text/plain" + CRLF
      + CRLF
      + HttpMethod.GET + " " + PROPERTY_URI + HTTP_VERSION + CRLF
      + CRLF
      + CRLF
      + "--" + BOUNDARY + "--";

  parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.UNEXPECTED_CONTENT_TYPE);
}
 
Example 6
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void handleMediaValueDispatching(final ODataRequest request, final ODataResponse response,
    final UriResource resource) throws ContentNegotiatorException, 
   ODataApplicationException, ODataLibraryException,
    ODataHandlerException, PreconditionException {
  final HttpMethod method = request.getMethod();
  validatePreferHeader(request);
  if (method == HttpMethod.GET) {
    // This can be a GET on an EntitySet, Navigation or Function
    final ContentType requestedContentType = ContentNegotiator.
        doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.MEDIA);
    handler.selectProcessor(MediaEntityProcessor.class)
        .readMediaEntity(request, response, uriInfo, requestedContentType);
    // PUT and DELETE can only be called on EntitySets or Navigation properties which are media resources
  } else if (method == HttpMethod.PUT && (isEntityOrNavigationMedia(resource) 
      || isSingletonMedia(resource))) {
    validatePreconditions(request, true);
    final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
    final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.ENTITY);
    handler.selectProcessor(MediaEntityProcessor.class)
        .updateMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
  } else if (method == HttpMethod.DELETE && isEntityOrNavigationMedia(resource)) {
    validatePreconditions(request, true);
    handler.selectProcessor(MediaEntityProcessor.class)
        .deleteMediaEntity(request, response, uriInfo);
  } else {
    throwMethodNotAllowed(method);
  }
}
 
Example 7
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void missingHttpVersion2() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.GET + " ESAllPrim?$format=json " + CRLF
      + CRLF
      + CRLF
      + "--" + BOUNDARY + "--";

  parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HTTP_VERSION);
}
 
Example 8
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void missingHttpVersion() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.GET + " ESAllPrim?$format=json" + CRLF
      + CRLF
      + CRLF
      + "--" + BOUNDARY + "--";

  parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE);
}
 
Example 9
Source File: ODataInvokeRequestTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequest() throws URISyntaxException {
  ODataClient client = ODataClientFactory.getClient();
  Class<ClientInvokeResult> reference = ClientInvokeResult.class;
  HttpMethod method = HttpMethod.GET;
  URI uri = new URI("test");
  ODataInvokeRequestImpl req = new ODataInvokeRequestImpl<ClientInvokeResult>(client, reference, method, uri);
  assertNotNull(req);
  assertNotNull(req.getAccept());
  assertNotNull(req.getContentType());
  assertNotNull(req.getDefaultFormat());
  assertNotNull(req.getHeader());
  assertNotNull(req.getHeaderNames());
  assertNull(req.getIfMatch());
  assertNull(req.getIfNoneMatch());
  assertNotNull(req.getHttpRequest());
  assertNotNull(req.getMethod());
  assertNull(req.getPayload());
  assertNotNull(req.getPOSTParameterFormat());
  assertNotNull(req.getPOSTParameterFormat());
  assertNull(req.getPrefer());
  assertNotNull(req.getResponseTemplate());
  assertNotNull(req.getURI());
  assertNotNull(req.addCustomHeader("custom", "header"));
  assertNotNull(req.setAccept("json"));
  assertNotNull(req.setContentType("json"));
  req.setFormat(ContentType.APPLICATION_ATOM_XML);
}
 
Example 10
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void handleSingleEntityDispatching(final ODataRequest request, final ODataResponse response,
    final boolean isMedia, final boolean isSingleton) throws 
ContentNegotiatorException, ODataApplicationException,
    ODataLibraryException, ODataHandlerException, PreconditionException {
  final HttpMethod method = request.getMethod();
  if (method == HttpMethod.GET) {
    validatePreferHeader(request);
    final ContentType requestedContentType = ContentNegotiator.
        doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.ENTITY);
    handler.selectProcessor(EntityProcessor.class)
        .readEntity(request, response, uriInfo, requestedContentType);
  } else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
    if (isMedia) {
      validatePreferHeader(request);
    }
    validatePreconditions(request, false);
    final ContentType requestFormat = getSupportedContentType(
        request.getHeader(HttpHeader.CONTENT_TYPE),
        RepresentationType.ENTITY, true);
    final ContentType responseFormat = ContentNegotiator.
        doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.ENTITY);
    handler.selectProcessor(EntityProcessor.class)
        .updateEntity(request, response, uriInfo, requestFormat, responseFormat);
  } else if (method == HttpMethod.DELETE && !isSingleton) {
    validateIsSingleton(method);
    validatePreconditions(request, false);
    validatePreferHeader(request);
    if (isMedia) {
      ((MediaEntityProcessor) handler.selectProcessor(MediaEntityProcessor.class))
      .deleteEntity(request, response, uriInfo);
      } else {
      ((EntityProcessor) handler.selectProcessor(EntityProcessor.class))
      .deleteEntity(request, response, uriInfo);
    }
  } else {
    throwMethodNotAllowed(method);
  }
}
 
Example 11
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void basic() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.GET + " " + PROPERTY_URI + "?$format=json" + HTTP_VERSION + CRLF
      + HttpHeader.ACCEPT_LANGUAGE + ":en-US,en;q=0.7,en-GB;q=0.9" + CRLF
      + CRLF
      + CRLF
      + "--" + BOUNDARY +CRLF
      + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF
      + CRLF
      + "--" + CHANGESET_BOUNDARY + CRLF
      + MIME_HEADERS
      + HttpHeader.CONTENT_ID + ": changeRequest1" + CRLF
      + CRLF
      + HttpMethod.PUT + " " + PROPERTY_URI + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_LENGTH + ": 100000" + CRLF
      + ACCEPT_HEADER
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + "{\"value\":\"€ MODIFIED\"}" + CRLF
      + CRLF
      + "--" + CHANGESET_BOUNDARY + "--" + CRLF
      + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.GET + " " + PROPERTY_URI + "?$format=json" + HTTP_VERSION + CRLF
      + CRLF
      + CRLF
      + "--" + BOUNDARY + "--";
  final List<BatchRequestPart> batchRequestParts = parse(batch);

  Assert.assertNotNull(batchRequestParts);
  Assert.assertFalse(batchRequestParts.isEmpty());

  for (final BatchRequestPart object : batchRequestParts) {
    Assert.assertEquals(1, object.getRequests().size());
    final ODataRequest request = object.getRequests().get(0);
    Assert.assertEquals(SERVICE_ROOT, request.getRawBaseUri());
    Assert.assertEquals("/" + PROPERTY_URI, request.getRawODataPath());

    if (!object.isChangeSet()) {
      Assert.assertEquals(HttpMethod.GET, request.getMethod());

      if (request.getHeaders(HttpHeader.ACCEPT_LANGUAGE) != null) {
        Assert.assertEquals(3, request.getHeaders(HttpHeader.ACCEPT_LANGUAGE).size());
      }

      Assert.assertEquals(SERVICE_ROOT + "/" + PROPERTY_URI + "?$format=json", request.getRawRequestUri());
      Assert.assertEquals("$format=json", request.getRawQueryPath());

    } else {
      Assert.assertEquals(HttpMethod.PUT, request.getMethod());
      Assert.assertEquals("100000", request.getHeader(HttpHeader.CONTENT_LENGTH));
      Assert.assertEquals(APPLICATION_JSON, request.getHeader(HttpHeader.CONTENT_TYPE));

      final List<String> acceptHeader = request.getHeaders(HttpHeader.ACCEPT);
      Assert.assertEquals(4, request.getHeaders(HttpHeader.ACCEPT).size());
      Assert.assertEquals("application/atom+xml;q=0.8", acceptHeader.get(2));
      Assert.assertEquals("*/*;q=0.1", acceptHeader.get(3));

      Assert.assertEquals(SERVICE_ROOT + "/" + PROPERTY_URI, request.getRawRequestUri());
      Assert.assertEquals("", request.getRawQueryPath()); // No query parameter

      Assert.assertEquals("{\"value\":\"€ MODIFIED\"}" + CRLF, IOUtils.toString(request.getBody()));
    }
  }
}
 
Example 12
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] {HttpMethod.GET};
}
 
Example 13
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] {HttpMethod.GET};
}
 
Example 14
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void methodsForIndividualRequests() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.POST + " ESAllPrim" + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + "{ \"PropertyString\": \"Foo\" }"
      + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.DELETE + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + CRLF
      + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + "{ \"PropertyString\": \"Foo\" }" + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.PUT + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + "{ \"PropertyString\": \"Foo\" }" + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.GET + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + ACCEPT_HEADER
      + CRLF
      + CRLF
      + "--" + BOUNDARY + "--";

  final List<BatchRequestPart> requests = parse(batch);

  Assert.assertEquals(HttpMethod.POST, requests.get(0).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim", requests.get(0).getRequests().get(0).getRawODataPath());
  Assert.assertEquals("{ \"PropertyString\": \"Foo\" }",
      IOUtils.toString(requests.get(0).getRequests().get(0).getBody()));

  Assert.assertEquals(HttpMethod.DELETE, requests.get(1).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(1).getRequests().get(0).getRawODataPath());

  Assert.assertEquals(HttpMethod.PATCH, requests.get(2).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(2).getRequests().get(0).getRawODataPath());
  Assert.assertEquals("{ \"PropertyString\": \"Foo\" }",
      IOUtils.toString(requests.get(2).getRequests().get(0).getBody()));

  Assert.assertEquals(HttpMethod.PUT, requests.get(3).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(3).getRequests().get(0).getRawODataPath());
  Assert.assertEquals("{ \"PropertyString\": \"Foo\" }",
      IOUtils.toString(requests.get(3).getRequests().get(0).getBody()));

  Assert.assertEquals(HttpMethod.GET, requests.get(4).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(4).getRequests().get(0).getRawODataPath());
}
 
Example 15
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT,
      HttpMethod.DELETE };
}
 
Example 16
Source File: ServiceRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
protected boolean isGET() {
  return this.request.getMethod() == HttpMethod.GET;
}
 
Example 17
Source File: ServiceRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] {HttpMethod.GET};
}
 
Example 18
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] {HttpMethod.GET};
}
 
Example 19
Source File: AbstractODataRetrieveRequest.java    From olingo-odata4 with Apache License 2.0 2 votes vote down vote up
/**
 * Private constructor.
 *
 * @param odataClient client instance getting this request
 * @param query query to be executed.
 */
public AbstractODataRetrieveRequest(final ODataClient odataClient, final URI query) {
  super(odataClient, HttpMethod.GET, query);
}
 
Example 20
Source File: ODataRawRequestImpl.java    From olingo-odata4 with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param odataClient client instance getting this request
 * @param uri request URI.
 */
ODataRawRequestImpl(final ODataClient odataClient, final URI uri) {
  super(odataClient, HttpMethod.GET, uri);
}