// Java Client for GeoNames Webservices private String getPhysicalPlaceOnGeonames(double lat, double lng) { String sPlaceName = ""; String sGeoNameId = ""; String hostname = "www.geonames.org"; try { Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 " + hostname); int returnVal = p1.waitFor(); boolean reachable = (returnVal == 0); if (reachable) { WebService.setUserName("betaas"); PostalCodeSearchCriteria postalCodeSearchCriteria = new PostalCodeSearchCriteria(); postalCodeSearchCriteria.setLatitude(lat); postalCodeSearchCriteria.setLongitude(lng); List<Toponym> placeNames = WebService.findNearbyPlaceName(lat, lng); for (int i = 0; i < placeNames.size(); i++) { sGeoNameId = String.valueOf(placeNames.get(i).getGeoNameId()); sPlaceName = "<" + PREFIX_GEONAMES + sGeoNameId + ">"; } } // else // mLogger.info("[CM] Adaptation Context Manager, Geonames function. Service " + // hostname + " unavailable."); } catch (Exception e) { // mLogger // .error("[CM] Adaptation Context Manager, Geonames function. It has not been // executed correctly. Probably there is not Internet connection."); } return sPlaceName; }
public List<Filme> doService() { List<Filme> encontrados = new ArrayList<Filme>(); try { WebService ws = new WebService(); JSONArray response = ws.getJson("https://api.myjson.com/bins/33yhd", "Os Filmes mais Esperados"); for (int i = 0; i < response.length(); i++) { JSONObject obj = response.getJSONObject(i); Filme filme = new Filme(); filme.setNome(obj.getString("nome")); filme.setDiretor(obj.getString("diretor")); filme.setAtores(obj.getString("atores")); filme.setLancamento(obj.getString("lancamento")); filme.setNacionalidade(obj.getString("nacionalidade")); filme.setGenero(obj.getString("genero")); filme.setImage(obj.getString("img")); encontrados.add(filme); } } catch (Exception e) { System.out.print(e.getMessage()); } return encontrados; }
@Override protected Integer doInBackground(String... urls) { WebService ws = new WebService(); serverId = 0; phrase = Constants.Phrase; String dec = AppConfig.GetDec(context); flag = false; List<InvoiceProduct> invoiceProducts = InvoiceProduct.GetAllInvoiceProductByFK_invoiceId(context, invoice.getInvoiceId()); String itemsString = CommandHandler.EncodeCommand.InvoiceProduct(invoiceProducts); res = ws.SubmitInvoice( AppConfig.GetUserId(context), String.valueOf(invoice.getInvoiceId()), invoice.getAddress(), itemsString, dec, phrase); flag = CommandHandler.CommandValidation(res); if (flag) { res = CommandHandler.GetCommand(res); return CommandHandler.errorType_NoError; } else return CommandHandler.errorType_ServerAccess; }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(LogTags.WS_TAG, "sending positions ..."); final ConnectionSetting connectionSetting = createConnectionSetting(intent); final WebService webService = new WebService(connectionSetting); final List<Position> positions = positionCache.getCachedPositions(); for (final Position position : positions) { Log.d(LogTags.WS_TAG, "send " + position); final boolean success = webService.send(position.toParamMap()); if (success) { Log.d(LogTags.WS_TAG, "remove " + position); positionCache.removePostion(position); } } Log.d(LogTags.WS_TAG, "... sending positions finished"); return super.onStartCommand(intent, flags, startId); }
public List<Cinema> doService() { List<Cinema> encontrados = new ArrayList<Cinema>(); try { WebService ws = new WebService(); JSONArray response = ws.getJson("https://api.myjson.com/bins/4135h", "cinemas"); for (int i = 0; i < response.length(); i++) { JSONObject obj = response.getJSONObject(i); Cinema cinema = new Cinema(); cinema.setNome(obj.getString("nome")); cinema.setLat(obj.getDouble("lat")); cinema.setLongi(obj.getDouble("long")); encontrados.add(cinema); } } catch (Exception e) { System.out.print(e.getMessage()); } return encontrados; }
public List<Person> getData(String url, Aplication dtoFactory, String type) throws SQLException { Dao<Person, Integer> person = dtoFactory.getContatoDao(); ArrayList<Person> representative = new ArrayList<Person>(); mainfeed = new WebService(url); Map<String, String> params = new HashMap<String, String>(); String response = mainfeed.webGet("", params); JSONObject json; try { json = new JSONObject(response.toString()); JSONArray venues = json.getJSONArray("results"); JSONObject JSONObj; Person r; GsonBuilder gsonb = new GsonBuilder(); Gson gson = gsonb.create(); for (int i = 0; i < venues.length(); i++) { JSONObj = (JSONObject) venues.get(i); r = gson.fromJson(JSONObj.toString(), Person.class); r.setType(type); representative.add(r); person.create(r); } } catch (JSONException e) { e.printStackTrace(); } return representative; }
public static void main(String[] args) throws ClassNotFoundException { String username = "******"; // Ändra username här // Ändra Auth tillhörande ditt spotify-account String OAuthToken = "BQB3W-ODBi1wq3gQWYwByWrRzshSd_LxRDBWBmI9L1VIh9MVGJeDm9vDYib2T1aebBiR9ghPbqqU8aI9oyeI3PWR-sggQtNfOjjNNXA3bo9AQxlIb3zNVJ24ZcmXGrPQ6pp3epObUrxC9lLohP39w-B8TQlGunisPxiwQrg9C-2K_K_dC5-3Dq9-wgdohH61RzXv32zwiNjNLcmrVFdARzgjNjFdY2Wo1Jiu"; WebService ws = new WebService(); JsonReader jr = new JsonReader(OAuthToken); setPort(8081); get( "/trip", (req, res) -> { System.out.println("-- Trip called --"); res.header("Access-Control-Allow-Origin", "*"); String from = req.queryParams("from"); String to = req.queryParams("to"); String key = "4651be79-347f-45e5-8eac-2062d752068c"; ArrayList<Trip> trips = jr.getTrips( "https://api.resrobot.se/trip?key=" + key + "&originId=" + from + "&destId=" + to + "&format=json"); System.out.println(ws.buildJsonObject(trips)); return ws.buildJsonObject(trips); }); get( "/location", (req, res) -> { System.out.println("-- Station called --"); res.header("Access-Control-Allow-Origin", "*"); String name = req.queryParams("name"); String key = "4651be79-347f-45e5-8eac-2062d752068c"; return jr.getLocations( "https://api.resrobot.se/location.name.json?key=" + key + "&input=" + name); }); get( "/trip/playlist", (req, res) -> { res.header("Access-Control-Allow-Origin", "*"); String from = req.queryParams("from"); String to = req.queryParams("to"); String x = req.queryParams("id"); int identi = Integer.parseInt(x); String key = "4651be79-347f-45e5-8eac-2062d752068c"; ArrayList<Trip> trips = jr.getSpotifyTrips( "https://api.resrobot.se/trip?key=" + key + "&originId=" + from + "&destId=" + to + "&format=json"); JSONObject jsonPlaylist = jr.createPlaylist( "https://api.spotify.com/v1/users/" + username + "/playlists", "Spellista " + x); String url = ""; for (Trip trip : trips) { if (Integer.parseInt(trip.getId()) == identi) { for (Track track : trip.getTracks()) { if (url.length() < 1) { url += track.getUrl(); } else { url += "," + track.getUrl(); } } } } String playlistID = jsonPlaylist.getString("id"); jr.addTracks( "https://api.spotify.com/v1/users/" + username + "/playlists/" + playlistID + "/tracks?uris=" + url); return jsonPlaylist.getJSONObject("external_urls").getString("spotify"); }); get( "/playlist", (req, res) -> { res.header("Access-Control-Allow-Origin", "*"); String x = req.queryParams("ms"); String playlistName = req.queryParams("name"); int duration = Integer.parseInt(x); ArrayList<Track> tracks = jr.getSpotifyTracks(duration); JSONObject jsonPlaylist = jr.createPlaylist( "https://api.spotify.com/v1/users/" + username + "/playlists", playlistName); String url = ""; for (Track track : tracks) { if (url.length() < 1) { url += track.getUrl(); } else { url += "," + track.getUrl(); } } String playlistID = jsonPlaylist.getString("id"); jr.addTracks( "https://api.spotify.com/v1/users/" + username + "/playlists/" + playlistID + "/tracks?uris=" + url); return jsonPlaylist.getJSONObject("external_urls").getString("spotify"); }); }
@Override public void onCreate(Bundle savedInstanceState) { try { // Need to call the superclass constructor first super.onCreate(savedInstanceState); setContentView(R.layout.weatherlayout); application = (TheLuvExchange) this.getApplication(); user = application.getUser(); city = application.getCity(); // // Set Header to selected city name // TextView cityName = (TextView)findViewById(R.id.header); // cityName.setText(city.getName()); weatherO = (WebService.getWeather(city)); setText(city.getName(), R.id.header); setText(city.getName() + " Weather", R.id.CityWeatherTitle); // Left Side Temp setText( " " + weatherO.getWeatherCurrentCondition().getTempF() + (char) 0x00B0 + "F", R.id.CurrentTemperature); // Right Side Temp setText( " " + weatherO.getWeatherCurrentCondition().getTempF() + (char) 0x00B0 + "F", R.id.textView1); setText( " " + weatherO.getWeatherCurrentCondition().getWindspeedMiles() + "mph", R.id.CurrentWindSpeed); setText(" " + weatherO.getWeatherCurrentCondition().getHumidity() + " %", R.id.TextView07); // Current Weather Condition Below Image setText(weatherO.getWeatherCurrentCondition().getDescription(), R.id.textView2); // Current Weather Image setImage(weatherO.getWeatherCurrentCondition().getIconURL(), R.id.CurrentWeatherImage); // Current Visibility setText(" " + weatherO.getWeatherCurrentCondition().getVisibiltiy() + " mi", R.id.TextView06); int year; int month; int day; GregorianCalendar gregorianCalendar; // create an array of days String[] strDays = new String[] { "Thusday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" }; String strDaysForecast[] = new String[3]; Log.d("Weather", weatherO.getWeatherForecastConditions().get(2).getDate().substring(0, 4)); Log.d("Weather", weatherO.getWeatherForecastConditions().get(2).getDate().substring(5, 7)); Log.d("Weather", weatherO.getWeatherForecastConditions().get(2).getDate().substring(8, 10)); for (int i = 1; i <= 3; i++) { year = Integer.parseInt( weatherO.getWeatherForecastConditions().get(i).getDate().substring(0, 4)); month = Integer.parseInt( weatherO.getWeatherForecastConditions().get(i).getDate().substring(5, 7)); day = Integer.parseInt( weatherO.getWeatherForecastConditions().get(i).getDate().substring(8, 10)); gregorianCalendar = new GregorianCalendar(year, month, day); strDaysForecast[i - 1] = strDays[gregorianCalendar.get(Calendar.DAY_OF_WEEK) - 1]; } // 3 Day Forecast Descriptions setText(strDaysForecast[0], R.id.textViewForecast1); setText(strDaysForecast[1], R.id.textViewForecast2); setText(strDaysForecast[2], R.id.textViewForecast3); setText(weatherO.getWeatherForecastConditions().get(1).getDesc(), R.id.TextView10); setText(weatherO.getWeatherForecastConditions().get(2).getDesc(), R.id.TextView11); setText(weatherO.getWeatherForecastConditions().get(3).getDesc(), R.id.TextView05); setText( weatherO.getWeatherForecastConditions().get(1).getTempMinF() + (char) 0x00B0 + "F" + "/" + weatherO.getWeatherForecastConditions().get(1).getTempMaxF() + (char) 0x00B0 + "F", R.id.TextView12); setText( weatherO.getWeatherForecastConditions().get(2).getTempMinF() + (char) 0x00B0 + "F" + "/" + weatherO.getWeatherForecastConditions().get(2).getTempMaxF() + (char) 0x00B0 + "F", R.id.TextView13); setText( weatherO.getWeatherForecastConditions().get(3).getTempMinF() + (char) 0x00B0 + "F" + "/" + weatherO.getWeatherForecastConditions().get(3).getTempMaxF() + (char) 0x00B0 + "F", R.id.TextView14); /* * Author Notes: Pranav */ // Commented because the weather web service is buggy and doesn't return any images for the // forecasts // setImage(weatherO.getWeatherForecastConditions().get(1).getIconURL(),R.id.ImageView01); // // setImage(weatherO.getWeatherForecastConditions().get(2).getIconURL(),R.id.ImageView02); // // setImage(weatherO.getWeatherForecastConditions().get(3).getIconURL(),R.id.ImageView03); // Following not used // setText(" "+weatherO.getWeatherForecastConditions().get(0).getTempMaxF()+(char) // 0x00B0+"F",R.id.tempMax); // setText(" "+weatherO.getWeatherCurrentCondition().getPrecMM()+" in",R.id.prec); // setText(" "+weatherO.getWeatherForecastConditions().get(0).getTempMinF()+(char) // 0x00B0+"F",R.id.tempMin); this.setVisible(true); } catch (Exception e) { // Catch any errors and display them on LogCat Log.e("TheLuvExchange", "WeatherError", e); } }
public static void main(String args[]) throws Exception { URL wsdlURL = WebService.WSDL_LOCATION; if (args.length > 0) { File wsdlFile = new File(args[0]); try { if (wsdlFile.exists()) { wsdlURL = wsdlFile.toURI().toURL(); } else { wsdlURL = new URL(args[0]); } } catch (MalformedURLException e) { e.printStackTrace(); } } WebService ss = new WebService(wsdlURL, SERVICE_NAME); WebServiceSoap port = ss.getWebServiceSoap12(); { System.out.println("Invoking checkServerHealthV2..."); java.lang.String _checkServerHealthV2_type = ""; net.cbtltd.rest.interhome.CheckServerHealthResultV2 _checkServerHealthV2__return = port.checkServerHealthV2(_checkServerHealthV2_type); System.out.println("checkServerHealthV2.result=" + _checkServerHealthV2__return); } { System.out.println("Invoking cancelBooking..."); net.cbtltd.rest.interhome.CancelBookingInputValue _cancelBooking_inputValue = null; net.cbtltd.rest.interhome.CancelBookingReturnValue _cancelBooking__return = port.cancelBooking(_cancelBooking_inputValue); System.out.println("cancelBooking.result=" + _cancelBooking__return); } { System.out.println("Invoking paymentExtInformation..."); net.cbtltd.rest.interhome.PaymentInformationInputValue _paymentExtInformation_inputValue = null; net.cbtltd.rest.interhome.PaymentInformationReturnValue _paymentExtInformation__return = port.paymentExtInformation(_paymentExtInformation_inputValue); System.out.println("paymentExtInformation.result=" + _paymentExtInformation__return); } { System.out.println("Invoking prices..."); net.cbtltd.rest.interhome.PricesInputValue _prices_inputValue = null; net.cbtltd.rest.interhome.PricesRetunValue _prices__return = port.prices(_prices_inputValue); System.out.println("prices.result=" + _prices__return); } { System.out.println("Invoking newsletter..."); net.cbtltd.rest.interhome.NewsletterInputValue _newsletter_inputValue = null; net.cbtltd.rest.interhome.NewsletterReturnValue _newsletter__return = port.newsletter(_newsletter_inputValue); System.out.println("newsletter.result=" + _newsletter__return); } { System.out.println("Invoking checkBooking..."); net.cbtltd.rest.interhome.CheckBookingInputValue _checkBooking_inputValue = null; net.cbtltd.rest.interhome.CheckBookingReturnValue _checkBooking__return = port.checkBooking(_checkBooking_inputValue); System.out.println("checkBooking.result=" + _checkBooking__return); } { System.out.println("Invoking retailerBooking..."); net.cbtltd.rest.interhome.RetailerBookingInputValue _retailerBooking_inputValue = null; net.cbtltd.rest.interhome.RetailerBookingReturnValue _retailerBooking__return = port.retailerBooking(_retailerBooking_inputValue); System.out.println("retailerBooking.result=" + _retailerBooking__return); } { System.out.println("Invoking nearestBookingDate..."); net.cbtltd.rest.interhome.NearestBookingDateInputValue _nearestBookingDate_inputValue = null; net.cbtltd.rest.interhome.NearestBookingDateReturnValue _nearestBookingDate__return = port.nearestBookingDate(_nearestBookingDate_inputValue); System.out.println("nearestBookingDate.result=" + _nearestBookingDate__return); } { System.out.println("Invoking checkServerHealth..."); net.cbtltd.rest.interhome.CheckServerHealthResult _checkServerHealth__return = port.checkServerHealth(); System.out.println("checkServerHealth.result=" + _checkServerHealth__return); } { System.out.println("Invoking search..."); net.cbtltd.rest.interhome.SearchInputValue _search_inputValue = null; net.cbtltd.rest.interhome.SearchReturnValue _search__return = port.search(_search_inputValue); System.out.println("search.result=" + _search__return); } { System.out.println("Invoking priceDetail..."); net.cbtltd.rest.interhome.PriceDetailInputValue _priceDetail_inputValue = null; net.cbtltd.rest.interhome.PriceDetailRetunValue _priceDetail__return = port.priceDetail(_priceDetail_inputValue); System.out.println("priceDetail.result=" + _priceDetail__return); } { System.out.println("Invoking availability..."); net.cbtltd.rest.interhome.AvailabilityInputValue _availability_inputValue = null; net.cbtltd.rest.interhome.AvailabilityRetunValue _availability__return = port.availability(_availability_inputValue); System.out.println("availability.result=" + _availability__return); } { System.out.println("Invoking accommodationDetail..."); net.cbtltd.rest.interhome.AccommodationDetailInputValue _accommodationDetail_inputValue = null; net.cbtltd.rest.interhome.AccommodationDetailReturnValue _accommodationDetail__return = port.accommodationDetail(_accommodationDetail_inputValue); System.out.println("accommodationDetail.result=" + _accommodationDetail__return); } { System.out.println("Invoking readBooking..."); net.cbtltd.rest.interhome.ReadBookingInputValue _readBooking_inputValue = null; net.cbtltd.rest.interhome.ReadBookingReturnValue _readBooking__return = port.readBooking(_readBooking_inputValue); System.out.println("readBooking.result=" + _readBooking__return); } { System.out.println("Invoking cancellationConditions..."); net.cbtltd.rest.interhome.CancellationConditionInputValue _cancellationConditions_inputValue = null; net.cbtltd.rest.interhome.CancellationConditionReturnValue _cancellationConditions__return = port.cancellationConditions(_cancellationConditions_inputValue); System.out.println("cancellationConditions.result=" + _cancellationConditions__return); } { System.out.println("Invoking ratifyBooking..."); net.cbtltd.rest.interhome.RatifyBookingInputValue _ratifyBooking_inputValue = null; net.cbtltd.rest.interhome.RatifyBookingReturnValue _ratifyBooking__return = port.ratifyBooking(_ratifyBooking_inputValue); System.out.println("ratifyBooking.result=" + _ratifyBooking__return); } { System.out.println("Invoking clientBooking..."); net.cbtltd.rest.interhome.ClientBookingInputValue _clientBooking_inputValue = null; net.cbtltd.rest.interhome.ClientBookingReturnValue _clientBooking__return = port.clientBooking(_clientBooking_inputValue); System.out.println("clientBooking.result=" + _clientBooking__return); } { System.out.println("Invoking additionalServices..."); net.cbtltd.rest.interhome.AdditionalServicesInputValue _additionalServices_inputValue = null; net.cbtltd.rest.interhome.AdditionalServicesReturnValue _additionalServices__return = port.additionalServices(_additionalServices_inputValue); System.out.println("additionalServices.result=" + _additionalServices__return); } { System.out.println("Invoking priceList..."); net.cbtltd.rest.interhome.PriceListInputValue _priceList_inputValue = null; net.cbtltd.rest.interhome.PriceListReturnValue _priceList__return = port.priceList(_priceList_inputValue); System.out.println("priceList.result=" + _priceList__return); } { System.out.println("Invoking trips..."); net.cbtltd.rest.interhome.TripsInputValue _trips_inputValue = null; net.cbtltd.rest.interhome.TripsReturnValue _trips__return = port.trips(_trips_inputValue); System.out.println("trips.result=" + _trips__return); } { System.out.println("Invoking voucherDetail..."); net.cbtltd.rest.interhome.VoucherDetailInputValue _voucherDetail_inputValue = null; net.cbtltd.rest.interhome.VoucherDetailReturnValue _voucherDetail__return = port.voucherDetail(_voucherDetail_inputValue); System.out.println("voucherDetail.result=" + _voucherDetail__return); } { System.out.println("Invoking affiliateDetail..."); net.cbtltd.rest.interhome.AffiliateDetailInputValue _affiliateDetail_inputValue = null; net.cbtltd.rest.interhome.AffiliateDetailReturnValue _affiliateDetail__return = port.affiliateDetail(_affiliateDetail_inputValue); System.out.println("affiliateDetail.result=" + _affiliateDetail__return); } System.exit(0); }
@Override public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo) throws AnnotationProcessorException { AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler(); AnnotatedElement annElem = annInfo.getAnnotatedElement(); AnnotatedElement origAnnElem = annElem; boolean ejbInWar = ignoreWebserviceAnnotations(annElem, annCtx); // Bug http://monaco.sfbay/detail.jsf?cr=6956406 // When there is an ejb webservice packaged in a war // ignore the annotation processing for WebBundleDescriptor // In Ejb webservice in a war there are 2 bundle descriptors // so we should just allow the processing for the EjbBundleDescriptor // and add webservices to that BundleDescriptor if (ejbInWar) { return HandlerProcessingResultImpl.getDefaultResult( getAnnotationType(), ResultType.PROCESSED); } // sanity check if (!(annElem instanceof Class)) { AnnotationProcessorException ape = new AnnotationProcessorException( wsLocalStrings.getLocalString( "enterprise.deployment.annotation.handlers.wrongannotationlocation", "WS00022: symbol annotation can only be specified on TYPE"), annInfo); annInfo.getProcessingContext().getErrorHandler().error(ape); return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED); } // Ignore @WebService annotation on an interface; process only those in an actual service impl // class if (((Class) annElem).isInterface()) { return HandlerProcessingResultImpl.getDefaultResult( getAnnotationType(), ResultType.PROCESSED); } if (isJaxwsRIDeployment(annInfo)) { // Looks like JAX-WS RI specific deployment, do not process Web Service annotations otherwise // would end up as two web service endpoints conLogger.log( Level.INFO, LogUtils.DEPLOYMENT_DISABLED, new Object[] { annInfo.getProcessingContext().getArchive().getName(), "WEB-INF/sun-jaxws.xml" }); return HandlerProcessingResultImpl.getDefaultResult( getAnnotationType(), ResultType.PROCESSED); } // let's get the main annotation of interest. javax.jws.WebService ann = (javax.jws.WebService) annInfo.getAnnotation(); BundleDescriptor bundleDesc = null; // Ensure that an EJB endpoint is packaged in EJBJAR and a servlet endpoint is packaged in a WAR try { /* TODO These conditions will change since ejb in war will be supported //uncomment if needed if(annCtx instanceof EjbContext && (provider !=null) && (provider.getType("javax.ejb.Stateless") == null)) { AnnotationProcessorException ape = new AnnotationProcessorException( localStrings.getLocalString("enterprise.deployment.annotation.handlers.webeppkgwrong", "Class {0} is annotated with @WebService and without @Stateless but is packaged in a JAR." + " If it is supposed to be a servlet endpoint, it should be packaged in a WAR; Deployment will continue assuming this " + "class to be just a POJO used by other classes in the JAR being deployed", new Object[] {((Class)annElem).getName()}),annInfo); ape.setFatal(false); throw ape; } if(annCtx instanceof EjbBundleContext && (provider !=null) && (provider.getType("javax.ejb.Stateless") == null)) { AnnotationProcessorException ape = new AnnotationProcessorException( localStrings.getLocalString ("enterprise.deployment.annotation.handlers.webeppkgwrong", "Class {0} is annotated with @WebService and without @Stateless but is packaged in a JAR." + " If it is supposed to be a servlet endpoint, it should be packaged in a WAR; Deployment will continue assuming this " + "class to be just a POJO used by other classes in the JARbeing deployed", new Object[] {((Class)annElem).getName()}),annInfo); ape.setFatal(false); throw ape; } if(annCtx instanceof WebBundleContext && (provider !=null) && (provider.getType("javax.ejb.Stateless") != null)) { AnnotationProcessorException ape = new AnnotationProcessorException( localStrings.getLocalString ("enterprise.deployment.annotation.handlers.ejbeppkgwrong", "Class {0} is annotated with @WebService and @Stateless but is packaged in a WAR." +" If it is supposed to be an EJB endpoint, it should be packaged in a JAR; Deployment will continue assuming this " +" class to be just a POJO used by other classes in the WAR being deployed", new Object[] {((Class)annElem).getName()}),annInfo); ape.setFatal(false); throw ape; }*/ // let's see the type of web service we are dealing with... if ((ejbProvider != null) && ejbProvider.getType("javax.ejb.Stateless") != null && (annCtx instanceof EjbContext)) { // this is an ejb ! EjbContext ctx = (EjbContext) annCtx; bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor(); bundleDesc.setSpecVersion("3.0"); } else { // this has to be a servlet since there is no @Servlet annotation yet if (annCtx instanceof WebComponentContext) { bundleDesc = ((WebComponentContext) annCtx).getDescriptor().getWebBundleDescriptor(); } else if (!(annCtx instanceof WebBundleContext)) { return getInvalidAnnotatedElementHandlerResult( annInfo.getProcessingContext().getHandler(), annInfo); } bundleDesc = ((WebBundleContext) annCtx).getDescriptor(); bundleDesc.setSpecVersion("2.5"); } } catch (Exception e) { throw new AnnotationProcessorException( wsLocalStrings.getLocalString( "webservice.annotation.exception", "WS00023: Exception in processing @Webservice : {0}", e.getMessage())); } // WebService.name in the impl class identifies port-component-name // If this is specified in impl class, then that takes precedence String portComponentName = ann.name(); // As per JSR181, the serviceName is either specified in the deployment descriptor // or in @WebSErvice annotation in impl class; if neither service name implclass+Service String svcNameFromImplClass = ann.serviceName(); String implClassName = ((Class) annElem).getSimpleName(); String implClassFullName = ((Class) annElem).getName(); // In case user gives targetNameSpace in the Impl class, that has to be used as // the namespace for service, port; typically user will do this in cases where // port_types reside in a different namespace than that of server/port. // Store the targetNameSpace, if any, in the impl class for later use String targetNameSpace = ann.targetNamespace(); // As per JSR181, the portName is either specified in deployment desc or in @WebService // in impl class; if neither, it will @WebService.name+Port; if @WebService.name is not there, // then port name is implClass+Port String portNameFromImplClass = ann.portName(); if ((portNameFromImplClass == null) || (portNameFromImplClass.length() == 0)) { if ((portComponentName != null) && (portComponentName.length() != 0)) { portNameFromImplClass = portComponentName + "Port"; } else { portNameFromImplClass = implClassName + "Port"; } } // Store binding type specified in Impl class String userSpecifiedBinding = null; javax.xml.ws.BindingType bindingAnn = (javax.xml.ws.BindingType) ((Class) annElem).getAnnotation(javax.xml.ws.BindingType.class); if (bindingAnn != null) { userSpecifiedBinding = bindingAnn.value(); } // Store wsdlLocation in the impl class (if any) String wsdlLocation = null; if (ann.wsdlLocation() != null && ann.wsdlLocation().length() != 0) { wsdlLocation = ann.wsdlLocation(); } // At this point, we need to check if the @WebService points to an SEI // with the endpointInterface attribute, if that is the case, the // remaining attributes should be extracted from the SEI instead of SIB. if (ann.endpointInterface() != null && ann.endpointInterface().length() > 0) { Class endpointIntf; try { endpointIntf = ((Class) annElem).getClassLoader().loadClass(ann.endpointInterface()); } catch (java.lang.ClassNotFoundException cfne) { throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.classnotfound", "class {0} referenced from annotation symbol cannot be loaded", new Object[] {ann.endpointInterface()}), annInfo); } annElem = endpointIntf; ann = annElem.getAnnotation(javax.jws.WebService.class); if (ann == null) { throw new AnnotationProcessorException( wsLocalStrings.getLocalString( "no.webservice.annotation", "WS00025: SEI {0} referenced from the @WebService annotation on {1} does not contain a @WebService annotation", ((javax.jws.WebService) annInfo.getAnnotation()).endpointInterface(), ((Class) annElem).getName())); } // SEI cannot have @BindingType if (annElem.getAnnotation(javax.xml.ws.BindingType.class) != null) { throw new AnnotationProcessorException( wsLocalStrings.getLocalString( "cannot.have.bindingtype", "WS00026: SEI {0} cannot have @BindingType", ((javax.jws.WebService) annInfo.getAnnotation()).endpointInterface())); } } WebServicesDescriptor wsDesc = bundleDesc.getWebServices(); // WebService.name not found; as per 109, default port-component-name // is the simple class name as long as the simple class name will be a // unique port-component-name for this module if (portComponentName == null || portComponentName.length() == 0) { portComponentName = implClassName; } // Check if this port-component-name is unique for this module WebServiceEndpoint wep = wsDesc.getEndpointByName(portComponentName); if (wep != null) { // there is another port-component by this name in this module; // now we have to look at the SEI/impl of that port-component; if that SEI/impl // is the same as the current SEI/impl then it means we have to override values; // If the SEI/impl classes do not match, then no overriding should happen; we should // use fully qualified class name as port-component-name for the current endpoint if ((wep.getServiceEndpointInterface() != null) && (wep.getServiceEndpointInterface().length() != 0) && (!((Class) annElem).getName().equals(wep.getServiceEndpointInterface()))) { portComponentName = implClassFullName; } } // Check if the same endpoint is already defined in webservices.xml // This has to be done again after applying the 109 rules as above // for port-component-name WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName); WebService newWS; if (endpoint == null) { if (DOLUtils.warType().equals(bundleDesc.getModuleType())) { // http://java.net/jira/browse/GLASSFISH-17204 WebComponentDescriptor[] wcByImplName = ((WebBundleDescriptor) bundleDesc).getWebComponentByImplName(implClassFullName); for (WebComponentDescriptor wc : wcByImplName) { if (!wsDesc.getEndpointsImplementedBy(wc).isEmpty()) { // URL mapping for annotated service exists - it can be JAX-RPC service // as well as some servlet or maybe only invalid port-component-name, // so let user know about possible error logger.log( Level.SEVERE, LogUtils.WS_URLMAPPING_EXISTS, new Object[] {implClassFullName}); break; } } } // Check if a service with the same name is already present // If so, add this endpoint to the existing service if (svcNameFromImplClass != null && svcNameFromImplClass.length() != 0) { newWS = wsDesc.getWebServiceByName(svcNameFromImplClass); } else { newWS = wsDesc.getWebServiceByName(implClassName + "Service"); } if (newWS == null) { newWS = new WebService(); // service name from annotation if (svcNameFromImplClass != null && svcNameFromImplClass.length() != 0) { newWS.setName(svcNameFromImplClass); } else { newWS.setName(implClassName + "Service"); } wsDesc.addWebService(newWS); } endpoint = new WebServiceEndpoint(); if (portComponentName != null && portComponentName.length() != 0) { endpoint.setEndpointName(portComponentName); } else { endpoint.setEndpointName(((Class) annElem).getName()); } newWS.addEndpoint(endpoint); wsDesc.setSpecVersion(WebServicesDescriptorNode.SPEC_VERSION); } else { newWS = endpoint.getWebService(); } // If wsdl-service is specified in the descriptor, then the targetnamespace // in wsdl-service should match the @WebService.targetNameSpace, if any. // make that assertion here - and the targetnamespace in wsdl-service, if // present overrides everything else if (endpoint.getWsdlService() != null) { if ((targetNameSpace != null) && (targetNameSpace.length() != 0) && (!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace))) { AnnotationProcessorException ape = new AnnotationProcessorException( wsLocalStrings.getLocalString( "mismatch.targetnamespace", "WS00027: Target Namespace in wsdl-service element does not match @WebService.targetNamespace"), annInfo); annInfo.getProcessingContext().getErrorHandler().error(ape); return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED); } targetNameSpace = endpoint.getWsdlService().getNamespaceURI(); } // Service and port should reside in the same namespace - assert that if ((endpoint.getWsdlService() != null) && (endpoint.getWsdlPort() != null)) { if (!endpoint .getWsdlService() .getNamespaceURI() .equals(endpoint.getWsdlPort().getNamespaceURI())) { AnnotationProcessorException ape = new AnnotationProcessorException( wsLocalStrings.getLocalString( "mismatch.port.targetnamespace", "WS00028: Target Namespace for wsdl-service and wsdl-port should be the same"), annInfo); annInfo.getProcessingContext().getErrorHandler().error(ape); return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED); } } // Use annotated values only if the deployment descriptor equivalen has not been specified // If wsdlLocation was not given in Impl class, see if it is present in SEI // Set this in DOL if there is no Depl Desc entry // Precedence given for wsdlLocation in impl class if (newWS.getWsdlFileUri() == null) { if (wsdlLocation != null) { newWS.setWsdlFileUri(wsdlLocation); } else { if (ann.wsdlLocation() != null && ann.wsdlLocation().length() != 0) { newWS.setWsdlFileUri(ann.wsdlLocation()); } } } // Set binding id id @BindingType is specified by the user in the impl class if ((!endpoint.hasUserSpecifiedProtocolBinding()) && (userSpecifiedBinding != null) && (userSpecifiedBinding.length() != 0)) { endpoint.setProtocolBinding(userSpecifiedBinding); } if (endpoint.getServiceEndpointInterface() == null) { // take SEI from annotation if (ann.endpointInterface() != null && ann.endpointInterface().length() != 0) { endpoint.setServiceEndpointInterface(ann.endpointInterface()); } else { endpoint.setServiceEndpointInterface(((Class) annElem).getName()); } } // at this point the SIB has to be used no matter what @WebService was used. annElem = annInfo.getAnnotatedElement(); if (DOLUtils.warType().equals(bundleDesc.getModuleType())) { if (endpoint.getServletImplClass() == null) { // Set servlet impl class here endpoint.setServletImplClass(((Class) annElem).getName()); } // Servlet link name WebBundleDescriptor webBundle = (WebBundleDescriptor) bundleDesc; if (endpoint.getWebComponentLink() == null) { // <servlet-link> = fully qualified name of the implementation class endpoint.setWebComponentLink(implClassFullName); } if (endpoint.getWebComponentImpl() == null) { WebComponentDescriptor webComponent = (WebComponentDescriptor) webBundle.getWebComponentByCanonicalName(endpoint.getWebComponentLink()); if (webComponent == null) { // GLASSFISH-3297 WebComponentDescriptor[] wcs = webBundle.getWebComponentByImplName(implClassFullName); if (wcs.length > 0) { webComponent = wcs[0]; } } // if servlet is not known, we should add it now if (webComponent == null) { webComponent = new WebComponentDescriptorImpl(); webComponent.setServlet(true); webComponent.setWebComponentImplementation(((Class) annElem).getCanonicalName()); webComponent.setName(endpoint.getEndpointName()); webComponent.addUrlPattern("/" + newWS.getName()); webBundle.addWebComponentDescriptor(webComponent); } endpoint.setWebComponentImpl(webComponent); } } else { // TODO BM handle stateless Stateless stateless = null; try { stateless = annElem.getAnnotation(javax.ejb.Stateless.class); } catch (Exception e) { if (logger.isLoggable(Level.FINE)) { // This can happen in the web.zip installation where there is no ejb // Just logging the error conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); } } Singleton singleton = null; try { singleton = annElem.getAnnotation(javax.ejb.Singleton.class); } catch (Exception e) { if (logger.isLoggable(Level.FINE)) { // This can happen in the web.zip installation where there is no ejb // Just logging the error conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); } } String name; if ((stateless != null) && ((stateless).name() == null || stateless.name().length() > 0)) { name = stateless.name(); } else if ((singleton != null) && ((singleton).name() == null || singleton.name().length() > 0)) { name = singleton.name(); } else { name = ((Class) annElem).getSimpleName(); } EjbDescriptor ejb = ((EjbBundleDescriptor) bundleDesc).getEjbByName(name); endpoint.setEjbComponentImpl(ejb); ejb.setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface()); if (endpoint.getEjbLink() == null) endpoint.setEjbLink(ejb.getName()); } if (endpoint.getWsdlPort() == null) { // Use targetNameSpace given in wsdl-service/Impl class for port and service // If none, derive the namespace from package name and this will be used for // service and port - targetNamespace, if any, in SEI will be used for pprtType // during wsgen phase if (targetNameSpace == null || targetNameSpace.length() == 0) { // No targerNameSpace anywhere; calculate targetNameSpace and set wsdl port // per jax-ws 2.0 spec, the target name is the package name in // the reverse order prepended with http:// if (((Class) annElem).getPackage() != null) { StringTokenizer tokens = new StringTokenizer(((Class) annElem).getPackage().getName(), ".", false); if (tokens.hasMoreElements()) { while (tokens.hasMoreElements()) { if (targetNameSpace == null || targetNameSpace.length() == 0) { targetNameSpace = tokens.nextElement().toString(); } else { targetNameSpace = tokens.nextElement().toString() + "." + targetNameSpace; } } } else { targetNameSpace = ((Class) annElem).getPackage().getName(); } } else { throw new AnnotationProcessorException( wsLocalStrings.getLocalString( "missing.targetnamespace", "WS00029: The javax.jws.WebService annotation targetNamespace must be used for classes or interfaces that are in no package")); } targetNameSpace = "http://" + (targetNameSpace == null ? "" : targetNameSpace + "/"); } // WebService.portName = wsdl-port endpoint.setWsdlPort(new QName(targetNameSpace, portNameFromImplClass, "ns1")); } if (endpoint.getWsdlService() == null) { // Set wsdl-service properly; namespace is the same as that of wsdl port; // service name derived from deployment desc / annotation / default String serviceNameSpace = endpoint.getWsdlPort().getNamespaceURI(); String serviceName = null; if ((svcNameFromImplClass != null) && (svcNameFromImplClass.length() != 0)) { // Use the serviceName annotation if available serviceName = svcNameFromImplClass; } else { serviceName = newWS.getName(); } endpoint.setWsdlService(new QName(serviceNameSpace, serviceName, "ns1")); } // Now force a HandlerChain annotation processing // This is to take care of the case where the endpoint Impl class does not // have @HandlerChain but the SEI has one specified through JAXWS customization if ((((Class) origAnnElem).getAnnotation(javax.jws.HandlerChain.class)) == null) { return (new HandlerChainHandler()) .processHandlerChainAnnotation(annInfo, annCtx, origAnnElem, (Class) origAnnElem, true); } return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED); }