Post ebase formdata through HTTPS without leaving the form

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

Post ebase formdata through HTTPS without leaving the form

#1

Postby Vircos » Fri Oct 05, 2007 2:00 pm

I need to post the ebase formdata to another webapplication without leaving the form itself. I wrote a java class which makes that possible. However I need to do the same thing if the external webapplication is SSL secured (through HTTPS) and that gives me headache. With the java class I wrote I get the following error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target *

Can someone help me with this?

The java class I wrote lookes like this:

Code: Select all

package com.ebasetech.ufs.customfunctions;

/**
* Class : PostForm
* 
* Function : Post data
* Date: 5-10-2007
* 
*/

import java.util.*;
import org.nfunk.jep.*;
import com.ebasetech.ufs.function.*;
import com.ebasetech.ufs.kernel.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

public class PostForm extends UFSCustomFunction {

	/**
	 * Constructor
	 */
	
	public PostForm(UFSFormInterface formInterface) {
		super(formInterface);
		numberOfParameters = 1;
	}
	
	/**
	 * Reads data form stack
	 * Pushes data into stack
	 * @throws FormException, ParseException
	 */
	
	public void run(Stack inStack) throws FormException, ParseException {
		
		checkStack(inStack);
		
		Object param1 = inStack.pop(); //URL with parameters
	
		if(param1 instanceof String) {
			
			String url = param1.toString();
						
			try {
				HttpClient httpclient = new HttpClient();
				PostMethod post = new PostMethod(url);
				
				try {
					int result = httpclient.executeMethod(post);
					if(result == 200 || result == 201 || result == 302)
						inStack.push("OK");
					else {
						String error = Integer.toString(result) + " " + post.getResponseBodyAsString();
						inStack.push(error);
					}
				} finally {
					post.releaseConnection();
				}
			} catch(Exception e) {
				throw new FormException (e.getMessage());
			}
		} else {
			throw new ParseException ("Invalid parameter type");
		}
	}
}
0 x
What's the meaning of Justice...

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

#2

Postby Wai » Fri Oct 05, 2007 2:56 pm

Something I found on the web:

HTTPS and Proxy Servers

Using HttpClient to try out URLs that involve HTTPS is the same as with ordinary URLs. Just state https://… as your URL, and it should work fine. You only need to have Java Secure Socket Extension (JSSE) running properly on your machine. JSSE ships as a part of Java Software Development Kit (JSDK) 1.4 and higher and does not require any separate download and installation.

If you have to go through a proxy server, introduce the following piece of code. Replace PROXYHOST with the host name and replace 9999 with the port number for your proxy server:

HttpClient client = new HttpClient();
HostConfiguration hConf= client.getHostConfiguration();
hConf.setProxy("PROXYHOST ", 9999);

If you also need to specify a username password for the proxy, you can do this using the setProxyCredentials method of the class HttpState. This method takes a Credentials object as a parameter. Credentials is a marker interface that has no methods and has a single implementation UsernamePasswordCredentials. You can use this class to create a Credentials object that holds the username and password required for Basic authentication.
0 x

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

#3

Postby Wai » Fri Oct 05, 2007 3:01 pm

There could also be something wrong with the certificate perhaps:

http://blogs.sun.com/andreas/entry/no_m ... le_to_find
0 x

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

#4

Postby Vircos » Mon Oct 08, 2007 7:22 am

Thank you Wai for your replies.

The problem lay with the certificate.
The hyperlink in your last post was very usefull.

I have to blame myself for not finding that link on my own :lol:

So....problem solved :)
0 x
What's the meaning of Justice...

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

#5

Postby Vircos » Wed Oct 10, 2007 6:18 am

Whaaa.....again a problem.

After installing the certificate the handshake between the httpclient and the httpserver is succesfull. But a new problem appears after that.

The httpserver does not receive any of the parameters with the correspoding values which were send in the http-request.

This only appears when using https, with normal http everything works fine. I do not use a proxy-server.

I tried the internet but was unable to find a solution. I hope you guys have an idea.
Last edited by Vircos on Wed Oct 10, 2007 12:16 pm, edited 1 time in total.
0 x
What's the meaning of Justice...

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

#6

Postby Vircos » Wed Oct 10, 2007 7:40 am

Never mind my last problem.
I have got that solved also. The problem was the 302 response code.

See http://jakarta.apache.org/httpcomponent ... rects.html for the solution.
0 x
What's the meaning of Justice...

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

#7

Postby Vircos » Wed Oct 17, 2007 2:12 pm

For the people who are interested in the custom ebase function I will post the java class for it.

Code: Select all

package com.ebasetech.ufs.customfunctions;

/**
* Class : PostForm
* 
* Function : Submits formdata to an external application using the POST http-request method
* Author: Remco Visser
* Date: 17-10-2007
* 
*/

import java.util.*;
import org.nfunk.jep.*;
import com.ebasetech.ufs.function.*;
import com.ebasetech.ufs.kernel.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

public class PostForm extends UFSCustomFunction {

	/**
	 * Constructor
	 */
	
	public PostForm(UFSFormInterface formInterface) {
		super(formInterface);
		numberOfParameters = 1;
	}
	
	/**
	 * Reads data form stack
	 * Pushes data into stack
	 * @throws FormException, ParseException
	 */
	
	public void run(Stack inStack) throws FormException, ParseException {
		
		checkStack(inStack);
		
		Object param1 = inStack.pop(); //URL
	
		if(param1 instanceof String) {
			
			String url = param1.toString();
						
			try {
				HttpClient httpclient = new HttpClient();
				PostMethod post = new PostMethod(url);
				
				try {
					int result = httpclient.executeMethod(post);
					if(result == 200 || result == 201 || result == 302) {
						
						if (result == 302 && url.contains("https")) {
					        Header locationHeader = post.getResponseHeader("location");
					        if (locationHeader != null) {
					            url = locationHeader.getValue();
					            result = httpclient.executeMethod(post);
					        } else {
					        	throw new FormException (Integer.toString(result) + " " + post.getResponseBodyAsString());	
					        }
						}
						
						String info = "External server response: " + Integer.toString(result) + " - " + post.getStatusLine();
						formInterface.logFormInfo(info);
						inStack.push("OK");
					} else {
						String error = Integer.toString(result) + " " + post.getResponseBodyAsString();
						inStack.push(error);
					}
				} finally {
					post.releaseConnection();
				}
			} catch(Exception e) {
				throw new FormException (e.getMessage());
			}
		} else {
			throw new ParseException ("Invalid parameter type");
		}
	}
}
0 x
What's the meaning of Justice...

riham
Ebase User
Posts: 1
Joined: Thu Dec 04, 2014 3:45 am

#8

Postby riham » Thu Dec 04, 2014 7:36 am

You could also use a table to store the uploaded file names. I mostly use a table with two columns to store the filename and user_filename.

An add row button triggers the upload dialog.

The addrow fpl command inserts the data into the table.

Put this in a component and you can reuse it in other forms.
0 x
Enjoy the real success with C4120-782 exam dump exam and cisco ccna online training programs and latest testking.co.uk - CBAP dumps


Who is online

Users browsing this forum: Google [Bot] and 8 guests