public FacesRequest withParameter(String name, String value) { this.connection.addRequestParameter(name, value); return this; }
public byte[] execute() { if (connection.isStarted() || connection.isFinished()) { throw new IllegalStateException(); } connection.execute(); return connection.getResponseBody(); }
public FacesRequest finish() { if (!connection.isStarted() || connection.isFinished()) { throw new IllegalStateException(); } connection.finish(); return this; }
public FacesRequest start() { if (connection.isStarted() || connection.isFinished()) { throw new IllegalStateException(); } connection.start(); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(facesServer.getContext(), connection.getRequest(), connection.getResponse(), lifecycle); if (null != viewId) { facesContext.setViewRoot(application.getViewHandler().createView(facesContext, viewId)); } return this; }
public FacesRequest submit() throws MalformedURLException, FacesException { if (!connection.isFinished()) { throw new IllegalStateException(); } // Extract VIEW_STATE value. Map<String, String> fields = getHiddenFields(connection.getContentAsString()); if (!fields.containsKey(ResponseStateManager.VIEW_STATE_PARAM)) { throw new FacesException("No view state field in response"); } FacesRequest facesRequest = createFacesRequest(connection.getRequest().getRequestURL().toString()) .withViewId(viewId); facesRequest.connection.setRequestMethod(HttpMethod.POST); for (Map.Entry<String, String> entry : fields.entrySet()) { facesRequest.withParameter(entry.getKey(), entry.getValue()); } return facesRequest; }
/** * <p class="changed_added_2_0"></p> * @param url * @throws MalformedURLException * @throws FacesException */ protected void setupFacesRequest(String url) throws MalformedURLException, FacesException { connection = facesServer.getConnection(new URL( url)); setupConnection(); connection.start(); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(facesServer .getContext(), connection.getRequest(), connection .getResponse(), lifecycle); }
public void release() { if (null != facesContext) { facesContext.release(); facesContext = null; } if (null != connection) { if (!connection.isFinished()) { connection.finish(); } connection = null; } requests.remove(this); }
protected String getRequestQueryString() { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String[]> entry : getRequestParameters().entrySet()) { if(null !=entry.getValue()){ for (String value : entry.getValue()) { if(queryString.length()>0){ queryString.append("&"); } queryString.append(encode(entry.getKey())); if(null != value){ queryString.append("=").append(encode(value)); } } } }; return queryString.length()>0?queryString.toString():null; }
/** * Parse 'application/x-www-form-urlencoded' string with parameters name/value pairs, * as it expected after a form submit. * @param queryString URL query string or POST content. */ /* (non-Javadoc) * @see org.jboss.test.faces.staging.HttpConnection#parseFormParameters(java.lang.String) */ public void parseFormParameters(String queryString) { String[] queryParams = queryString.split("&"); for (int i = 0; i < queryParams.length; i++) { String par = queryParams[i]; int eqIndex = par.indexOf('='); if (eqIndex >= 0) { // decode url-decoded values. String name = decode(par.substring(0, eqIndex)); String value = decode( par.substring(eqIndex + 1)); addRequestParameter(name, value); } else { addRequestParameter(decode(par), null); } } }
@Override public void run() { while (!this.isInterrupted()) { // Exit when thread's interrupt flag is set HttpConnection con = new HttpConnection(params, "http://surfkid.redio.de/getChannelState", this.ins); con.start(); try { Log.e("Sleep", "Begin"); UpdateState.this.sleep(5000); Log.e("Sleep", "End"); } catch (InterruptedException e) { Log.e("Sleep", "Error"); e.printStackTrace(); // Restore interrupt flag after catching InterruptedException // to make loop condition false Thread.currentThread().interrupt(); } } }
protected String decode(String value){ if(null != getRequestCharacterEncoding()){ try { return URLDecoder.decode(value, getRequestCharacterEncoding()); } catch (UnsupportedEncodingException e) { return URLDecoder.decode(value); } } else { return URLDecoder.decode(value); } }
public void addRequestParameter(String name, String value) { // checkNotStarted(); String[] values = getRequestParameters().get(name); if (null == values) { values = new String[1]; } else { String[] newValues = new String[values.length + 1]; System.arraycopy(values, 0, newValues, 0, values.length); values = newValues; } values[values.length - 1] = value; getRequestParameters().put(name, values); }
public String getResponseAsString() { return connection.getContentAsString(); }
public FacesRequest start() { if (connection.isStarted() || connection.isFinished()) { throw new IllegalStateException(); } connection.start(); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(facesServer.getContext(), connection.getRequest(), connection.getResponse(), lifecycle); if (null != viewId) { facesContext.setViewRoot(application.getViewHandler().createView(facesContext, viewId)); } return this; }
public FacesRequest submit() throws MalformedURLException, FacesException { if (!connection.isFinished()) { throw new IllegalStateException(); } // Extract VIEW_STATE value. Map<String, String> fields = getHiddenFields(connection.getContentAsString()); if (!fields.containsKey(ResponseStateManager.VIEW_STATE_PARAM)) { throw new FacesException("No view state field in response"); } FacesRequest facesRequest = createFacesRequest(connection.getRequest().getRequestURL().toString()) .withViewId(viewId); facesRequest.connection.setRequestMethod(HttpMethod.POST); for (Map.Entry<String, String> entry : fields.entrySet()) { facesRequest.withParameter(entry.getKey(), entry.getValue()); } return facesRequest; }
/** * <p class="changed_added_2_0"></p> * @param url * @throws MalformedURLException * @throws FacesException */ protected void setupFacesRequest(String url) throws MalformedURLException, FacesException { connection = facesServer.getConnection(new URL( url)); setupConnection(); connection.start(); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(facesServer .getContext(), connection.getRequest(), connection .getResponse(), lifecycle); }
public void release() { if (null != facesContext) { facesContext.release(); facesContext = null; } if (null != connection) { if (!connection.isFinished()) { connection.finish(); } connection = null; } requests.remove(this); }
protected String getRequestQueryString() { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String[]> entry : getRequestParameters().entrySet()) { if(null !=entry.getValue()){ for (String value : entry.getValue()) { if(queryString.length()>0){ queryString.append("&"); } queryString.append(encode(entry.getKey())); if(null != value){ queryString.append("=").append(encode(value)); } } } }; return queryString.length()>0?queryString.toString():null; }
/** * Parse 'application/x-www-form-urlencoded' string with parameters name/value pairs, * as it expected after a form submit. * @param queryString URL query string or POST content. */ /* (non-Javadoc) * @see org.jboss.test.faces.staging.HttpConnection#parseFormParameters(java.lang.String) */ public void parseFormParameters(String queryString) { String[] queryParams = queryString.split("&"); for (int i = 0; i < queryParams.length; i++) { String par = queryParams[i]; int eqIndex = par.indexOf('='); if (eqIndex >= 0) { // decode url-decoded values. String name = decode(par.substring(0, eqIndex)); String value = decode( par.substring(eqIndex + 1)); addRequestParameter(name, value); } else { addRequestParameter(decode(par), null); } } }
protected String decode(String value){ if(null != getRequestCharacterEncoding()){ try { return URLDecoder.decode(value, getRequestCharacterEncoding()); } catch (UnsupportedEncodingException e) { return URLDecoder.decode(value); } } else { return URLDecoder.decode(value); } }