cancel
Showing results for 
Search instead for 
Did you mean: 

http-adapter: Convert html-post to JAVA-post?

Former Member
0 Kudos

Hello everybody,

unfortunately I am not a java programmer. But I am testing the http adapter.

Is it possible to convert the following html-post into JAVA code?

<html><head>

<body>

<form action="http://myserver" method="post">

<p>Interface Namespace<br>

<input name="namespace" value="http://mum.mappings" size="40"></p>

<p>(Sender-) Service:<br>

<input name="service" value="MUMHTTP" size="40"></p>

<p>Interface Name:<br>

<input name="interface" value="MI_Merge_1" size="40"></p>

<p>Text:<br>

<textarea name="Text" rows="5" cols="50"></textarea></p>

<p><input type="submit" value="Send"></p>

</form>

</form>

</body>

</head>

</html>

For me it is important to send the values of the <input> values.

How has the code look like?

Many regards, mario

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi anath,

I get the following error:

*************************************************

java.net.UnknownHostException: http

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at sun.net.NetworkClient.doConnect(Unknown Source)

at sun.net.www.http.HttpClient.openServer(Unknown Source)

at sun.net.www.http.HttpClient.openServer(Unknown Source)

at sun.net.www.http.HttpClient.<init>(Unknown Source)

at sun.net.www.http.HttpClient.<init>(Unknown Source)

at sun.net.www.http.HttpClient.New(Unknown Source)

at sun.net.www.http.HttpClient.New(Unknown Source)

at sun.net.www.http.HttpClient.New(Unknown Source)

at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)

at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)

at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)

at sun.main(sun.java:41)

*************************************************

Is my import correct?:

import java.net.HttpURLConnection;

Thanks a lot, regards Mario

Former Member
0 Kudos

Hi Mario,

Yes, you have to import the following classes..


import java.net.HttpURLConnection;
import java.net.URL;

Did you try giving Host as IP address or you can try fully qualified URL like (http://xiserver.orgname.com:PORT_NUM etc)??

And one more point to be noted here is You need to give XIAPPLUSER and corresponding password in the URL itself.

Regards,

Ananth

Former Member
0 Kudos

Hi Mario,

I Have once used this code snippet to send a payload to XI engine. Please change the parameters like XI server URL,

Namespace,senderservice etc..

Please let me know if you need any further help.

Regards,

Ananth


public static void main(String[] args) throws Exception {
	try {

		URL sapURL = null;

		String urlString = "http://"+serverHost+":"+serverPort+"/sap/xi/adapter_plain?namespace="+senderNamespace+"&interface="
+senderInterface+"&service="+senderservice+"&party=&agency=&scheme=&QOS="+QOS+"&sap-user="+sapUser+"&sap-password="+
sapPWD+"&sap-client="+client+"&sap-language=E";

		sapURL= new URL(urlString);
		HttpURLConnection xi = (HttpURLConnection)sapURL.openConnection();

		xi.setRequestMethod("POST");
		xi.setRequestProperty("Content-Type","text/xml");
		xi.setDoOutput(true);

			
		generateXML(xi.getOutputStream());

		
		System.out.println(urlString);
		System.out.println("Resp Msg:"+xi.getResponseMessage()+" -- Resp Msg:"+xi.getResponseCode());
		
		xi= null;

		
	} catch (Exception e) {
			e.printStackTrace();
	}

}

public static void generateXML(OutputStream out){
	try {

		PrintWriter prt = new PrintWriter(out,false);

		//Create XML tags
		prt.println("<?xml version= "1.0"?>");

		prt.print("<"+resp_MsgType+" xmlns:ns=""+resp_NameSpace+"">");
		prt.print("<"+xml_tag1+">");
		prt.print(xml_tagValue1);
		prt.print("</"+xml_tag1+">");
		prt.print("<"+xml_tag2+">");
		prt.print(xml_tagValue2);
		prt.print("</"+xml_tag2+">");
		prt.print("</"+resp_MsgType+">");

		prt.flush();
		prt.close();
		out.close();
		prt=null;
		out=null;

		}catch(Exception e){
			e.printStackTrace();
		 }

}