package com.accenture.hybris.wsmonitoring.controllers;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.accenture.hybris.wsmonitoring.core.WsMonitoringPropertiesReader;
import com.accenture.hybris.wsmonitoring.data.WsMonitoringData;
@Controller
public class WsMonitoringController
{
// @Resource(name = "wsMonitoringPropertiesReader")
// private static WsMonitoringPropertiesReader propertiesReader;
//Client HTTP utilizzato per effettuare le richieste
private final CloseableHttpClient httpclient;
private final ConcurrentHashMap<String, String> servizi;
private final static Logger LOG = Logger.getLogger(WsMonitoringController.class);
private String accountBase64;
private String username;
private String password;
public WsMonitoringController()
{
LOG.debug("WsMonitoringController---Inizio Costruttore");
final WsMonitoringPropertiesReader propertiesReader = new WsMonitoringPropertiesReader();
this.httpclient = HttpClients.createDefault();
this.servizi = new ConcurrentHashMap<String, String>();
final int numservizi = Integer.parseInt((propertiesReader.getPropertyValue("numero.servizi")));
if (propertiesReader.getPropertyValue("basicauthentication.username") != null
&& propertiesReader.getPropertyValue("basicauthentication.password") != null)
{
this.username = propertiesReader.getPropertyValue("basicauthentication.username");
this.password = propertiesReader.getPropertyValue("basicauthentication.password");
LOG.debug("username: " + this.username + " password: " + this.password);
final String account = this.username + ":" + this.password;
this.accountBase64 = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(account.getBytes());
}
LOG.debug("WsMonitoringController---trovati " + numservizi + " servizi");
for (int i = 1; i <= numservizi; i++)
{
try
{
servizi.put(propertiesReader.getPropertyValue("servizio" + i + ".nome"),
propertiesReader.getPropertyValue("servizio" + i + ".url"));
LOG.debug("WsMonitoringController---aggiunto servizio" + 1);
}
catch (final Exception e)
{
LOG.debug("servizio" + i + " non esistente");
}
}
LOG.debug("WsMonitoringController---Fine Costruttore");
}
@RequestMapping(value = "/{nomeServizio:.*}")
public String interrogaServizio(@PathVariable("nomeServizio") final String nomeServizio, final Model model)
{
LOG.debug("WsMonitoringController---Interrogazione servizio:" + nomeServizio);
final String url = servizi.get(nomeServizio);
if (null != url)
{
LOG.debug("WsMonitoringController---Interrogazione servizio: trovata url" + url);
model.addAttribute("result", doRequest(nomeServizio, url, model));
}
else
{
LOG.debug("WsMonitoringController---Interrogazione servizio:servizio:" + nomeServizio + " non esistente");
model.addAttribute("errore", nomeServizio);
}
return "pagina";
}
private WsMonitoringData doRequest(final String nome, final String url, final Model model)
{
WsMonitoringData wsData = null;
final HttpGet httpget = new HttpGet(url);
CloseableHttpResponse response = null;
try
{
if (this.accountBase64 != null && nome.equals("alfresco")) /* 12-05-2014: aggiunta condizione su servizio alfresco che è l'unico con basicauthentication */
{
LOG.debug("accountBase64: " + accountBase64);
httpget.addHeader("Authorization", accountBase64);
}
response = httpclient.execute(httpget);
wsData = new WsMonitoringData(nome, url, response.getStatusLine().getStatusCode(), response.getStatusLine()
.getReasonPhrase());
LOG.debug("Status code: " + wsData.getStatusCode());
LOG.debug("Reason phrase: " + wsData.getReasonPhrase());
LOG.debug("Service name: " + wsData.getServiceName());
LOG.debug("url: " + wsData.getUrl());
LOG.debug("result: " + wsData.getResult());
model.addAttribute("result", wsData);
}
catch (final ClientProtocolException cex)
{
wsData = new WsMonitoringData(nome, url, 500, "ClientProtocolException");
LOG.info("WsMonitoringController---doRequest: ClientProtocolException - Errore nella creazione della response :");
cex.printStackTrace();
}
catch (final IOException e)
{
wsData = new WsMonitoringData(nome, url, 500, "IOException");
LOG.info("WsMonitoringController---doRequest: IOException - Errore nell'esecuzione della GET :");
e.printStackTrace();
}
finally
{
try
{
if (null != response)
{
response.close();
}
}
catch (final IOException e)
{
wsData = new WsMonitoringData(nome, url, 500, "IOException");
LOG.info("WsMonitoringController---doRequest: IOException - Errore nella chiusura della response :");
e.printStackTrace();
}
}
return wsData;
}
public CloseableHttpClient getHttpclient()
{
return httpclient;
}
}
commons-codec-1.9.jar
commons-logging-1.2.jar
fluent-hc-4.5.1.jar
httpclient-4.5.1.jar
httpclient-cache-4.5.1.jar
httpclient-win-4.5.1.jar
httpcore-4.4.3.jar
httpmime-4.5.1.jar
jna-4.1.0.jar
jna-platform-4.1.0.jar
异常的堆栈是:
ERROR [localhost-startStop-1] [DispatcherServlet] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wsMonitoringController' defined in file [C:\coop\hybris-commerce-suite-5.5.0.6\hybris\bin\custom\wsmonitoring\web\webroot\WEB-INF\classes\com\accenture\hybris\wsmonitoring\controllers\WsMonitoringController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.accenture.hybris.wsmonitoring.controllers.WsMonitoringController]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1037)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:983)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5229)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5516)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.accenture.hybris.wsmonitoring.controllers.WsMonitoringController]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1030)
... 29 more
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955)
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
这就是问题所在:
创建文件中定义的名为'WS MonitoringController'的bean时出错...bean实例化失败;嵌套异常是org.springframework.beans.beanInstantiationException:无法实例化bean类[com.accenture.hybris.wsmonitoring.controllers.wsmonitoringController]:构造函数抛出异常;嵌套异常是java.lang.NosuchFieldError:INSTANCE
Spring正在寻找一个名为instance
的字段,但它不在您的类中。检查您的Spring配置文件,并将它们与WSMonitoringController
对齐。
当我试图运行下面的代码时,每次我都得到错误“org.openqa.selenium.timeoutexception:Expected condition failed:waiting for visibility of element Locited by by.xpath”,我不确定xpate会是什么,请有人帮助我为登录应用程序创建自动化测试用例。 Java: HTML:
问题内容: 尝试通过StormSubmitter提交结构时,我得到 我正在使用Spring。 我没有在Spout / Bolt构造函数中初始化HttpClient。相反,它是在prepare()通过螺栓方法从Spring Context中获取的类的构造函数中初始化的 代码的结构如下- SomeBolt.java SomeClient.java AppContext.java 问题答案: 我遇到了类
问题内容: 在我自己滚动之前,是否有io.Pipe的缓冲版本(在标准库中还是在第三方库中)? 上下文:我正在尝试使用该解决方案来解析使用bzip2压缩的JSON数据,以便解压缩和解析是并行进行的,但是发现加速非常小。解析未压缩的数据每百万条记录大约需要22秒。解压缩大量数据大约需要相同的时间。如预期的那样,在单线程上完成它们大约需要44秒。使用上述解决方案大约需要41秒。 io.Pipe的文档说:
问题内容: 作为测试项目,我使用wsdl和jax- ws创建了一个非常简单的WebService。如果客户端作为GlassFish中的Web应用程序部署,则客户端运行得很好,但是如果我直接在Eclipse中启动相同的(WebService-)代码,则会收到以下错误: 经过研究,我发现它与某些版本的库文件有一定关系。所以现在我的问题是,如何才能“修复” Eclipse Java执行以正确运行我的We
错误: 任务“:App:ProcessDebugGoogleServices”执行失败。请通过更新Google-Services插件的版本(关于最新版本的信息可以在这里获得)或更新com.google.android.gms的版本到8.3.0来修复版本冲突。 在应用程序gradle中