I'm using nlog it's working well for log file but I want to add log info in db too.
But it's not working for me.
I couldn't find my problem.
I'm using postgresql as database.
I'm using .NET5
NLog 4.7.10
nlog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="allfile" xsi:type="File"
fileName="D:\BEBKA.JobTracking.logs\${shortdate}.log"/>
<target xsi:type="Database" name="db" dbProvider="Npgsql.NpgsqlConnection, Npgsql" connectionstring="Server=127.0.0.1;Port=5432;Database=BEBKAJobTracking;User Id=postgres;Password=123;">
<commandText>
INSERT INTO public."Logs"("Type", "Method", "StatusCode", "StackTrace", "MethodName", "Message", "RequestData", "ResponseData", "Ip", "CreatedDate", "CreatedId")
VALUES (#Type, #Method, #StatusCode, #StackTrace, #MethodName, #Message, #RequestData, #ResponseData, #Ip, #CreatedDate, #CreatedId);
</commandText>
<parameter name="#Type" layout="${type}"/>
<parameter name="#Method" layout="${method}"/>
<parameter name="#StatusCode" layout="${statusCode}"/>
<parameter name="#StackTrace" layout="${stackTrace}"/>
<parameter name="#MethodName" layout="${methodName}"/>
<parameter name="#Message" layout="${message}"/>
<parameter name="#RequestData" layout="${requestData}"/>
<parameter name="#ResponseData" layout="${responseData}"/>
<parameter name="#Ip" layout="${ip}"/>
<parameter name="#CreatedDate" layout="${createdDate}"/>
<parameter name="#CreatedId" layout="${createdId}"/>
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="allfile" />
<logger name="db" minlevel="Trace" writeTo="db" />
</rules>
</nlog>
My logger service
using BEBKA.Infrastructure.Abstractions.Core;
using BEBKA.Infrastructure.Abstractions.Loggger.Interfaces;
using NLog;
namespace BEBKA.Infrastructure.Services
{
public class LoggerService : ILoggerService
{
private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
public void LogDebug(ILog log)
{
logger.Debug(log.Message);
}
public void LogDebug(string message)
{
logger.Debug(message);
}
public void LogError(ILog log)
{
logger.Error(log.Message);
}
public void LogError(string message)
{
logger.Error(message);
}
public void LogInfo(ILog log)
{
//TODO: Need Bugfix
LogEventInfo theEvent = new(LogLevel.Info, "db", log.Message);
SetLogEventInfo(theEvent, log);
logger.Log(theEvent);
//logger.Info("{message}",log.Message);
}
public void LogInfo(string message)
{
logger.Info(message);
}
public void LogWarn(ILog log)
{
logger.Warn(log.Message);
}
public void LogWarn(string message)
{
logger.Warn(message);
}
private static void SetLogEventInfo(LogEventInfo theEvent, ILog
data)
{
theEvent.Properties["Type"] = data.Type;
theEvent.Properties["Method"] = data.Method;
theEvent.Properties["StatusCode"] = data.StatusCode;
theEvent.Properties["StackTrace"] = data.StackTrace;
theEvent.Properties["MethodName"] = data.MethodName;
theEvent.Properties["Message"] = data.Message;
theEvent.Properties["RequestData"] = data.RequestData;
theEvent.Properties["ResponseData"] = data.ResponseData;
theEvent.Properties["Ip"] = data.Ip;
theEvent.Properties["CreatedDate"] = data.CreatedDate;
theEvent.Properties["CreatedId"] = data.CreatedId;
}
}
}
..................................................................................................................................................................................................................................................................
You have several issues going on:
Event-Properties must be rendered with help from ${event-properties}
<parameter name="#Type" layout="${event-properties:type}"/>
<parameter name="#Method" layout="${event-properties:method}"/>
<parameter name="#StatusCode" layout="${event-properties:statusCode}"/>
<parameter name="#StackTrace" layout="${event-properties:stackTrace}"/>
<parameter name="#MethodName" layout="${event-properties:methodName}"/>
<parameter name="#Message" layout="${event-properties:message}"/>
<parameter name="#RequestData" layout="${event-properties:requestData}"/>
<parameter name="#ResponseData" layout="${event-properties:responseData}"/>
<parameter name="#Ip" layout="${event-properties:ip}"/>
<parameter name="#CreatedDate" layout="${event-properties:createdDate}"/>
<parameter name="#CreatedId" layout="${event-properties:createdId}"/>
Logger-Name should never be assigned, but must be null for filtering to work
public class LoggerService : ILoggerService
{
private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
private static readonly ILogger Dblogger = LogManager.GetLogger("db");
public void LogInfo(ILog log)
{
LogEventInfo theEvent = new(LogLevel.Info, null, log.Message);
SetLogEventInfo(theEvent, log);
Dblogger.Log(theEvent); // DbLogger matches <logger name="db" minlevel="Trace" writeTo="db" />
}
It is a little confusing that all LogEventInfo-constructors takes Logger-name as input-parameter, but it should never be assigned. Tried to improve on this, but my pull-request was rejected: https://github.com/NLog/NLog/issues/4086
Notice that one could also log ILog as single object like Dblogger.Info("{payload}", data) and extract individual properties like this: ${eventproperties:payload:objectpath=CreatedId}
Related
I'm trying to get a list of persons using JPA. Every time I run the code, I get "java.lang.IllegalArgumentException: NamedQuery of name: Persoon.getAllePersonen not found."
I tried changing the table name, replaced Persoon.getAllePersonen by getAllePersonen,.... I just can't seem to figure out what's causing the error
Persoon
#Entity
#Table(name = "Persoon")
#NamedQueries({
#NamedQuery(name = "Persoon.getAllePersonen",
query = "SELECT p FROM Persoon p"),
#NamedQuery(name = "Persoon.findByName",
query = "SELECT p FROM Persoon p WHERE p.achternaam = :persoonNaam OR p.voornaam = :persoonNaam")
})
public class Persoon implements Serializable {
PersoonDao
public List<Persoon> getAlleLeden(){
TypedQuery<Persoon> queryP = em.createNamedQuery("Persoon.getAllePersonen", Persoon.class);
try{ return queryP.getResultList();
} catch (NoResultException e){
throw new EntityNotFoundException("Cannot find leden");
}
}
EDIT:
Generic Superclass DAO
public class GenericDaoJpa<T>{
private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("TaijitanPU");
protected static final EntityManager em = emf.createEntityManager();
Persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="TaijitanPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>domein.Persoon</class>
<class>domein.Graad</class>
<class>domein.Locatie</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost\sqlexpress:1433;databaseName=Taijitan;integratedSecurity=true;"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
You have to do an abstract class Generic class and override the entityManager of the parent class for each child. Check below. I used EJB Stateless for the childs.
-> PARENT DAO
public abstract class AbstractDAO<T> {
...
protected abstract EntityManager getEntityManager();
-> CHILD DAO
#PersistenceContext(unitName = "yourPersistenceUnitName")
private EntityManager em;
#Override
protected EntityManager getEntityManager() {
return em;
}
When I use log4j and TestNG #DataProvider I was able to generate logs for the below code, but when I use #DataProvider the logs are getting overwritten. I tried to use #BeforeTest but it's not working. Any idea on how can I generate for logs for all the my rows?
public class DemoTest extends baseFX {
public static Logger Log = LogManager.getLogger(baseFX.class.getName());
#Test(dataProvider="DataProvider", groups = { "baseFX" })
public void loginPageNav(String Test, String newMemEmail, String newMemPass ) throws Exception {
driver=driverSetup();
Log.info("Driver is initialized");
//Creating object for the Index to the class
IndexPage indexpage = new IndexPage(driver);
Log.info("Navigated to Index Page");
//invoke method
indexpage.clickLogin().click();
Log.info("Clicked on Login");
//Creating an object for the login page and invoke its elements
LoginPage loginpage = new LoginPage(driver);
loginpage.getPassword().sendKeys(password);
loginpage.loginBtn().click();
Log.info("Member successfully logged in");
//driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.close();
}
#DataProvider
public Object[][] DataProvider() throws Exception{
Object[][] arrayObject = ReadExcelData.getExcelData("./src/test/java/Autopkg/TestData/Demo.xlsx", "Sheet1");
return arrayObject;
}
//#AfterTest
//public void tearDown(){
//}
}
I use log4j configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="basePath">./logs</Property>
</Properties>
<Appenders>
<RollingFile name="File" fileName="${basePath}/prints.log" filePattern="${basePath}/prints-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<SizeBasedTriggeringPolicy size="1000" />
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
I've read many topics with the same problem like my but it didn't solved so I've decided write here.
The problem is that when I want to edit or delete record in my project, every function implemented in Java seems to run correctly, but there aren't any changes in database.
For example in my project I've got model called 'Oddzial' (in english it's department).
I can add new Oddzial (Department) to the database and I'll see the changes. But if I want to delete everything, there aren't any errors but also there aren't any changes in database. The record which should be deleted is still in database.
Here are my files:
Model:
#Entity
#Table(name="oddzial")
public class Oddzial implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
private Integer oddzial_id;
#Size(min=3, max=25, message="test message.")
private String miasto;
#Size(min=5, max=50, message="test message.")
private String ulica;
public Integer getOddzial_id() {
return oddzial_id;
}
public void setOddzial_id(Integer oddzial_id) {
this.oddzial_id = oddzial_id;
}
public Integer getId() {
return oddzial_id;
}
public void setId(Integer id_oddzial) {
this.oddzial_id = id_oddzial;
}
public String getMiasto() {
return miasto;
}
public void setMiasto(String miasto) {
this.miasto = miasto;
}
public String getUlica() {
return ulica;
}
public void setUlica(String ulica) {
this.ulica = ulica;
}
#Override
public String toString() {
return "[" + oddzial_id + "] " + ulica + " " + miasto;
}
}
Here is Oddzial's DAO:
#Repository
public class OddzialDAOImpl implements OddzialDAO {
#Autowired
private SessionFactory sessionFactory;
private Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
public void addOddzial(Oddzial oddzial) {
getCurrentSession().save(oddzial);
}
public void updateOddzial(Oddzial oddzial) {
Oddzial oddzialToUpdate = getOddzial(oddzial.getId());
oddzialToUpdate.setMiasto(oddzial.getMiasto());
oddzialToUpdate.setUlica(oddzial.getUlica());
getCurrentSession().update(oddzialToUpdate);
}
public Oddzial getOddzial(int id) {
Oddzial oddzial = (Oddzial) getCurrentSession().get(Oddzial.class, id);
return oddzial;
}
public void deleteOddzial(int id) {
Oddzial oddzial = getOddzial(id);
if (oddzial != null)
getCurrentSession().delete(oddzial);
}
#SuppressWarnings("unchecked")
public List<Oddzial> getOddzialy() {
return getCurrentSession().createQuery("from Oddzial").list();
}
}
Here is OddzialService:
#Service
#Transactional
public class OddzialServiceImpl implements OddzialService {
#Autowired
private OddzialDAO oddzialDAO;
#Override
public void addOddzial(Oddzial oddzial) {
oddzialDAO.addOddzial(oddzial);
}
#Override
public void updateOddzial(Oddzial oddzial) {
oddzialDAO.updateOddzial(oddzial);
}
#Override
public Oddzial getOddzial(int id) {
return oddzialDAO.getOddzial(id);
}
#Override
public void deleteOddzial(int id) {
oddzialDAO.deleteOddzial(id);
}
#Override
public List<Oddzial> getOddzialy() {
return oddzialDAO.getOddzialy();
}
}
And here is Controller:
#Controller
#RequestMapping(value="/oddzial")
public class OddzialController {
#Autowired
private OddzialService oddzialService;
#RequestMapping(value="/add", method=RequestMethod.GET)
public ModelAndView addOddzialPage() {
ModelAndView modelAndView = new ModelAndView("add-oddzial-form");
modelAndView.addObject("oddzial", new Oddzial());
return modelAndView;
}
#RequestMapping(value="/add", method=RequestMethod.POST)
public String addingOddzial(#ModelAttribute #Valid Oddzial oddzial, BindingResult result) {
if(result.hasErrors()) {
return "add-oddzial-form";
}
oddzialService.addOddzial(oddzial);
String message = "Oddział został pomyślnie dodany do bazy.";
return "list-of-oddzials";
}
#RequestMapping(value="/list")
public ModelAndView listOfOddzials() {
ModelAndView modelAndView = new ModelAndView("list-of-oddzials");
List<Oddzial> oddzials = oddzialService.getOddzialy();
modelAndView.addObject("oddzials", oddzials);
return modelAndView;
}
#RequestMapping(value="/edit/{id}", method=RequestMethod.GET)
public ModelAndView editOddzialPage(#PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("edit-oddzial-form");
Oddzial oddzial = oddzialService.getOddzial(id);
modelAndView.addObject("oddzial",oddzial);
return modelAndView;
}
#RequestMapping(value="/edit/{id}", method=RequestMethod.POST)
public ModelAndView edditingOddzial(#ModelAttribute Oddzial oddzial, #PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("home");
oddzialService.updateOddzial(oddzial);
String message = "Dane zostały zmodyfikowane.";
modelAndView.addObject("message", message);
return modelAndView;
}
#RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
public ModelAndView deleteOddzial(#PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("home");
oddzialService.deleteOddzial(id);
String message = "Oddział został usunięty.";
modelAndView.addObject("message", message);
return modelAndView;
}
}
The content of my Spring configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/tutorial" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="pl.carrental" />
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="passwordEncoder"
class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<constructor-arg value="256" />
</bean>
<bean id="saltSource"
class="org.springframework.security.authentication.dao.ReflectionSaltSource">
<property name="userPropertyToUse" value="username" />
</bean>
<!-- <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"></property> </bean> <bean
class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> <property
name="flowExecutor" ref="flowExecutor"></property> </bean> <flow:flow-executor
id="flowExecutor" flow-registry="flowRegistry" /> <flow:flow-registry id="flowRegistry"
base-path="/WEB-INF/flows"> <flow:flow-location-pattern value="/**/*-flow.xml"
/> </flow:flow-registry> -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan
base-package="pl.carrental" />
The content of web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/spring-security.xml
</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>localizationFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>localizationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Thanks in advance for help
SOLVED. The line:
<tx:annotation-driven transaction-manager="transactionManager" />
must be in servlet-context.xml. Not in root-config.xml like in my case. Now transactions are committed and I can delete and update records.
I've got a silverlight project and I'm trying to configure NLog for calling static method but it doesn't (using Nlog.config).
I'm following this example.
Here's Nlog.config code:
...
<targets>
<target name="m" xsi:type="MethodCall"
className="NLogTestSilver.MainPage, NLogTestSilver"
methodName="LogMethod">
<parameter layout="${level}" />
<parameter layout="${message}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="m" />
</rules>
...
Assembly name = NLogTestSilver.dll
Here's MainPage.xaml.cs code:
namespace NLogTestSilver
{
public partial class MainPage : UserControl
{
public static Logger Logger = LogManager.GetCurrentClassLogger();
public MainPage()
{
InitializeComponent();
Logger.Fatal("Fatality");
}
public static void LogMethod(string level, string message)
{
System.Windows.Browser.HtmlPage.Window.Alert(level + " " + message);
}
}
}
P.S. Programmatic configuration works well.
So it was found out that an exception is thrown in NLog.Targets.MethodCallTarget.InitializeTarget() method while processing className parameter.
If we change
className="NLogTestSilver.MainPage, NLogTestSilver"
to
className="NLogTestSilver.MainPage, NLogTestSilver,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx"
it works great.
Where xxxxxxxxxxxxxxxx is public key token of our assembley.
When I am trying to generate Apex classes from the below WSDL file I am getting the
The following generated class(es) have compilation errors:
Error: testxyzCom
Error: unexpected token: 'limit' at 7:23
The generated class is also given below. I already have some experience in Salesforce and as far as I remember if a WSDL document contains an Apex reserved word, the word is appended with _x when the Apex class is generated. For example, limit in a WSDL document converts to limit_x in the generated Apex class. But this is not happening in above case please explain. Please help me out.
The WSDL file
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://test.xyz.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://test.xyz.com" xmlns:intf="http://test.xyz.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://test.xyz.com" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="createOpurtunityData">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="keys" type="xsd:string"/>
<element maxOccurs="unbounded" name="values" type="xsd:string"/>
<element name="limit" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="createOpurtunityDataResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="createOpurtunityDataReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="createOpurtunityDataResponse">
<wsdl:part element="impl:createOpurtunityDataResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="createOpurtunityDataRequest">
<wsdl:part element="impl:createOpurtunityData" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="TestWSDL">
<wsdl:operation name="createOpurtunityData">
<wsdl:input message="impl:createOpurtunityDataRequest" name="createOpurtunityDataRequest">
</wsdl:input>
<wsdl:output message="impl:createOpurtunityDataResponse" name="createOpurtunityDataResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestWSDLSoapBinding" type="impl:TestWSDL">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="createOpurtunityData">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="createOpurtunityDataRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="createOpurtunityDataResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestWSDLService">
<wsdl:port binding="impl:TestWSDLSoapBinding" name="TestWSDL">
<wsdlsoap:address location="http://tempuri.org/Salesforcexyz/services/TestWSDL"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Generated Apex class is
/Generated by wsdl2apex
public class testxyzCom {
public class createOpurtunityData_element {
public String[] keys;
public String[] values;
public Integer limit;
private String[] keys_type_info = new String[]{'keys','http://www.w3.org/2001/XMLSchema','string','1','-1','false'};
private String[] values_type_info = new String[]{'values','http://www.w3.org/2001/XMLSchema','string','1','-1','false'};
private String[] limit_type_info = new String[]{'limit','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://test.xyz.com','true','false'};
private String[] field_order_type_info = new String[]{'keys','values','limit'};
}
public class TestWSDL {
public String endpoint_x = 'http://tempuri.org/Salesforcexyz/services/TestWSDL';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://test.xyz.com', 'testxyzCom'};
public String[] createOpurtunityData(String[] keys,String[] values,Integer limit) {
testxyzCom.createOpurtunityData_element request_x = new testxyzCom.createOpurtunityData_element();
testxyzCom.createOpurtunityDataResponse_element response_x;
request_x.keys = keys;
request_x.values = values;
request_x.limit = limit;
Map<String, testxyzCom.createOpurtunityDataResponse_element> response_map_x = new Map<String, testxyzCom.createOpurtunityDataResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'http://test.xyz.com',
'createOpurtunityData',
'http://test.xyz.com',
'createOpurtunityDataResponse',
'testxyzCom.createOpurtunityDataResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.createOpurtunityDataReturn;
}
}
public class createOpurtunityDataResponse_element {
public String[] createOpurtunityDataReturn;
private String[] createOpurtunityDataReturn_type_info = new String[]{'createOpurtunityDataReturn','http://www.w3.org/2001/XMLSchema','string','1','-1','false'};
private String[] apex_schema_type_info = new String[]{'http://test.xyz.com','true','false'};
private String[] field_order_type_info = new String[]{'createOpurtunityDataReturn'};
}
}
I've had a similar issue recently with a WSDL that generated an APEX class using the reserved keyword 'long'.
I don't think wsdl2apex is smart enough to add a suffix to reserved keywords as you suggest.
Can you do it by hand to the generated class?
In createOpurtunityData_element
public Integer limit_x;
In TestWSDL
public String[] createOpurtunityData(String[] keys,String[] values,Integer limit_x) {
request_x.limit_x = limit_x;
I'm not 100% sure how the call to WebServiceCallout.invoke will handle this change though. If you can, it would be easier to update the web service and WSDL so it doesn't use a APEX keyword.