I have implented GetAllBusinessPartnerCommand and also customized the code in the BusinessPartnerServlet. When I try to call the application with the customized code, I always get this error.
Code GetAllBusinessPartnersCommand
package com.sap.cloud.s4hana.examples.commands;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import com.sap.cloud.s4hana.examples.BusinessPartnerServlet;
import com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory;
import com.sap.cloud.sdk.frameworks.hystrix.HystrixUtil;
import com.sap.cloud.sdk.s4hana.connectivity.ErpCommand;
import com.sap.cloud.sdk.s4hana.datamodel.odata.helper.Order;
import com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.businesspartner.BusinessPartner;
import com.sap.cloud.sdk.s4hana.datamodel.odata.services.DefaultBusinessPartnerService;
public class GetAllBusinessPartnersCommand extends ErpCommand<List<BusinessPartner>>{
private static final Logger logger = CloudLoggerFactory.getLogger(BusinessPartnerServlet.class);
public static final String CATEGORY_PERSON ="1";
public GetAllBusinessPartnersCommand() {
super(HystrixUtil.getDefaultErpCommandSetter(
GetAllBusinessPartnersCommand.class,
HystrixUtil.getDefaultErpCommandProperties().withExecutionTimeoutInMilliseconds(10000)));
}
#Override
protected List<BusinessPartner> run() throws Exception {
// TODO Auto-generated method stub
return new DefaultBusinessPartnerService().getAllBusinessPartner()
.select(BusinessPartner.BUSINESS_PARTNER,
BusinessPartner.LAST_NAME,
BusinessPartner.FIRST_NAME,
BusinessPartner.IS_MALE,
BusinessPartner.IS_FEMALE,
BusinessPartner.CREATION_DATE)
.filter(BusinessPartner.BUSINESS_PARTNER_CATEGORY.eq(CATEGORY_PERSON))
.orderBy(BusinessPartner.LAST_NAME, Order.ASC)
.execute();
}
#Override
protected List<BusinessPartner> getFallback() {
logger.warn("Fallback called because of exception:",
getExecutionException());
return Collections.emptyList();
}
}
n the following you can see the commands and the offered workaround for the problem set ALLOW_MOCKED_AUTH_HEADER=true. Before testing I checked if all variables are set correctly and set ALLOW_MOCKED_AUTH_HEADER=true again because I set it too early before.
After this steps i build my project like i always do and get the error from above when im calling the service. I also read this post where someone have the same problem and used the mentioned workaround. But this doesnt work for me and i have no clue why. TenantNotAvailableException, when trying to call business partner from s4 CF SDK
error when call page
Starting mock-server
set variables and workaround plus check
Unfortunately SAP Cloud SDK 2.x is no longer supported. Please use our migration guide to move to the latest version 3.43.0 You can find my blog post on this topic too. If you face any issues, please create another StackOverflow question (with tag sap-cloud-sdk) or comment to the blog post. For more details, please find our documentation.
Related
I want to use Step name which is mentioned in Scenario/Scenario Outline feature file. So please help me how to get the step information in Cucumber java.
You can use Hooks to get the scenario object and then its name.
Should be something like this
package util;
import cucumber.api.java.Before;
public class Hooks {
public String scenario_name;
#Before
public void getScenario(Scenario){
scenario_name = Scenario.getName();
}
}
and then, don't forget to add util, in that case, to your glue
#CucumberOptions(...glue = {"yourStepPackage","util"}...)
Hope it helps!
I'm working on some integration tests in Groovy. There are a few hundred tests and I've been tasked with removing hardcoded ID's in favor of a single file with constants. For about 500 of the files, everything works as expected (Thanks, grep and sed): hardcoded ID's have been replaced with a constant:
old
package com.example.package.tests;
class SomeTest extends BaseGroovyTest {
#Test
public void testSomething() {
def merchantId = "1234"
...
}
}
new
package com.example.package.tests;
import com.example.package.util.ConstantMerchants
class SomeTest extends BaseGroovyTest {
#Test
public void testSomething() {
def merchantId = ConstantMerchants.MERCHANT_A
...
}
}
ConstantMerchants
package com.example.package.util;
public final class ConstantMerchants {
public static final String MERCHANT_A = "1234";
public static final String MERCHANT_B = "1111";
public static final String MERCHANT_C = "2222";
public static final String MERCHANT_D = "3333";
...
private ConstantMerchants() { }
}
However, while some files were changed successfully (so the hardcoded ID is replaced with a reference to ConstantMerchants and ConstantMerchants is imported), their tests can't run due to the error:
groovy.lang.MissingPropertyException: No such property: ConstantMerchants for class: com.example.package.tests.SomeTest
I've checked multiple times, and the only modifications to the files are the addition of an import station for ConstantMerchants, and the replacement of a string ID with a ConstantMerchants counterpart.
Removing the import statement and then having eclipse add it by pressing Ctrl+Shift+O (Organize imports) results in the same file I had before removing the import statement, and the error still occurring.
Any help in resolving this issue would be very much appreciated!
You mentioned that you have many tests running and some of them fails. That makes me think that there is a dependency problem of your tests, means maybe some tests are not allowed to have the class ConstantMerchants in their import correctly.
Do the following:
Try to change the class ConstantMerchants position where all the tests have an access to that class.
Another thing you should check is your IDE synchronization:
Delete the build directory.
Rebuild the project.
Check if that helped.
No, then check for any other synchronization issues of the IDE.
If it didn't work, try another thing:
Check your building tool if it has some limitations or any Environment variable it needs for running in the best way.
And do the follows:
Delete the build directory
Perform a synchronization to the project libraries.
Rerun the project.
Most of the time it works great and can help eliminate that error.
I hope it helps.
Apparently some class that was used by a class that was used by a class (...) that was used by my test referenced ConstantMerchants but didn't properly import it.
For some reason the compiler thought this was the fault of the class at the end of the usage chain so it kept saying my tests were missing references while it was actually some util class a few layers deep. Adding the import to that file fixed the issue.
I finally found this by grepping for files that contain ConstantMerchants but not the import statement. If anyone is interested, my grep command was:
grep -L -e "import .*ConstantMerchants" $(grep -E -f /mnt/c/Data/search_replaced.txt * -rclH)
Where search_replaced.txt contains a few patterns that match the replaced IDs.
I have a button on an XPage where I want to connect to a remote OpenOffice instance. OpenOffice is started and is listening for a socket connection.
The onclick event of the button runs following SSJS:
oo = new com.test.OpenOffice();
oo.init("host=127.0.0.1,port=8107");
oo.openFile("C:\\TEMP\\Test.odt");
The code raises an excepction jva.lang.IlleagalStateException: NotesContext not initialized for the thread
The exception is raised within the method initof the class OpenOffice.
The relevant parts of the class OpenOffice is the following code:
public class DHOpenOffice implements Serializable {
private static final long serialVersionUID = -7443191805456329135L;
private XComponentContext xRemoteContext;
private XMultiComponentFactory xMCF;
private XTextDocument oTextDocument;
public DHOpenOffice() {
xRemoteContext = null;
xMCF = null;
oTextDocument = null;
}
public void init(String hostAdr) throws java.lang.Exception {
xRemoteContext = null;
XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null);
XUnoUrlResolver xUrlResolver = UnoUrlResolver.create(xLocalContext);
String sConnect = "uno:socket," + hostAdr + ",tcpNoDelay=0;urp;StarOffice.ServiceManager";
Object context = xUrlResolver.resolve(sConnect);
xRemoteContext = UnoRuntime.queryInterface(XComponentContext.class, context);
xMCF = xRemoteContext.getServiceManager();
}
The code line Object context = xUrlResolver.resolve(sConnect); is the one that raises the exception.
Why is this happing? What is the reason for this exception and how can I resolve the situation?
N.B.: The class code runs smoothly in a standalone application. The error occurs only when the code is started by a SSJS code.
It looks like a threading issue. There are a number of things you can go and try:
Wrap the whole interaction into a custom class and use it from a managed bean instead of calling it from SSJS
Make sure not to hand over any Notes objects into the custom class, only your own
Check if the Open Document Toolkit would be sufficient to do the operations you are interested in, so you don't need to run OO
let us know how it goes
Update
Try to get outside the standard XPages cycle. One way is to deploy a custom plug-in servlet:
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class OpenOfficeServlet extends HttpServlet {
// Your code goes here
}
You need to get the plugin.xml right:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.equinox.http.registry.servlets">
<servlet alias="/ooproxy" class="com.yourcompany.OpenOfficeServlet" />
</extension>
</plugin>
Then you could e.g. post a JSON structure or a serializable Java object to the servlet with the data and process it there (async if necessary). You deploy such a plug-in using the updatesite.nsf
Thanks to the answer of #stwissel I was able to solve the problem (he pointed me to the right direction).
I could solve the problem with a simple OSGI plug-in. The servlet approach solved the problem, too, but for me the OSGI plug-in was easier to use.
So these are the steps to create the plug-in
start a new plugin project
copy the open office jar files into the project and include them into the build path
copy the custom class that uses the UNO API into the plug-in
create a feature project for the plugin
create an update site
deploy the plugin via an update site
The following site where also quite helpfull:
Creating an XPages Library
Wrap an existing JAR file into a plug-in
I finally got my test servlet working from this thread?
Calling HttpServlet class from xpages client side script and regular notes forms?
The issue that remains is I am being asked to login. But my final servlet will need to run without logging in. I have my acl set to Read public document and Write public documents for anonymous.
What I don't know how to do is to make the serlet public access. Other design documents have an "Available to Public Access users" property but I am seeing no such property for java files. Would this be set somewhere else? Maybe in my IServletFactory perhaps?
I don't know why I was required to log in before but it looks like it is now working. The only thing that is requred is that Read Public Public Document be enabled.
This is a bit concerning since it at least appears there is no way to make some servlets non-public. In my case it won't be an issue but it could be an issue for others.
Also what I noticed is that if you change the Public Access acl setting, it looks like you need to rebuild your servlets for some reason or the servlets won't run. When I get a chance I will open a ticket with notes support for both of these issues.
For those wanting to execute a servlet, I suggest this article:
http://8b30b0.wordpress.com/2013/02/04/creating-a-basic-domino-servlet/#comments
But here is a much more simplifed version of IServletFactory that might be easier to understand and get working.
package test;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import com.ibm.designer.runtime.domino.adapter.ComponentModule;
import com.ibm.designer.runtime.domino.adapter.IServletFactory;
import com.ibm.designer.runtime.domino.adapter.ServletMatch;
public class TestFactory implements IServletFactory {
private ComponentModule module;
public ServletMatch getServletMatch(String contextPath, String path)
throws ServletException {
System.out.println("TestFactory:getServletMatch");
String servletPath = "";
String pathInfo = path;
return new ServletMatch(getWidgetServlet(),servletPath,pathInfo);
}
public void init(ComponentModule arg0) {
System.out.println("TestFactory:init");
this.module = arg0;
}
public Servlet getWidgetServlet() throws ServletException {
return module.createServlet("com.pnc.cld.HelloWorld", "testServlet",null);
}
}
I'm trying to create and run a simple JUnitStory to run a .story file.
I have this:
class Scenario1 extends JUnitStory {
#Delegate MySteps steps = new MySteps()
#Override
public Configuration configuration() {
return new MostUsefulConfiguration()
.useStoryLoader(new LoadFromRelativeFile(new File('src/test/groovy').toURL()))
.useStoryReporterBuilder(
new StoryReporterBuilder()
.withDefaultFormats()
.withFormats(Format.HTML, Format.CONSOLE, Format.TXT)
);
}
#Override
public List candidateSteps() {
final candidateSteps = new InstanceStepsFactory(configuration(), this).createCandidateSteps()
return candidateSteps;
}
}
With or without the delegate (copying and pasting in all the annotated methods of MySteps), whenever I run JBehave, I get the following output:
somePattern(){
// PENDING
}
It's like the individual stories don't pick up the steps.
When I create a "Stories" class and pull all the story files in with storyPaths, the individual steps are defined. Using a debugger, I see that candidateSteps is being hit, but it's not pulling in the data it needs to.
What could possibly be going on here?
You don't need to delegate to the Steps. And also you should not override candidateSteps, but rather stepsFactory. In later versions of JBehave, candidateSteps is deprecated, to make that preference for the factory method more prominent ( http://jbehave.org/reference/stable/javadoc/core/org/jbehave/core/ConfigurableEmbedder.html#candidateSteps() )
See this blog, where I explained how the basic JBehave configuration works in more detail:
http://blog.codecentric.de/en/2012/06/jbehave-configuration-tutorial/
Andreas
Here is your answer buddy:
The package of format has Changed.
This is the deprecated
import static org.jbehave.core.reporters.StoryReporterBuilder.Format.HTML;
This is the new one :)
import static org.jbehave.core.reporters.Format.HTML;
Took a while to find the answer, but was hidden on the jbehave documentation
Hope it helps!
Cheers!
You shouldn't need to use the #Delegate - your JUnitStory is not your Steps class. Can you try passing in steps where you have this?
When you pass in a class that has been bytecode manipulated for Steps classes, JBehave may not see the jbehave annotations anymore.
JBehave is old, underdeveloped technology. Don't use it.