cancel
Showing results for 
Search instead for 
Did you mean: 

Error in simple java code.

Former Member
0 Kudos

Hi folks,

I am having some problem to compile this code, anybody can help me please ?

Thanks a lot.

Patricio.

-


package Duck02;

import java.util.List;

import com.sapportals.portal.prt.component.*;

import com.sapportals.wcm.repository.IResource;

import com.sapportals.wcm.repository.ResourceContext;

import com.sapportals.wcm.repository.ResourceFactory;

import com.sapportals.wcm.util.uri.RID;

import com.sapportals.portal.security.usermanagement.IUser;

import com.sap.netweaver.bc.rf.common.exception.*;

public class MyFirstComponent extends AbstractPortalComponent

{

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

{

IResourceContext resourceContext = new ResourceContext(user);

RID rid = RID.getRID("/etc");

try {

IResource resource = ResourceFactory.getInstance().getResource(rid, resourceContext);

if( resource != null ) {

// resource found

System.out.println("resource " + resource.getRID() + " found");

} else {

// resource not found

System.out.println("resource " + resource.getRID() + " does not exist");

}

}

catch( ResourceException e ) {

// problem while retrieving the resource

System.out.println(

"exception while trying to get resource " + e.getRID()

+ ": " + e.getMessage()

);

}

}

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

add the following jar as a reference in your project.

com.sap.security.api.ep5.jar

Former Member
0 Kudos

Prakash,

I am confuse, in short which changes I have to do ?

1. Must I add these two lines or it's not necessary ?

2. import file is the same. (*.IUser)

3. Where must I add this reference (*ep5.jar)?

Patricio.

Former Member
0 Kudos

You could find the jar in your local installation directory of NWDS or you can send me an email at psingh(at)ust.net. Your code should look like following.

p

ackage Duck02;

import java.util.List;
import com.sapportals.portal.prt.component.*;
import com.sapportals.wcm.repository.IResource;
import com.sapportals.wcm.repository.ResourceContext;
import com.sapportals.wcm.repository.ResourceFactory;
import com.sapportals.wcm.util.uri.RID;
import com.sapportals.portal.security.usermanagement.IUser;
import com.sap.netweaver.bc.rf.common.exception.*;


public class MyFirstComponent extends AbstractPortalComponent
{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{

IUser user = WPUMFactory.getUserFactory().getEP5User(request.getUser());
IResourceContext resourceContext = new ResourceContext(user);


RID rid = RID.getRID("/etc");
try {
IResource resource = ResourceFactory.getInstance().getResource(rid, resourceContext);
if( resource != null ) {
// resource found
System.out.println("resource " + resource.getRID() + " found");
} else {
// resource not found
System.out.println("resource " + resource.getRID() + " does not exist");
}
}
catch( ResourceException e ) {
// problem while retrieving the resource
System.out.println(
"exception while trying to get resource " + e.getRID()
+ ": " + e.getMessage()
);
}
}

Former Member
0 Kudos

Prakash,

I could find the jar file, but I do not know how to create this reference.

Why have you commented part of this source code ?

ps:

if I add these lines:

IUser user = WPUMFactory.getUserFactory().getEP5User(request.getUser());IResourceContext resourceContext = new ResourceContext(user);

and create the reference to jar file

Is it all that I have to do in order to compile ?

Patricio.

Former Member
0 Kudos

Hi Patricio,

Yes that is all you have to do . I have not commented out anything in your code.

I am sending you a par to your email address that i have describe in the following weblog.

Prakash

Former Member
0 Kudos

There is nothing wrong with your code. Try /documents folder and that should give you a good idea of your code works or not. What is the exception that you are getting? I have never read /etc folder before, i wonder if it is not acessible via KM api.

Former Member
0 Kudos

Hi Prakash,

I can not compile it, the error is:

In this sentence:

IResourceContext resourceContext = new ResourceContext(user);

IResourceContext can not be resolved or is not a type.

user: cannot be resolved.

Patricio.

Former Member
0 Kudos

Hi Patricio,

Sorry i didn't notice that in the code. Add the following line.

IUser user = WPUMFactory.getUserFactory().getEP5User(request.getUser());
IResourceContext resourceContext = new ResourceContext(user);

PS: Please reward points for helpful answer or problem resolved.

Former Member
0 Kudos

Prakash,

I am working with EP 6.0 SP11. If you make a copy/paste of this source in your developer studio, you can see the error.

Thanks a lot for your help.

Patricio.