cancel
Showing results for 
Search instead for 
Did you mean: 

URL inside UDF

Former Member
0 Kudos

Hi All,

I am developing an UDF, where I am accessing an URL.

But I want to pass a value from payload as a part of URL.

Like:

URL server = new URL("http://Host:port//AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=CC_name&action=stop");

        String userPassword = Userid + ":" + Password;
 String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
    URLConnection uc=server.openConnection();
    uc.setRequestProperty ("Authorization", "Basic " + encoding);
    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));

     while ((inputLine = br.readLine()) != null)
     output+=inputLine;
    br.close();
   }

In this code the URL is hardcoded. But I want to pass channel name from payload(channel name is one of the sender messagetype field ). Instead of channel=CC_name I want to pass channelname inside the URL.

How to achieve this?

Any pointer?

Regards

Manisha

Accepted Solutions (0)

Answers (2)

Answers (2)

rajasekhar_reddy14
Active Contributor
0 Kudos

>

>

URL server = new URL("http://Host:port//AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=CC_name&action=stop");
> 
>         String userPassword = Userid + ":" + Password;
>  String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
>     URLConnection uc=server.openConnection();
>     uc.setRequestProperty ("Authorization", "Basic " + encoding);
>     BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
> 
>      while ((inputLine = br.readLine()) != null)
>      output+=inputLine;
>     br.close();
>    }

>

Have you tested above code,is it working fine??

Regards,

Raj

Former Member
0 Kudos

Hi Raj,

Yes, the above code is working fine.

Once i m passing the value, its not working.

~manisha

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi,

Declare one varialbe URL1 and assign value to that variable till channel name,and pass channel name as string argument to the UDF,

and create one more varailbe URLFULL,then append URL1 and Channel name to the URLFULL.

then change code like

URL server = new URL(URLFULL);

it will work

Regards,

Raj

Former Member
0 Kudos

Hi Raj,

According to your idea, the URL("http://Host:port//AdapterFramework/ChannelAdminServlet?party=&service=&channel=CC_name&action=stop") will have 3 parts.

Part 1: URL from begining to Channel i.e. http://Host:port//AdapterFramework/ChannelAdminServlet?party=&service=&channel=

Part 2: I will pass Channel Name instead of CC_Name

Part 3: end of the URL i.e. &action=stop

I dont have much Java knowledge.

Could you please explain it by code example?

Thanks for your reply.

Manisha

Edited by: Manisha Das on Mar 19, 2010 11:32 AM

former_member181985
Active Contributor
0 Kudos
URL server = new URL("http://Host:port//AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=" + a + "&action=stop");

a is the input field which carries channel name.

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi,

follow praveen reply,its very simple than my approch,if praveen approch not working i will give you code.

Regards,

Raj

Former Member
0 Kudos

I did that method and got error so i have raised this issue in SDN.

And the error was:

usr/sap/SID/DVEBMGS22/j2ee/cluster/server0/./temp/classpath_resolver/Mapd31430c0334511dfa3f0aef8ecf0e303/source/com/sap/xi/tf/_MM_Name_Stop_.java:65: empty character literal URL server = new URL("http://Host:port/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=" + Name + ''&action=stop"); ^ /usr/sap/SID/DVEBMGS22/j2ee/cluster/server0/./temp/classpath_resolver/Mapd31430c0334511dfa3f0aef8ecf0e303/source/com/sap/xi/tf/_MM_CommunicationChannel_Stop_.java:65: unclosed character literal URL server = new URL("http://Host:port/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=" + Name + ''&action=stop"); ^ /usr/sap/SID/DVEBMGS22/j2ee/cluster/server0/./temp/classpath_resolver/Mapd31430c0334511dfa3f0aef8ecf0e303/source/com/sap/xi/tf/_MM_CommunicationChannel_Stop_.java:65: unclosed string literal URL server = new URL("http://Host:port/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=" + Name + ''&action=stop");

Edited by: Manisha Das on Mar 19, 2010 11:56 AM

former_member181985
Active Contributor
0 Kudos

can you post the entire UDF code.

I guess your java code is throwing some exception. Use a try catch block and write the error to trace.

Regards,

Praveen Gujjeti.

Edited by: Praveen Gujjeti on Mar 19, 2010 4:56 PM

former_member181985
Active Contributor
0 Kudos
URL server = new URL("http://Host:port/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=" + Name + ' '&action=stop");

that is incorrect, the error you are getting is a java syntactical error

give like this.........

URL server = new URL("http://Host:port/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=" + Name + "&action=stop");

Edited by: Praveen Gujjeti on Mar 19, 2010 5:14 PM

Former Member
0 Kudos

Hi praveen,

Thanks for ur help.

Now no error.

manisha

Edited by: Manisha Das on Mar 19, 2010 1:03 PM

former_member181985
Active Contributor
0 Kudos

can you mark this thread as closed if your issue is resolved.............

Former Member
0 Kudos

Hi Praveen,

There is no error but I am not getting the result.

Is "//" in the URL is special charecter and not able to get the result by passing that as string?

Any idea?

Manisha

former_member181985
Active Contributor
0 Kudos

no that is not a special character.

Better do a standalone java test first. If it works the same should work in UDF too.........

Regards,

Praveen Gujjeti.

former_member181985
Active Contributor
0 Kudos

Have you done all the setting according this link for controlling channel externally:

[Controlling a Communication Channel Externally |http://help.sap.com/saphelp_nw04/helpdata/en/45/0c86aab4d14dece10000000a11466f/content.htm]

Former Member
0 Kudos

The URL should have single '/' after port like

http://host:port/AdapterFramework

But whereas yours is like

"http://host:port//AdapterFramework"

former_member181985
Active Contributor
0 Kudos

Use this standalone code for testing purposes. As mentioned earlier make sure that you have done settings according to this link: [Controlling a Communication Channel Externally|http://help.sap.com/saphelp_nw04/helpdata/en/45/0c86aab4d14dece10000000a11466f/content.htm]

import java.net.*;
import java.io.*;

class ExternalChannelControlXIPI
{
	public static void main(String[] args) 
	{
		try
		{
			//Give HostName, Port and Channel Name
			URL server = new URL("http://<Host:port>/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=" + <ChannelName> + "&action=stop");
			
			//Hardcode UserName & Password 
			String userPassword = "<USERNAME>" + ":" + "<PASSWORD>";
			String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
			URLConnection uc=server.openConnection();
			uc.setRequestProperty ("Authorization", "Basic " + encoding);
			BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
			String inputLine = "";
			String output = "";		 
			 while (( inputLine = br.readLine()) != null)
			     output+=inputLine;
                       System.out.print(output);
			br.close();				
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}		
	}
}

- Praveen Gujjeti.