Hot questions for Using GlassFish in web services

Top Java Programmings / GlassFish / web services

Question:

I've been working on a web-service that returns an arraylist. How can I add the returning arraylist to jtable and display?

    ArrayList customerDetails = new ArrayList();
    try {
        String sqlQuery = "SELECT * FROM customer WHERE AccountNumber="+accountNumber;
        PreparedStatement stmt = DatabaseConnection.dBconn().prepareStatement(sqlQuery);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {

            customerDetails.add(rs.getString("Name"));
            customerDetails.add(rs.getString("DoB"));
            customerDetails.add(rs.getString("Address"));
            customerDetails.add(rs.getString("Mobile"));
            customerDetails.add(rs.getString("Email"));
            customerDetails.add(rs.getString("AccountType"));
            customerDetails.add(rs.getString("AccountNumber"));
            customerDetails.add(rs.getString("SortCode"));
            customerDetails.add(rs.getString("Balance"));
            customerDetails.add(rs.getString("Card"));

        }
        return customerDetails;

    } catch (SQLException err) {
        System.out.println(err.getMessage());
    }
    return customerDetails;

Answer:

Let's start with the fact that your ArrayList is not structured as a row/columns grouping, you will need a List within a List, where the outer list is the rows and the inner list are the column values

While we're at it, let's also make use of the PreparedStatement properly and manage the resources so they are closed properly while we're at it

ArrayList<List<String>> customerDetails = new ArrayList<>(25);
String sqlQuery = "SELECT * FROM customer WHERE AccountNumber=?";
try (PreparedStatement stmt = DatabaseConnection.dBconn().prepareStatement(sqlQuery)) {
    stmt.setString(1, accountNumber);
    try (ResultSet rs = stmt.executeQuery()) {

        while (rs.next()) {
            List<String> rowDetails = new ArrayList<>(10);
            rowDetails.add(rs.getString("Name"));
            rowDetails.add(rs.getString("DoB"));
            rowDetails.add(rs.getString("Address"));
            rowDetails.add(rs.getString("Mobile"));
            rowDetails.add(rs.getString("Email"));
            rowDetails.add(rs.getString("AccountType"));
            rowDetails.add(rs.getString("AccountNumber"));
            rowDetails.add(rs.getString("SortCode"));
            rowDetails.add(rs.getString("Balance"));
            rowDetails.add(rs.getString("Card"));

            customerDetails.add(rowDetails);
        }
    }

} catch (SQLException err) {
    System.out.println(err.getMessage());
}
return customerDetails;

Have a look at Using Prepared Statements and The try-with-resources Statement for more details

Now, we need a TableModel which can support it, at very basic level...

public class ListTableModel extends AbstractTableModel {

    private List<List<String>> rows;
    private List<String> columnNames;

    public ListTableModel(List<String> columnNames, List<List<String>> rows) {
        this.rows = new ArrayList<>(rows);
        this.columnNames = columnNames;
    }

    @Override
    public int getRowCount() {
        return rows.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.size();
    }

    @Override
    public String getColumnName(int column) {
        return columnNames.get(column);
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        Class type = String.class;
        return type;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        List<String> rowData = rows.get(rowIndex);
        return rowData.get(columnIndex);
    }
}

This takes a List for the column names and a List<List> for the row data.

Personally, I'd prefer to wrap the data into some kind of Plain Old Java Object (POJO) as it encapsulates the data and provides greater flexibility when displaying it (ie, I need to display all the properties of the object if I don't want to)

Take a look at How to Use Tables for more details

Question:

I developed a Java EE 7 application, that uses Glassfish as the application server and MySQL as the database.

locally every thing is working correctly

now, I want to deploy the application to the cloud using AWS.

after reading some official documentations:

I created The database in the cloud 'AWS RDS', and conneted to it from MySQL Workbench and also The application in my workspace was able to connect to it and act on it.

Now for The application deployment I used Elastic Beanstalk with Glassfish 4.1 Java 8 (the docker one).

The probleme is that I need to configure Glassfish In AWS to

  1. Create JDBC Connection Pool
  2. Create JDBC Resource
  3. Create A Security Realm

so that the apllication can work correctly.

How Can I do This?


Answer:

I switch to Jelastic, I can access admin page usign their cloud, and I already deployed my appication

Question:

I am currently working on upgrading an application from Java7 running on Glassfish 3.1.2.2, to Java8 running on Glassfish 4.1. The application is packaged as an ear-file, containing an ejb-jar, and a war. The war in turn contains some webservices.

In Glassfish 3.1.2.2, deploying the ear will lead to the war exposing a number of webservices. But, when I deploy the ear in Glassfish 4.1, no webservice are exposed. When listing the components for the ear in Glassfish, the war does not list webservices (only web) in 4.1 (but does in 3.1.2.2).

I have tried deploying the war-file as a standalone application, and when doing this the webservices becomes available.

Does anyone know if there is a known bug with regards to deploying webservices through an ear-file with Glassfish 4.1?

When it comes to changes, I have upgraded some dependencies, but as far as I know there is nothing that should affect this.

My application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
    "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
    "http://java.sun.com/dtd/application_1_3.dtd">
<application>
  <display-name>myApplication-ear</display-name>
  <description>myApplication</description>
  <module>
    <ejb>myApplication-ejb-5.2-SNAPSHOT.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>myApplication-war-5.2-SNAPSHOT.war</web-uri>
      <context-root>/myApplication-war</context-root>
    </web>
  </module>
</application>

Answer:

The problem was an old dependency:

  <dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.2.7</version>
  </dependency>

I removed it because it is already included in rt.jar in the java installation. Somehow Glassfish didn't handle this at all, the webservices simply didn't work and no traces of error in the server.log

Question:

I have a JAX-RS Rest Service. I then call this service in Netbeans. I'm using genson-1.0. I call the service like this:

    ArrayList<Appointment> appointments;
    AppointmentRRSClient client = new AppointmentRRSClient();        
    Object response = client.allAppointments(Appointment.class); 

My JSON Array

[{"id":1,"date":"2014-09-19","patient_id":1,"patient_name":"Lorenzana, Jerome Keith G.","patient_mobile":"+639178374407","staff_id":1,"staff_name":"Tugado, John Ephraim G.","location":"Makati Health Center","type":"walk-in","remarks":"okay lang"},{"id":2,"date":"2014-09-19","patient_id":2,"patient_name":"Black, Gucci G.","patient_mobile":"+639178488120","staff_id":1,"staff_name":"Tugado, John Ephraim G.","location":"Makati Health Center","type":"walk-in","remarks":"okay lang"},{"id":3,"date":"2014-09-19","patient_id":3,"patient_name":"Sagucio, Matthew V.","patient_mobile":"+6391068753242","staff_id":1,"staff_name":"Tugado, John Ephraim G.","location":"Makati Health Center","type":"walk-in","remarks":"okay lang"},{"id":4,"date":"2014-09-19","patient_id":4,"patient_name":"Lizardo, Daniel Z.","patient_mobile":"+639175606349","staff_id":1,"staff_name":"Tugado, John Ephraim G.","location":"Makati Health Center","type":"walk-in","remarks":"okay lang"},{"id":5,"date":"2014-09-19","patient_id":5,"patient_name":"Abulencia, Chester X.","patient_mobile":"+639051200480","staff_id":1,"staff_name":"Tugado, John Ephraim G.","location":"Makati Health Center","type":"walk-in","remarks":"okay lang"}]
Error

Exception in thread "main" javax.ws.rs.WebApplicationException: HTTP 500 Internal Server Error at com.owlike.genson.ext.jaxrs.GensonJsonConverter.readFrom(GensonJsonConverter.java:127) at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:188) at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:134) at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:988) at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:833) at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:768) at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:96) at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:740) at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:88) at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:650) 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:228) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:421) at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:646) at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:375) at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:275) at myPackage.AppointmentRRSClient.allAppointments(AppointmentRRSClient.java:39) at mPackage.AppointmentRRSClientTest.main(AppointmentRRSClientTest.java:25) Caused by: com.owlike.genson.JsonBindingException: Could not deserialize to type class myPackage.Appointment at com.owlike.genson.Genson.deserialize(Genson.java:391) at com.owlike.genson.ext.jaxrs.GensonJsonConverter.readFrom(GensonJsonConverter.java:125) ... 18 more Caused by: com.owlike.genson.stream.JsonStreamException: Illegal character at row 0 and column 0 expected { but read '[' ! at com.owlike.genson.stream.JsonReader.newWrongTokenException(JsonReader.java:949) at com.owlike.genson.stream.JsonReader.begin(JsonReader.java:425) at com.owlike.genson.stream.JsonReader.beginObject(JsonReader.java:157) at com.owlike.genson.reflect.BeanDescriptor._deserWithCtrArgs(BeanDescriptor.java:120) at com.owlike.genson.reflect.BeanDescriptor.deserialize(BeanDescriptor.java:95) at com.owlike.genson.convert.BeanViewConverter.deserialize(BeanViewConverter.java:102) at com.owlike.genson.convert.NullConverter$NullConverterWrapper.deserialize(NullConverter.java:56) at com.owlike.genson.Genson.deserialize(Genson.java:389) ... 19 more Java Result: 1 BUILD SUCCESSFUL (total time: 1 second)

Is my JSON in a bad format?

Illegal character at row 0 and column 0 expected { but read '['

When I fetch single data things work fine.

{"username":null,"password":null,"staff_id":1,"staff_name":"Tugado, John Ephraim G.","staff_gender":"male","staff_position_id":1,"health_center_id":1,"health_center_name":"Makati Health Center","account_type":"administrator","account_id":1,"staff_position":"Doctor"}

Thanks in advance!

EDIT:

The AppointmentRRSClient has this method to get the json data and parse it as list of object of type Appointments.

public <T> T allAppointments(Class<T> responseType) throws ClientErrorException {
        WebTarget resource = webTarget;
        resource = resource.path("allAppointments");
        return resource.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).get(responseType);
    }

Solution

I used Gson. Now I call the service like this.

List<String> names = new ArrayList<String>();

        URL url = new URL("http://my-url.com/rest/name");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");

        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(
            (conn.getInputStream())));
                String response = "";
        String output;
        while ((output = br.readLine()) != null) {
            response += output;
        }
                conn.disconnect();
               // System.out.println(response);
        Gson gson = new Gson();
                TypeToken<List<String>> token = new TypeToken<List<String>>(){};
                names = gson.fromJson(response, token.getType());

Answer:

Your json contains an array of apointments but you are deserializing to an appointment object. The solution with substring maybe works for this case, but it is not clean nor stable (what happens if you want to deserialize a list that has more than one element - you get the first one...), you shouldn't do it this way.

The clean solution would be to change the method signature from:

public <T> T allAppointments(Class<T> responseType)

to

public <T> T allAppointments(GenericType<T> responseType) {
  WebTarget resource = webTarget;
  resource = resource.path("allAppointments");
  return resource.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).get(responseType);
}

And then you call it this way:

AppointmentRRSClient client = new AppointmentRRSClient();        
List<Appointment> response = client.allAppointments(new GenericType<List<Appointment>>(){}); 

Remark GenericType is not the one from Genson but from Jersey: javax.ws.rs.core.GenericType

Question:

I am using glassfish server and trying to deploy a test web service. The following doesn't work if I use the @WebService annotation. But I would need to use that annotation to define it as a web service. Otherwise it just comes out as web when I check under the server manager.

Once the error appears, error never goes off even if I remove the annotation. I will have to totally remove my class from the server list and add it again for it to work (work without @WebService annotation). Am I missing out on some settings?

Web service Java code

import javax.jws.WebService;

@WebService //able to deploy if I remove this annotation.
public class ProductCatalogue {

    public List<String> getProductCategories(){
        List<String> categories = new ArrayList<>(); 
        categories.add("Books");
        categories.add("Music");
        categories.add("Movies");
        return categories;
    }
}    

Error

'Publishing to GlassFish 4 at localhost [domain 1]...' has encountered a problem.

Cannot Deploy Classname

Stacktrace

    2016-05-14T15:05:08.120+0100|Info: visiting unvisited references
2016-05-14T15:05:08.139+0100|Info: visiting unvisited references
2016-05-14T15:05:08.140+0100|Severe: WS00029: The javax.jws.WebService annotation targetNamespace must be used for classes or interfaces that are in no package.
2016-05-14T15:05:08.141+0100|Severe: Annotations processing failed for file:/D:/Downloads/glassfish-4.1.1/glassfish4/glassfish/domains/domain1/eclipseApps/WebServiceTester/
2016-05-14T15:05:08.142+0100|Info: visiting unvisited references
2016-05-14T15:05:08.182+0100|Info: Webservice Endpoint deployed ProductCatalogue
 listening at address at http://K:8080/WebServiceTester/ProductCatalogueService.
2016-05-14T15:05:08.182+0100|Severe: Exception while invoking class org.glassfish.webservices.WebServicesDeployer prepare method
2016-05-14T15:05:08.183+0100|Severe: java.lang.RuntimeException
    at org.glassfish.webservices.WebServicesDeployer.prepare(WebServicesDeployer.java:185)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
    at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
    at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at org.glassfish.webservices.deployment.DeployedEndpointData.<init>(DeployedEndpointData.java:118)
    at org.glassfish.webservices.deployment.WebServicesDeploymentMBean.deploy(WebServicesDeploymentMBean.java:272)
    at org.glassfish.webservices.deployment.WebServicesDeploymentMBean.deploy(WebServicesDeploymentMBean.java:301)
    at org.glassfish.webservices.WebServicesDeployer.prepare(WebServicesDeployer.java:182)
    ... 40 more
2016-05-14T15:05:08.183+0100|Severe: Exception while preparing the app
2016-05-14T15:05:08.183+0100|Severe: Exception during lifecycle processing
java.lang.RuntimeException
    at org.glassfish.webservices.WebServicesDeployer.prepare(WebServicesDeployer.java:185)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
    at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
    at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at org.glassfish.webservices.deployment.DeployedEndpointData.<init>(DeployedEndpointData.java:118)
    at org.glassfish.webservices.deployment.WebServicesDeploymentMBean.deploy(WebServicesDeploymentMBean.java:272)
    at org.glassfish.webservices.deployment.WebServicesDeploymentMBean.deploy(WebServicesDeploymentMBean.java:301)
    at org.glassfish.webservices.WebServicesDeployer.prepare(WebServicesDeployer.java:182)
    ... 40 more

2016-05-14T15:05:08.190+0100|Severe: Exception while preparing the app
java.lang.NullPointerException
    at org.glassfish.webservices.deployment.DeployedEndpointData.<init>(DeployedEndpointData.java:118)
    at org.glassfish.webservices.deployment.WebServicesDeploymentMBean.deploy(WebServicesDeploymentMBean.java:272)
    at org.glassfish.webservices.deployment.WebServicesDeploymentMBean.deploy(WebServicesDeploymentMBean.java:301)
    at org.glassfish.webservices.WebServicesDeployer.prepare(WebServicesDeployer.java:182)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
    at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
    at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
    at java.lang.Thread.run(Thread.java:745)

Answer:

If you see the below stack trace it tells you to specify the targetNamespace if the webservice class doesn't have a specified package. So you can either create a package and include the ProductCatalogue in it or specify the targetNamespace in @WebService annotation as @WebService(targetNamespace = "http://www.something.com")

The javax.jws.WebService annotation targetNamespace must be used for classes or interfaces that are in no package.

Question:

Hello I'm trying to run a query in my webservice, but a function that a query is within breaks from nothing.

My code:

public boolean excluir(String usuario)
{
String sql = "DELETE * FROM listaproduto where uclogin=?";
Boolean retorno = false;
PreparedStatement pst = Conexao.getPreparedStatement(sql);
try {
    pst.setString(1, usuario); //He breaks that part.
    if(pst.executeUpdate()>0)
    {
        retorno = true;
    }
} catch (SQLException ex) {
    Logger.getLogger(ProdutoDAO.class.getName()).log(Level.SEVERE, null, ex);
    retorno = false;
}
return retorno;
} 

Error:

GET SolicitaĆ§Ć£oFailed RequestFailed --> Status: (500) Resposta: { HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NullPointerException

root cause

java.lang.NullPointerException

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs. GlassFish Server Open Source Edition 4.1.1


Answer:

String sql = "DELETE FROM listaproduto where uclogin=?";

Delete your '' and then, try it again.. I think that delete method does not need ''.. Hope this can help you :)

Question:

What is the easiest way to either configure Axis2 or extend the message listener to PREVENT any and all information regarding system from returning to the calling client?

An example of what I'm trying to prevent is as follows: Someone sends an improper soap request with some weird stuff in the header and the server responds:

HTTP/1.1 500 Internal Server Error
Date: Wed, 19 Nov 2014 13:12:34 GMT
Server: Apache
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
Connection: close
Content-Length: 465
Content-Type: text/xml;charset=utf-8
... 
<faultstring>javax.xml.stream.XMLStreamException: DOCTYPE is not allowed</faultstring>

What is the best way to prevent all of that information from being delivered back to the client? The glassfish messages can be turned off in GlassFish as answered below. I should have been more specific I want to set it up so that any and all exceptions never reach the client. I want to somehow force axis2 to use a generic message instead of returning an Exception. Is it possible to do this with Axis2?


Answer:

You can add a

-Dproduct.name="".

in your JVM Option for suppressing the X-Powered-By

Question:

I am trying to create a sample web service by using the following link: https://metro.java.net/guide/ch02.html#using_metro-developing_with_nb

I have followed all the steps mentioned in the above link and deployed my application successfully. But when I run my application its showing "HTTP Status 404 - Not Found" error on the browser without showing any logs in the server console.

I am using GlassFish 4.0 and Netbeans 7.4 In the tutorial, they have asked us to use either GlassFish V2 or V3. Am I getting the above error because of using GlassFish 4.0?

Or am I missing anything here? How to get rid of 404 error?


Answer:

got it!! In the Metro User Guide, Relative URL field is given as /CalculatorWSService?wsdl but it should be /CalculatorWS?wsdl. Hence, the issue is resolved :)