Package org.exist.http.servlets

Examples of org.exist.http.servlets.RequestWrapper


    // get parameters
    final String uploadParamName = args[0].getStringValue();

    final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);
    if (value.getObject() instanceof RequestWrapper) {
      final RequestWrapper request = (RequestWrapper)value.getObject();
      final List<String> fnames = request.getUploadedFileName(uploadParamName);
      if(fnames == null) {
        return Sequence.EMPTY_SEQUENCE;
      }
      final ValueSequence result = new ValueSequence();
      for (final String name: fnames) {
View Full Code Here


            if( var.getValue().getItemType() == Type.JAVA_OBJECT ) {
                final JavaObjectValue reqValue = (JavaObjectValue)var.getValue().itemAt( 0 );

                if( reqValue.getObject() instanceof RequestWrapper) {
                    final RequestWrapper req = (RequestWrapper) reqValue.getObject();
                    final Object user = req.getAttribute(HTTP_REQ_ATTR_USER);
                    final Object passAttr = req.getAttribute(HTTP_REQ_ATTR_PASS);
                    if (user != null) {
                        final String password = passAttr == null ? null : passAttr.toString();
                        try {
                            return getBroker().getBrokerPool().getSecurityManager().authenticate(user.toString(), password);
                        } catch (final AuthenticationException e) {
                            LOG.error("User can not be authenticated: " + user.toString());
                        }
                    } else {
                        if (req.getSession() != null) {
                            return (Subject) req.getSession().getAttribute(HTTP_SESSIONVAR_XMLDB_USER);
                        }
                    }
                }
            }
        }
View Full Code Here

    if (var.getValue().getItemType() != Type.JAVA_OBJECT)
      {throw new XPathException(this, "Variable $request is not bound to an Java object.");}

    final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);
    if (value.getObject() instanceof RequestWrapper) {
            final RequestWrapper wrapper = (RequestWrapper) value.getObject();
            final Object attr = wrapper.getAttribute(XQueryURLRewrite.RQ_ATTR_REQUEST_URI);
            if (attr == null || isCalledAs("get-effective-uri"))
          {return new AnyURIValue(wrapper.getRequestURI());}
            else
                {return new AnyURIValue(attr.toString());}
    } else
      {throw new XPathException(this, "Variable $request is not bound to a Request object.");}
  } 
View Full Code Here

     */
    private void declareVariables(XQueryContext context, HttpServletRequest request, HttpServletResponse response) throws XPathException
    {
      if(request != null)
      {
        final RequestWrapper reqw = new HttpRequestWrapper(request, formEncoding, containerEncoding);
          context.declareVariable(RequestModule.PREFIX + ":request", reqw);
          context.declareVariable(SessionModule.PREFIX + ":session", reqw.getSession( false ));
      }
       
      if(response != null)
      {
        final ResponseWrapper respw = new HttpResponseWrapper(response);
View Full Code Here

        final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);

        if(!(value.getObject() instanceof RequestWrapper)) {
            throw new XPathException(this, "Variable $request is not bound to a Request object.");
        }
        final RequestWrapper request = (RequestWrapper)value.getObject();

        //if the content length is unknown or 0, return
        if(request.getContentLength() == -1 || request.getContentLength() == 0) {
            return Sequence.EMPTY_SEQUENCE;
        }
       
        InputStream isRequest = null;
        Sequence result = Sequence.EMPTY_SEQUENCE;
        try {
           
            isRequest = request.getInputStream();

            //was there any POST content?
            /**
             * There is a bug in HttpInput.available() in Jetty 7.2.2.v20101205
             * This has been filed as Bug 333415 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=333415
             * It is expected to be fixed in the Jetty 7.3.0 release
             */

            //TODO reinstate call to .available() when Jetty 7.3.0 is released, use of .getContentLength() is not reliable because of http mechanics
            //if(is != null && is.available() > 0) {
            if(isRequest != null && request.getContentLength() > 0) {

                // 1) determine if exists mime database considers this binary data
                String contentType = request.getContentType();
                if(contentType != null) {
                    //strip off any charset encoding info
                    if(contentType.indexOf(";") > -1) {
                        contentType = contentType.substring(0, contentType.indexOf(";"));
                    }

                    final MimeType mimeType = MimeTable.getInstance().getContentType(contentType);
                    if(mimeType != null && !mimeType.isXMLType()) {

                        //binary data
                        result = BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), isRequest);
                    }
                }

                if(result == Sequence.EMPTY_SEQUENCE) {
                    //2) not binary, try and parse as an XML documemnt, otherwise 3) return a string representation
                   
                    //parsing will consume the stream so we must cache!
                    InputStream is = null;
                    FilterInputStreamCache cache = null;
                    try {
                        //we have to cache the input stream, so we can reread it, as we may use it twice (once for xml attempt and once for string attempt)
                        cache = FilterInputStreamCacheFactory.getCacheInstance(new FilterInputStreamCacheConfiguration(){

                            @Override
                            public String getCacheClass() {
                                return (String) context.getBroker().getConfiguration().getProperty(Configuration.BINARY_CACHE_CLASS_PROPERTY);
                            }
                        });
                        is = new CachingFilterInputStream(cache, isRequest);
                       
                        //mark the start of the stream
                        is.mark(Integer.MAX_VALUE);
                       
                        //2) try and  parse as XML
                        result = parseAsXml(is);
                       
                       
                        if(result == Sequence.EMPTY_SEQUENCE) {
                            // 3) not a valid XML document, return a string representation of the document
                            String encoding = request.getCharacterEncoding();
                            if(encoding == null) {
                                encoding = "UTF-8";
                            }

                            try {
View Full Code Here

        final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);

        if (value.getObject() instanceof RequestWrapper) {

            final RequestWrapper request = (RequestWrapper) value.getObject();

            final List<File> files = request.getFileUploadParam(uploadParamName);
            if (files == null) {
                logger.debug("File param not found: " + uploadParamName);
                return Sequence.EMPTY_SEQUENCE;
            }
View Full Code Here

    // get parameters
    final String uploadParamName = args[0].getStringValue();

    final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);
    if (value.getObject() instanceof RequestWrapper) {
      final RequestWrapper request = (RequestWrapper)value.getObject();
      final List<File> files = request.getFileUploadParam(uploadParamName);
      if(files == null) {
        return Sequence.EMPTY_SEQUENCE;
      }
      final ValueSequence result = new ValueSequence();
      for (final File file : files) {
View Full Code Here

      {throw new XPathException(this, "Variable $request is not bound to an Java object.");}
    final JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0);
   
    if(value.getObject() instanceof RequestWrapper)
    {
      final RequestWrapper request = (RequestWrapper)value.getObject();
   
      //get the username and password parameters
      final String userName = args[0].getStringValue();
      final String passwd = args[1].getStringValue();
     
      //try and validate the user and password
      final SecurityManager security = context.getBroker().getBrokerPool().getSecurityManager();
      Subject user;
      try {
        user = security.authenticate(userName, passwd);
      } catch (final AuthenticationException e) {
        logger.warn("Could not validate user " + userName + " ["+ e.getMessage() + "]");
        return BooleanValue.FALSE;
      }
//      why it was empty if user wasn't found??? -shabanovd
//      if (user == null)
//        return Sequence.EMPTY_SEQUENCE;

      //validated user, store in session
      context.getBroker().setUser(user);
      final SessionWrapper session = request.getSession(true);
      session.setAttribute("user", userName);
      session.setAttribute("password", new StringValue(passwd));
      return BooleanValue.TRUE;
    }
    else
View Full Code Here

  private void declareVariables(XQueryContext context,
      HttpServletRequest request, HttpServletResponse response)
      throws XPathException {
   
    final RequestWrapper reqw = new HttpRequestWrapper(
        request,
        request.getCharacterEncoding(), request.getCharacterEncoding());
   
    final ResponseWrapper respw = new HttpResponseWrapper(response);
    // context.declareNamespace(RequestModule.PREFIX,
    // RequestModule.NAMESPACE_URI);
    context.declareVariable(RequestModule.PREFIX + ":request", reqw);
    context.declareVariable(ResponseModule.PREFIX + ":response", respw);
    context.declareVariable(SessionModule.PREFIX + ":session", reqw.getSession(false));
  }
View Full Code Here

TOP

Related Classes of org.exist.http.servlets.RequestWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.