Java Code Examples for org.apache.olingo.odata2.api.processor.ODataContext#getParameter()

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataContext#getParameter() . 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: CarsODataJPAServiceFactory.java    From tutorials with MIT License 6 votes vote down vote up
/**
 * This method will be called by Olingo on every request to
 * initialize the ODataJPAContext that will be used. 
 */
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {

    log.info("[I32] >>> initializeODataJPAContext()");
    ODataJPAContext ctx = getODataJPAContext();
    ODataContext octx = ctx.getODataContext();
    HttpServletRequest request = (HttpServletRequest)octx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);
    EntityManager em = (EntityManager)request.getAttribute(JerseyConfig.EntityManagerFilter.EM_REQUEST_ATTRIBUTE);
            
    // Here we're passing the EM that was created by the EntityManagerFilter (see JerseyConfig)
    ctx.setEntityManager(new EntityManagerWrapper(em));
    ctx.setPersistenceUnitName("default");
    
    // We're managing the EM's lifecycle, so we must inform Olingo that it should not
    // try to manage transactions and/or persistence sessions
    ctx.setContainerManaged(true);                
    return ctx;
}
 
Example 2
Source File: MediaProcessor.java    From lemonaid with MIT License 5 votes vote down vote up
public Object process(PostUriInfo uriParserResultView, InputStream content, String requestContentType) throws ODataException {
	initialize();
	ODataContext ctx = ODataJPAContextImpl.getContextInThreadLocal();
	HttpServletRequest request = (HttpServletRequest) ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);  		
	if (uriParserResultView.getTargetEntitySet().getEntityType().getName().equals("Attachment")) {
		Attachment attachment = new Attachment();
		attachment.setId(UUID.randomUUID().toString());
		attachment.setMimeType(requestContentType);
		attachment.setFileName(request.getHeader("slug"));
		try {
			attachment.setData(IOUtils.toByteArray(content));
		} catch (IOException e) {
			throw new ODataException(e);
		}
		attachment.setFileSize(attachment.getData().length);
		attachment.setLastModified(Calendar.getInstance());
		for (KeyPredicate keyPredicate : uriParserResultView.getKeyPredicates()) {
			if (keyPredicate.getProperty().getName().equals("Id")) {
				attachment.setMentorId(mentorRepository.findOne(keyPredicate.getLiteral()));
			}
		}
		attachmentRepository.save(attachment);
		attachment.setData(null);
		return attachment;
	}
	return null;
}
 
Example 3
Source File: BatchHandlerImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataRequestHandler createHandler(final ODataRequest request) throws ODataException {
  ODataContextImpl context = new ODataContextImpl(request, factory);
  ODataContext parentContext = service.getProcessor().getContext();
  context.setBatchParentContext(parentContext);
  context.setService(service);
  if (parentContext != null && parentContext.getParameter(BATCH_ODATA_REQUEST_HEADERS) != null) {
    context.setParameter(BATCH_ODATA_REQUEST_HEADERS, parentContext.getParameter(BATCH_ODATA_REQUEST_HEADERS));
  } else if (parentContext != null && parentContext.getRequestHeaders() != null) {
    context.setParameter(BATCH_ODATA_REQUEST_HEADERS, parentContext.getRequestHeaders());
  }
  service.getProcessor().setContext(context);
  return new ODataRequestHandler(factory, service, context);
}
 
Example 4
Source File: ContextTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void checkHttpRequest() throws ClientProtocolException, IOException, ODataException {
  final HttpGet get = new HttpGet(URI.create(getEndpoint().toString() + "/$metadata"));
  getHttpClient().execute(get);

  final ODataContext ctx = getService().getProcessor().getContext();
  assertNotNull(ctx);

  final Object requestObject = ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);
  assertNotNull(requestObject);
  assertTrue(requestObject instanceof HttpServletRequest);
}
 
Example 5
Source File: ODataAuthorization.java    From lemonaid with MIT License 4 votes vote down vote up
private HttpServletRequest getRequest() {
	ODataContext ctx = ODataJPAContextImpl.getContextInThreadLocal();  
	HttpServletRequest request = (HttpServletRequest) ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);  
	return request == null ? this.request : request;
}
 
Example 6
Source File: AdministrationService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 4 votes vote down vote up
private void forceSubsequentInitialization() {
	ODataContext ctx = BenefitsODataServiceFactory.getContextInThreadLocal();
	HttpServletRequest httpServlReq = (HttpServletRequest) ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);
	httpServlReq.getSession().setAttribute(SessionListener.INITIAL_FLAG, TRUE_STR);
}
 
Example 7
Source File: ODataService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 4 votes vote down vote up
private String getSFUser() {
	ODataContext ctx = BenefitsODataServiceFactory.getContextInThreadLocal();
	HttpServletRequest httpServlReq = (HttpServletRequest) ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);
	return (String) httpServlReq.getSession().getAttribute(SessionCreateFilter.SF_USER_ID_ATTR_NAME);
}