With RapidClipse I build a page with three elements. A drop-down field, a XdevTable and a XDevfieldGroup.
The drop-down field is filled by database table content (works fine)
The table should be filled after selecting a value out of drop-down field (works fine)
After selecting a value out of the XDevTable the related row should be editable by the fieldgroup.
After selecting a row in the table I get a null-pointer exeption:
Mai 27, 2019 4:41:19 PM com.vaadin.server.DefaultErrorHandler doDefault
SCHWERWIEGEND:
java.lang.NullPointerException
at
com.xdev.ui.entitycomponent.table.AbstractBeanTable.getSelectedItem(AbstractBeanTable.java:180)
at com.xdev.ui.masterdetail.FieldGroupMasterDetailConnection.lambda$0(FieldGroupMasterDetailConnection.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:200)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:163)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1015)
at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1161)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:571)
at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:735)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:468)
at com.vaadin.ui.AbstractSelect.changeVariables(AbstractSelect.java:547)
at com.vaadin.ui.Table.changeVariables(Table.java:2933)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:616)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:463)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:406)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:273)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:90)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1435)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:380)
at com.xdev.communication.XdevServlet.service(XdevServlet.java:212)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
If I am right, I assume, that there is a leak identifying the item which is selected in the table. But I still did what/how is described in RapidClipse Training. So the connection between table and fieldgroup is done by the property "ConnectedForm" inside the table.
The connection from drop-down field to table is done by following code:
private void comboBox_valueChange(final Property.ValueChangeEvent event) {
try {
Integer varMainClass = 0;
varMainClass = this.comboBox.getSelectedItem().getBean().getId();
Notification.show("Kuck a mole: ", this.comboBox.getSelectedItem().getBean().getGroupName()
, Notification.Type.ERROR_MESSAGE);
final BeanItemContainer<TGroup> mySubClasses = new BeanItemContainer<>(TGroup.class);
mySubClasses.addAll(new TGroupDAO().getAllSubClassByMainClassId(varMainClass));
this.table.setContainerDataSource(mySubClasses);
this.table.setVisibleColumns("id", "groupName");
this.table.setVisible(true);
} catch (final Exception e) {
e.printStackTrace();
final String stackTrace = Throwables.getStackTraceAsString(e);
this.textAreaErr.setValue(stackTrace);
this.textAreaErr.setVisible(true);
Notification.show("Do isch was falsch, Nachricht: ", e.getMessage(), Notification.Type.ERROR_MESSAGE);
}
}
In table event valueChange are just a notification for testing purpose:
private void table_valueChange(final Property.ValueChangeEvent event) {
Notification.show("Kuck a mole: ", this.table.getSelectedItem().getBean().getGroupName()
, Notification.Type.ERROR_MESSAGE);
}
All help would be appreciated
Thanks in advance
I am happy, because I found a solution with a help of my friend!
It was still my fault (as expected :-) ). I used the wrong container type:
I used:
final BeanItemContainer<TGroup> mySubClasses = new BeanItemContainer<>(TGroup.class);
But it was the wrong container!
I should use instead:
final XdevBeanItemContainer<TGroup> mySubClasses = new XdevBeanItemContainer<>(TGroup.class);
After I changed it, everything worked fine.
I also searched in the documentation for a hint how I could prevent this for future, but without success.
Related
I want to dynamically generate image with onClick method to call from page. But no matter how I tried, it goes failed.
My code in the backend class is like:
public class RuleController extends SelectorComposer<Component> {
.......
Image imageTemp = (Image)image.clone();
ZScript script = new ZScript("java","delCondition1("+indexCon1+")");
EventHandler evthdl = new EventHandler(script);
imageTemp.addEventHandler("onClick", evthdl);
........
public void delCondition1(int index){
.........
}
}
but after I Clicked the image on page, errors came out:
org.zkoss.zk.ui.UiException: Sourced file: inline evaluation of: ``delCondition1(0);'' : Command not found: delCondition1( int ) : at Line: 1 : in file: inline evaluation of: ``delCondition1(0);'' : delCondition1 ( 0 )
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.zkoss.lang.Classes.newInstance(Classes.java:76)
at org.zkoss.lang.Exceptions.wrap(Exceptions.java:163)
at org.zkoss.zk.ui.UiException$Aide.wrap(UiException.java:51)
at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:136)
at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:342)
at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:970)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3135)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3089)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1846)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1618)
at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1321)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:611)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:487)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:495)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:479)
at org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:479)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
It seems the onClick triggered java code can't find the method : delCondition1(int), Why? How can I set the method to call?
You should not use zscript in production, this is suitable for prototyping only. See the statement from the ZK team.
If your image is defined in your ZUL file, simply use #Listen("onClick = #yourImageId") annotation on your method.
If your image is generated dynamically, use an EventListener to add the onClick event to your image :
public class RuleController extends SelectorComposer<Component> {
...
Image imageTemp = (Image)image.clone();
EventListener<Event> actionListener = new SerializableEventListener<Event>() {
private static final long serialVersionUID = 1L;
public void onEvent(Event event) throws Exception {
delCondition1(indexCon1);
}
};
imageTemp.addEventListener(Events.ON_CLICK, actionListener);
...
public void delCondition1(int index){
...
}
}
See the documentation.
I keep on getting this error and I'm not sure why. Here is the code. Im not even executing any sql and it's still saying "Cannot close a connection while a transaction is still active"
DataAccess da = new DataAccess();
int param = Integer.parseInt(request.getParameter("geoAreaID"));
try (Connection tempConnection = DataAccess.OpenConnection())
{
tempConnection.rollback();
tempConnection.close();
}
catch (SQLException e)
{
e.printStackTrace();
System.exit(e.getErrorCode());
}
catch (Exception e)
{
e.printStackTrace();
System.exit(2);
}
The DataAccess class has the method to open the connection, here it is.
public static Connection OpenConnection() throws SQLException
{
Properties tempConnectionProperties = new Properties();
tempConnectionProperties.put("user", CONNECTION_USER);
tempConnectionProperties.put("password", CONNECTION_PASSWORD);
Connection tempConnection = DriverManager.getConnection(CONNECTION_STRING, tempConnectionProperties);
tempConnection.setAutoCommit(true);
tempConnection.createStatement().executeUpdate("SET SCHEMA APP");
return tempConnection;
}
this is the full error message
java.sql.SQLException: Cannot close a connection while a transaction is still active.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.ClientConnection.closeResourcesX(Unknown Source)
at org.apache.derby.client.am.ClientConnection.closeX(Unknown Source)
at org.apache.derby.client.am.ClientConnection.close(Unknown Source)
at org.apache.derby.client.net.NetConnection.close(Unknown Source)
at dkaru.servlets.GeographicAreaServlet.doGet(GeographicAreaServlet.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: ERROR 25001: Cannot close a connection while a transaction is still active.
at org.apache.derby.client.am.ClientConnection.checkForTransactionInProgress(Unknown Source)
... 29 more
Setting the auto commit property of the connection worked for me. Code shown below :
conn.setAutoCommit(true);
The code below is returning an EmptyFileException, despite the fact that the file is not empty(as can be seen in the output):
public class RecordImpl {
private AssociateImpl associate;
public AssociateImpl getAssociate() {
return associate;
}
public void setAssociate(AssociateImpl associate) {
this.associate = associate;
}
public Document createInsertRecord()throws IOException, InvalidFormatException {
String msg = "";
InputStream inputStream = associate.getFileInputStream();
byte[] binaryRep = IOUtils.toByteArray(inputStream);
System.out.println("File length: "+binaryRep.length);
String year = getYear(inputStream, associate.getPosition());
Document newRecord = new Document();
/*remaining code*/
return newRecord;
}
public String getYear(InputStream inputStream, String position)throws IOException, InvalidFormatException {
System.out.println("Inside RecordImpl: getYear()");
//code throws error at the line below
Workbook workbook = WorkbookFactory.create(associate.getFileInputStream());
Sheet sheet = workbook.getSheet(position);
DataFormatter df = new DataFormatter();
Iterator<Row> rowIterator = sheet.iterator();
String year = "";
/*remaining code*/
return year;
}
}
The length of the byte array is shown to be 21787, showing that the input stream is not empty. And yet the empty file error gets thrown. The output, with the stack trace is shown below:
File length: 21787
Oct 15, 2018 12:11:14 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey Web Application] in context with path [/my-goals] threw exception [org.apache.poi.EmptyFileException: The supplied file was empty (zero bytes long)] with root cause
org.apache.poi.EmptyFileException: The supplied file was empty (zero bytes long)
at org.apache.poi.util.IOUtils.peekFirstNBytes(IOUtils.java:74)
at org.apache.poi.util.IOUtils.peekFirst8Bytes(IOUtils.java:57)
at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:135)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:177)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
at com.cerner.model.impl.RecordImpl.getYear(RecordImpl.java:64)
at com.cerner.model.impl.RecordImpl.createInsertRecord(RecordImpl.java:42)
at com.cerner.model.impl.ActionImpl.insertNewRecord(ActionImpl.java:71)
at com.cerner.model.impl.ActionImpl.performAction(ActionImpl.java:43)
at com.cerner.my_goals.GoalResource.uploadFile(GoalResource.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:143)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:160)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:203)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:97)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:303)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:286)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1072)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:399)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
The file being passed is definitely a non-empty XLSX file. Any ideas as to what the problem could be?
I think with your call:
byte[] binaryRep = IOUtils.toByteArray(inputStream);
the inputStream will move to the end of the stream, so that the remaining bytes are 0.
I am developing a Spring MVC + Apache Oltu + Instagram example. In this example I created an App on https://www.instagram.com/developer/ and I got the ClientId and Client_Secrete.
Uisng this clientId and Client Secret, calling the Instagram Rest EndPoints. But when calling either the REST EndPoint I am getting the below error:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/apache-oltu] threw exception [Request processing failed; nested exception is OAuthProblemException{error='invalid_request', description='Missing parameters: access_token', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}] with root cause
OAuthProblemException{error='invalid_request', description='Missing parameters: access_token', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}
at org.apache.oltu.oauth2.common.exception.OAuthProblemException.error(OAuthProblemException.java:59)
at org.apache.oltu.oauth2.common.utils.OAuthUtils.handleOAuthProblemException(OAuthUtils.java:167)
at org.apache.oltu.oauth2.common.utils.OAuthUtils.handleMissingParameters(OAuthUtils.java:185)
at org.apache.oltu.oauth2.client.validator.OAuthClientValidator.validateRequiredParameters(OAuthClientValidator.java:90)
at org.apache.oltu.oauth2.client.validator.OAuthClientValidator.validateParameters(OAuthClientValidator.java:53)
at org.apache.oltu.oauth2.client.validator.OAuthClientValidator.validate(OAuthClientValidator.java:49)
at org.apache.oltu.oauth2.client.response.OAuthClientResponse.validate(OAuthClientResponse.java:127)
at org.apache.oltu.oauth2.client.response.OAuthClientResponse.init(OAuthClientResponse.java:96)
at org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse.init(OAuthAccessTokenResponse.java:65)
at org.apache.oltu.oauth2.client.response.OAuthClientResponse.init(OAuthClientResponse.java:101)
at org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse.init(OAuthAccessTokenResponse.java:60)
at org.apache.oltu.oauth2.client.response.OAuthClientResponse.init(OAuthClientResponse.java:120)
at org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory.createCustomResponse(OAuthClientResponseFactory.java:82)
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:111)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at com.apache.oltu.InstagramController.getAccessToken(InstagramController.java:76)
at com.apache.oltu.InstagramController.redirect(InstagramController.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Following are the details I used:
AUTHORIZATION_URL = "https://api.instagram.com/oauth/authorize";
ACCESS_TOKEN_URL = "https://api.instagram.com/oauth/access_token";
The scopes which I used are:
public_content follower_list comments relationships likes basic
When code is executing, I am getting the authorizationCode successfully, but looks like token is missing.
I am calling the Rest Endpoint from URL: https://www.instagram.com/developer/endpoints/users/
The code which I used below for reference:
private String getAccessToken(String authorizationCode) throws OAuthSystemException, OAuthProblemException {
OAuthClientRequest request = OAuthClientRequest
.tokenLocation(ACCESS_TOKEN_URL)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setRedirectURI(REDIRECT_URL)
.setCode(authorizationCode)
.buildQueryMessage();
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request, GitHubTokenResponse.class);
request= new OAuthBearerClientRequest("https://api.instagram.com/v1/users/self/").
setAccessToken(oAuthResponse.getAccessToken()).
buildQueryMessage();
System.out.println("REQUEST_BODY : "+request.getBody());
OAuthClient client = new OAuthClient(new URLConnectionClient());
OAuthResourceResponse resourceResponse= client.resource(request, "GET", OAuthResourceResponse.class);
if (resourceResponse.getResponseCode()==200){
logger.debug("HTTP OK");
System.out.println(resourceResponse.getBody());
return resourceResponse.getBody();
}
else{
System.out.println("Could not access resource: " + resourceResponse.getResponseCode()
+ " " + resourceResponse.getBody());
return null;
}
}
}
The following is the URL which is going ::
https://api.instagram.com/oauth/authorize?
scope=public_content+follower_list+comments+relationships+likes+basic&
response_type=code&
redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapache-oltu%2Finstagram%2Fredirect&
client_id=40eb3e6047a249ddb7d9194765be9901
If I used ResponseType="token" then I get the
{"error_type": "OAuthForbiddenException", "code": 403, "error_message": "Implicit authentication is disabled"}
After lots of trial and error method, I was able to resolve this issue:
While making request for the access token I should be using the below:
OAuthClientRequest request = OAuthClientRequest
.authorizationLocation(AUTHORIZATION_URL)
.setClientId(CLIENT_ID)
.setRedirectURI(REDIRECT_URL)
.setResponseType(ResponseType.CODE.toString())
.setScope("public_content follower_list comments relationships likes basic")
.buildQueryMessage();
and with the subsequent request I will be using the below:
OAuthClientRequest request = OAuthClientRequest
//.authorizationProvider(OAuthProviderType.INSTAGRAM)
.tokenLocation(ACCESS_TOKEN_URL)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setRedirectURI(REDIRECT_URL)
.setCode(authorizationCode)
.buildBodyMessage();
and this gives me the solid Response:
{"data": {"id": "3159574895", "username": "Raj", "profile_picture": "https://scontent.cdninstagram.com/t51.2885-19/s150x150/19367511_329283184160313_6318737005198966784_a.jpg", "full_name": "Raj", "bio": "Wish me on 25th-Dec\nLove to code !! \nEngineer by my choice !!\nLove to drive !! \ud83d\ude0b\ud83d\ude0a", "website": "", "is_business": false, "counts": {"media": 14, "follows": 18, "followed_by": 51}}, "meta": {"code": 200}}
After more google found : OAuthProblem, missing parameter access_token
I am following this tutorial, just that I changed the connection to UCanAccess.
I imported all jars, but I am still getting an error, I have no idea what is the problem
The Error
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 invalid page number 1
at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:264)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at servlets.ConnectionManager.getConnection(ConnectionManager.java:22)
at servlets.UserDAO.login(UserDAO.java:35)
at servlets.LoginServlet.doGet(LoginServlet.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
And the Code
package servlets;
import java.sql.*;
public class ConnectionManager {
static Connection conn;
static String url;
public static Connection getConnection()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String url="jdbc:ucanaccess://C:/workspaceWeb/LoginExample/src/servlets/usersetup.db";
System.out.println("blabla");
conn = DriverManager.getConnection(url,"UserName", "PassWord");
System.out.println("commecla");
}
catch (SQLException | ClassNotFoundException ex)
{
ex.printStackTrace();
}
return conn;
}
}
You are trying to open a SQLite database with UCanAccess, and that won't work. UCanAccess can only open Access databases (.accdb, .mdb, or related). To work with a SQLite database you will need to use something like Xerial's SQLite JDBC Driver.