cancel
Showing results for 
Search instead for 
Did you mean: 

Create a JAVA client calling a proxy...

david_fryda2
Participant
0 Kudos

Hi,

I succeed creating a servlet that calls a web service via a "deployable proxy".

Is it possible to create a java class (not a servlet or jsp) that connect to this proxy ?

Here is a sample of my client class:

InitialContext ic = new InitialContext();

Z_RFC_WS_TESTService sampleWS =

(Z_RFC_WS_TESTService) ic.lookup("java:comp/env/SampleWSProxy");

The WEB server is not local....how do I insert the url and how do I get the name of the Context.INITIAL_CONTEXT_FACTORY ?

Thanks a lot.

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

Hi David,

> how do I insert the url

props.put(Context.PROVIDER_URL, "yourhost:yourport");

You'll also need to authenticate against the portal:

props.put(Context.SECURITY_PRINCIPAL, "Administrator");
props.put(Context.SECURITY_CREDENTIALS, "");

> how do I get the name

> of the Context.INITIAL_CONTEXT_FACTORY

Depends on your WAS J2EE version. For 6.20, it is

props.put(Context.INITIAL_CONTEXT_FACTORY, "com.inqmy.services.jndi.InitialContextFactoryImpl");

Then you create

InitialContext ctx = new InitialContext(props);

You'll need some lib's of the portal for communication, for 6.20 this is at least:

<classpathentry kind="var" path="SAPJ2EE/services/naming/naming.jar"/>
<classpathentry kind="var" path="SAPJ2EE/lib/inqmy-lib.jar"/>
<classpathentry kind="var" path="SAPJ2EE/lib/inqmy-frame.jar"/>
<classpathentry kind="var" path="SAPJ2EE/lib/inqmy-frame-lib.jar"/>
<classpathentry kind="var" path="SAPJ2EE/lib/iq-lib.jar"/>
<classpathentry kind="var" path="SAPJ2EE/services/p4/p4.jar"/>
<classpathentry kind="var" path="SAPJ2EE/services/appclient/appclient.jar"/>

Hope it helps

Detlev

david_fryda2
Participant
0 Kudos

Hi Detlev,

First thanks.

1) Do I have to get the same jars for WEB AS 6.40 ?

2) Can I call the "deployable proxy" that will enable me making a call to my web service ?

Thanks a lot.

detlev_beutner
Active Contributor
0 Kudos

Hi David,

for NW installation, the InitialContextFactory used should be

com.sap.engine.services.jndi.InitialContextFactoryImpl

to be found within

/usr/sap/[...]/JC[...]/j2ee/cluster/server[...]/bin/services/naming/naming.jar

This jar you should also take over for your local implementation. Different things will be missing, but start with this and take JARFinder or WinRAR or something else to look up for the JARs containing additional classes needed.

I'm not familiar with the concept of the "deployable proxy", but if you have remote access to the object, the handling should work as with all objects used remotely...

Hope it helps

Detlev

david_fryda2
Participant
0 Kudos

Thanks Detlev.

I got all the jars.

I get an exception when executing my code:

com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception during getInitialContext operation. No server is running.

Here is the client sample

Properties props = new Properties();

props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl" );

props.put(Context.PROVIDER_URL,"server:port");

Context ctx = new InitialContext(props);

There is something strange because I do successfully execute a servlet....but not a java class standalone.

Do you know what might be the problem ?

Thank you.

Message was edited by: David Fryda

detlev_beutner
Active Contributor
0 Kudos

Hi David,

the servlet is also running on a different machine? Or is it running on the same WAS J2EE where you are doing a JNDI lookup?

I never did this on 6.40, so I would advise you to look around for "jndi" "6.40" and so within the forum (I'm just going home now). If nothing works, come back again, maybe I can assist tomorrow...

Best regards

Detlev

Message was edited by: Detlev Beutner

david_fryda2
Participant
0 Kudos

Hi,

The servlet is running on the same machine (the WAS J2EE where I'm doing the lookup).

The question is still opened.

Thanks.

detlev_beutner
Active Contributor
0 Kudos

Hi David,

I'm just doing the example, not ready, but I just saw that probably you are using the wrong port (50000 instead of probably 50004). Maybe that's all?!

Hope it helps

Detlev

david_fryda2
Participant
0 Kudos

Hi Detlev,

When I use the 50004 port I get this exception:

java.lang.NoClassDefFoundError: com/sap/engine/library/bytecode/tracing/Tracer

Do you know what it is ?

Just to be sure that we are doing the same thing.

I create a Deplyable Proxy that points on a wsdl file.

I deployed it on a J2EE engine server WAS 6.40.

I want to create a java class standalone and connect to my proxy.

Do I need authentication when I want to loockup to my proxy ?

Do I have to create a Standalone proxy instead of a Deplyable proxy.

Here are the 2 types of proxy :

· deployable proxy – a Web service client that must be deployed on the SAP J2EE Engine as an application.

· standalone proxy – a Web service client that generates stubs and runs without the J2EE Engine. This proxy can be used only with the SAP Web AS release for which it has been generated.

Last question: do I have to define a proxy server in the NW04 eclipse at Window > Preferences ?

Hope it will help us.

Thanks Detlev.

Message was edited by: David Fryda

detlev_beutner
Active Contributor
0 Kudos

Hi David,

first, once again, I'm not familiar with this proxy stuff. So about this I cannot say anything in detail.

All I recognized was that it seems that you try to access your J2EE servers JNDI context from outside, right? This is done by the now following solution, which shows you the whole context-tree of the J2EE's server JNDI root context:

package com.btexx.jndi.remote.test;

import java.util.Arrays;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;

public class Accessor {

  public static void main(String[] args) {
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");        
    props.put(Context.SECURITY_PRINCIPAL, "Administrator");
    props.put(Context.SECURITY_CREDENTIALS, "BTXadm");
    props.put(Context.PROVIDER_URL, "prag:50004");
    try {
      InitialContext ctx = new InitialContext(props);
      showInnerContent(ctx, 0);
    } catch (NamingException e) {
      e.printStackTrace();
    }
  }

  private static void showInnerContent(Context ctx, int indent) throws NamingException {
    NamingEnumeration enum = ctx.list("");
    while (enum.hasMore()) {
      NameClassPair pair = (NameClassPair) enum.next();
      char[] spcs = new char[indent];
      Arrays.fill(spcs, ' ');
      System.out.println(new String(spcs) + pair.getName());
      try {
        Context innerCtx = (Context) ctx.lookup(pair.getName());
        showInnerContent(innerCtx, indent+2);
      } catch (Exception e) {
      }
    }
  }

}

For this, you need the following JARs from the server (maybe there exists a client package with all together):

<classpathentry kind="lib" path="frame.jar"/>
<classpathentry kind="lib" path="naming.jar"/>
<classpathentry kind="lib" path="util.jar"/>
<classpathentry kind="lib" path="exception.jar"/>
<classpathentry kind="lib" path="boot.jar"/>
<classpathentry kind="lib" path="iq-lib.jar"/>
<classpathentry kind="lib" path="p4.jar"/>
<classpathentry kind="lib" path="log_api.jar"/>
<classpathentry kind="lib" path="cross_api.jar"/>
<classpathentry kind="lib" path="appclient.jar"/>
<classpathentry kind="lib" path="security_api.jar"/>
<classpathentry kind="lib" path="security.jar"/>
<classpathentry kind="lib" path="bytecode.jar"/>
<classpathentry kind="lib" path="logging.jar"/>

Alltogether about 3MB.

Hope it helps (it should be precious anyhow),

Detlev

david_fryda2
Participant
0 Kudos

Hi Detlev,

For sur, your help on this topic is precious.

I am asking from my IT team to create a user thus I can access the JNDI.

I asked them what the port 50004 is for ?

They told me that this port is for the "P4" service.

If you have little information on it....even few words, it could be helpfull.

When I will success calling my deplyable proxy...I will tell you.

I'm afraid that I should create a standalone proxy and not a deployable.

Thank you for the help!.

detlev_beutner
Active Contributor
0 Kudos

Hi David,

right, the J2EE remote access works over P4-protocol, this (among other stuff) is implemented within the lib's given above.

Also see http://help.sap.com/saphelp_webas630/helpdata/en/a4/38de11fc7d7b42a18c1a244b973b0e/content.htm

Hope it helps

Detlev

david_fryda2
Participant
0 Kudos

Hi Detlev,

It is almost done.

I got an admin user with all permissions.

I success looking up other ear files.

About my proxy : I cannot look it up.

I do not find it...but when I user the admin tool to see where is the proxy...I do see it.

The path is : sap.com.SampleProxy. This is where I found it in the tree.

I notice that the examples that are in the server are named , for example, "Hello.ear". My proxy is name "tempSampleProxy.ear".

Do I have to do something on server side to success looking my proxy ?

Thanks for all the help.

detlev_beutner
Active Contributor
0 Kudos

Hi David,

> About my proxy : I cannot look it up.

> I do not find it...

So you did ouput the whole context tree with the code given? And you could not find anything in relation with your proxy? Hm...

> The path is : sap.com.SampleProxy.

> This is where I found it in the tree.

In the tress of Visual Admin (down under...?)? And not in the (should be) corresponding output of my small program?

> I notice that the examples that are in the server

> are named , for example, "Hello.ear".

? When I run my program against my server, for Hello Example all I get is:

1.) webcontainer-applications-sap.com-Hello-Hello-java:comp-env-Stateless-HelloStatelessBean

2.) ejbContexts-sap.com-Hello-sap.com-Hello-Stateless-HelloStatelessBean-java:comp

3.) rfcaccessejb-sap.com-Hello-Stateless-HelloStatelessBean

4.) sap.com-Hello-Stateless-HelloStatelessBean

5.) ejbCosName-sap.com-Hello-Stateless-HelloStatelessBean

No naming with ".ear"...

> Do I have to do something

> on server side to success looking my proxy ?

Did you set any names within your descriptor? Do you see this within the output of the program?

Hope it helps

Detlev

david_fryda2
Participant
0 Kudos

Hi Detlev,

I saw the proxy with a admin tool. I do not have access to this tool...only the IT team do have.

The program shows me a list of objects...but my proxy is not there. Maybe I should do a recursion to look deeper in each node.

>Did you set any names within your descriptor?

What are the descriptors you are talking about ?

Thanks Detlev.

detlev_beutner
Active Contributor
0 Kudos

Hi David,

> The program shows me a list of objects...

> but my proxy is not there.

To get concrete: Under which control within Visual Admin did you see your deployed proxy? And there, under which complete path?

And is there something like a beginning path printed out by the program, where only the last component is missing or so?

> Maybe I should do a recursion

> to look deeper in each node.

??? It <i>is</i> recursive!?

> What are the descriptors you are talking about ?

See http://help.sap.com/sapdocu/netweaver/webas/630/helpdata/EN/1d/7e56eaede1c94d8867d98bfc15296d/conten..., the JNDI name which is set there.

In addition, do you know this thread: ? Maybe you can catch some hints from there?

Hope it helps

Detlev

Vlado
Advisor
Advisor
0 Kudos

> For this, you need the following JARs from the server

> (maybe there exists a client package with all

> together):

Sure, this is the sapj2eeclient.jar which you can find in

/usr/sap/<SID>/<INSTANCE>/j2ee/j2eeclient

In WebAS 6.20 the corresponding file is

<j2ee-install-dir>/tools/lib/client.jar

Best regards,

Vladimir

detlev_beutner
Active Contributor
0 Kudos

Thanks Vladimir. I should have searched for "*client.jar" instead of "client.jar"...

"Be generic!" - hitting my head against the wall - "Be generic!" - ...

Best regards

Detlev

david_fryda2
Participant
0 Kudos

Hi Detlev,

I see the proxy in Visual Admin tool user :

cluster->server->services->deploy->my proxy.

It still doesn't work.

I do success calling the proxy from a servlet or from a stateless EJB... but not from a java standalone class. Also, I do not success calling an EJB from a main class. It is very strange.

Thanks a lot for the help and your time.

If I success I'll tell on the forum how...

See you for futur new problems!

david_fryda2
Participant
0 Kudos

Hi Detlev,

Can you see in the Java forum my question about accessing EJB...

I thing that if I resolve the problem of accessing an EJB, I could put my proxy in the EJB and call it from my standalone java class.

But I have a problem accessing a simple EJB.

Please tell me if everything is correct

Thanks !

Answers (0)