Пример #1
0
  private String proxyRequest() {
    HttpProxyImpl proxy = new HttpProxyImpl();
    ProxyState state =
        new ProxyState("http://eprints.uitm.edu.my/cgi/search/simple", MethodType.GET);
    Map<String, String[]> params = new HashMap<String, String[]>();
    params.put("q", new String[] {"thesis"});
    params.put("hl", new String[] {"en"});
    params.put("btnG", new String[] {"Google+Search"});
    params.put("aq", new String[] {"f"});
    params.put("oq", new String[] {""});

    ProxyResponse pResponse = null;
    try {
      pResponse = proxy.request(state, params);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    XslContentTransformer xform =
        new XslContentTransformer("/com/plexobject/transform/xhtmlTransform.xslt", true);
    Map<String, String> props = new HashMap<String, String>();
    props.put("callbackHandler", "www.portlet.com");
    // props.put("portletURL",portletURL);
    String x = xform.transform(pResponse.getContents(), props);

    String content = x; // pResponse.getContents();
    return content;
  }
Пример #2
0
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    log.info("processaction");
    // read the config
    getPortletInfo(actionRequest);

    String method = actionRequest.getMethod();

    // get posted/getted params
    Map<String, String[]> paramMap = actionRequest.getParameterMap(); // .getRequestParameterMap();

    // build our proxy request to target server
    HttpProxyImpl proxy = new HttpProxyImpl();

    ProxyResponse pResponse = null;

    XslContentTransformer xform =
        new XslContentTransformer("/com/plexobject/transform/xhtmlTransform.xslt", true);
    Map<String, String> props = new HashMap<String, String>();
    props.put("callbackHandler", "www.portlet.com");
    props.put("portletURL", _portletURL);
    // props.put("portletURL",portletURL);

    String origActionURL = "", rootURL = _proxyURL;

    Map<String, String[]> params = new HashMap<String, String[]>();
    Iterator i = paramMap.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      String value = ((String[]) paramMap.get(key))[0];

      if (key.equalsIgnoreCase("origUrl")) // test for regular link e.g. a href
      origActionURL = value;
      else if (key.equalsIgnoreCase("_originalActionUrl")) // test for form link
      origActionURL = value;
      else if (key.equalsIgnoreCase("rootURL")) rootURL = value;
      else params.put(key, paramMap.get(key));
      // log.info("Key="+ key + " value=" + value);

    }

    String url = origActionURL == "" ? _proxyURL : origActionURL;
    // set relative URL

    if (Validator.isNotNull(_state)) rootURL = _state.getUri();
    url = buildProxyURL(url, rootURL);

    log.info("url=" + url + " method=" + method + " rooturl=" + rootURL);

    if (_state == null) _state = new ProxyState(url, method);
    else _state.setUri(url, method);
    pResponse = proxy.request(_state, params);

    String response = xform.transform(pResponse.getContents(), props);
    // System.out.print(response);
    // log.info(response);
    actionRequest.setAttribute("result", response);
    actionRequest.setAttribute("url", url);
    log.info("endAction");
    /*
    //show the result
    String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),portletName,
                   themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
    redirectURL.setParameter("jspPage", ProxyConstant.RENDER_RESPONSE); // set required parameter that you need in doView or render Method
    //redirectURL.setParameter("content", response);
    actionResponse.sendRedirect(redirectURL.toString());

           */
  }