Fórum

External form intergrating in a portlet

Sven De Rooij, modificado 10 Anos atrás.

External form intergrating in a portlet

New Member Mensagem: 1 Data de Entrada: 26/04/13 Postagens Recentes
Hello,

I have a problem during the creating of my portlet. it is rather complex so i will try to explain it.

There is a website of a third party that I need to integrate into a portlet.
This cannot be done by a IFrame because there need to be configured by possibility’s that are in a database.

I use the following code to execute the site that i:

.java file

package com.test.example;

//Import Files

public class example extends MVCPortlet {
	
	//
	public static String getPage(PortletPreferences prefs) throws Exception{
		String module = prefs.getValue("module", null); 
		if(module != null){
			String url = prefs.getValue("url", null);
			String page = loadPage(url);
			return page;
		}else{
			return null;
		}
	}

	//loads the api_url and returns the values
	private static String loadPage(String api_url) throws IOException {
		String returnLine = postUrl(api_url);
		
		return returnLine;
	}
	
	
	public static String postUrl(String uri) {
		String returnLine = "";
		final String server = uri;
	
		URL url = null;
		try {
			url = new URL(server);
		} catch (MalformedURLException ex) {
		//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
	        
		HttpURLConnection urlConn = null;
		try {
		// URL connection channel.
			urlConn = (HttpURLConnection) url.openConnection();
		} catch (IOException ex) {
			//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
	
		// Let the run-time system (RTS) know that we want input.
		urlConn.setDoInput (true);
	
		// Let the RTS know that we want to do output.
		urlConn.setDoOutput (true);
	
		// No caching, we want the real thing.
		urlConn.setUseCaches (false);
	
		try {
			urlConn.setRequestMethod("POST");
		} catch (ProtocolException ex) {
			//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
	
		try {
			urlConn.connect();
		} catch (IOException ex) {
			//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
	
		DataOutputStream output = null;
	
		try {
			output = new DataOutputStream(urlConn.getOutputStream());
		} catch (IOException ex) {
			//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
	
		// Construct the POST data.
		String content = "firstname=&lastname=&zipcode=&housenr=&search= search ";
	        
		// Send the request data.
		try {
			output.writeBytes(content);
			output.flush();
			output.close();
		} catch (IOException ex) {
			//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
	
		// Get response data.
		String str = null;
		try {
	    		BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
			while (null != (str = in.readLine())) {
			returnLine += str;
		}
		in.close ();
		return returnLine;
		} catch (IOException ex) {
			//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
		}
			return null;
		}
}


view.jsp


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="com.test.example.example" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.servlet.http.*" %>

<liferay-theme:defineobjects />
<portlet:defineobjects />

&lt;%
//getting settings/pregerences of the portlet
PortletPreferences prefs = renderRequest.getPreferences();

out.print(example.getPage(prefs));


What happens here is that I load a page that has a form on it.
When I press the send button I see in my firebug console that a post is done. But I can’t get the values of the post data.

Does anyone have an idea on how to fix this? So I can read the values of the POST request.

Kind regards,

Sven